#
#  File		: makelib
#  Description  :
#  	General makefile for TBirdOS 
#	This makefile is used for generate library
#  History	:
#  	Sep. 9  : Inititial version
#  (C) Altek 
#
#  NOTE: DO NOT CHANGE the / to \. or the makefile can not work properly.
#
# CONTROL system variable
#  PROJDIR
#  METADEV 	
#  CFGDIR
#  RELEASE
#
#
# if enviroment not set, load environment from current directory
#
ifeq ($(METADEV),)
	$(error "Environment METADEV do not set properly. You can use SET METADEV=... under DOS prompt or environment file to correct it and then remake")
endif
ifeq ($(CAMPROJDIR),)
	$(error "Environment CAMPROJDIR do not set properly. You can use SET CAMPROJDIR=... under DOS prompt or environment file to correct it and then remake")
endif
ifeq ($(CAMOSDIR),)
	$(error "Environment CAMOSDIR do not set properly. You can use SET CAMOSDIR=... under DOS prompt or environment file to correct it and then remake")
endif

ifeq ($(MODULENAME),)
MODULENAME = $(notdir $(basename $(dest)))
endif

#
#  set configuration
#
# pG CFGFILE ]w, ܤOq build.bat Is.
# ]w configure  debug
#
ifeq ($(CFGFILE),)
	export CFGDIR=$(CAMPROJDIR)/build
	export CFGFILE=$(CFGDIR)/config.mk
endif

#ifeq ($(RELEASE),)
#	export CFLAGFILE  =$(CFGDIR)/debug.opc
#	export AFLAGFILE  =$(CFGDIR)/debug.opa
#	export LFlAGFILE  =$(CFGDIR)/debug.opl
#	export LIBDIR=$(PROJDIR)/lib/debug
#	export OBJDIR = OBJ\debug
#else
#	export CFLAGFILE  =$(CFGDIR)/release.opc
#	export AFLAGFILE  =$(CFGDIR)/release.opa
#	export LFlAGFILE  =$(CFGDIR)/release.opl
#	export LIBDIR=$(PROJDIR)/Lib/release
#	export OBJDIR = OBJ\release
#endif

#
#include source file
#
-include sourcelist


dest=$(CAMPROJDIR)\lib\$(dir-prefix)\$(TARGET)

#
#inculde configuration 
#
-include $(CFGFILE)

-include $(CFGDIR)\ver\osver

makelist:
	@if exist objlist @erase objlist
	$(GLIST) objlist $(OBJDIR)\\ .o
	
#	@if exist objlist @erase objlist
#	@for %%i in ($(objects)) do @echo $(addprefix $(OBJDIR)/,%%i) >>objlist
	
#	@echo $(addprefix $(OBJDIR)/,$(objects))  >>objlist
  
$(dest) : makelist $(addprefix $(OBJDIR)/,$(objects)) 
	@if not exist "$(OBJDIR)" mkdir "$(OBJDIR)"
	@echo Build library $(dest)
	@if exist "ver.bin" @attrib -r ver.bin
	@$(MAKEVER) $(MODULENAME) $(OSVER)
	@$(LD) -rsq $(dest) @objlist >$(basename $(dest)).err
	@$(CHKERR) $(basename $(dest)).err err.txt
	@if exist "ver.bin" @attrib +r ver.bin
	@$(LD) -rsq  $(dest) ver.bin  2>NUL
	@echo Build $(dest) is finished.

