.SILENT:

# clibc_16.lib Makefile
# Byron Young
# 2002

# NMAKE 1.20
# ML 6.14

!INCLUDE Makefile.g


# rest of makefile
VERSION = 05
ZIPRELEASENAME=ilibc_$(VERSION).zip

# a list of all the directories to recurse into
# order is critical, and must match LIBNAMESA
DIRS =	    string\
	    misc

DEBUG_DIRS = debug\$(DIRS: = debug\)
RELEASE_DIRS = release\$(DIRS: = release\)

# a list of the names of the library to create in that directory
LIBNAMESA = string\string.lib\
	    misc\misc.lib

LIBNAMES_DEBUG=debug\$(LIBNAMESA: = debug\)
LIBNAMES_RELEASE=release\$(LIBNAMESA: = release\)

#MKFILE_DEPENDS = $(DIRS: =\Makefile )\Makefile

LIBNAME_RELEASE=clibc_16.lib
LIBNAME_DEBUG=clibcd16.lib

all : debug release
    if NOT EXIST $(DIR_C_INCLUDE) mkdir $(DIR_C_INCLUDE)
    echo Copying .h files to $(DIR_C_INCLUDE)
    for %%v in ($(DIRS)) do copy %%v\%%v.h $(DIR_C_INCLUDE)
    if NOT EXIST $(DIR_ASM_INCLUDE) mkdir $(DIR_ASM_INCLUDE)
    echo Copying .inc files to $(DIR_ASM_INCLUDE)
    for %%v in ($(DIRS)) do copy %%v\%%v.inc $(DIR_ASM_INCLUDE)
    echo Copying debug\$(LIBNAME_DEBUG) to $(DIR_LIB)
    copy debug\$(LIBNAME_DEBUG) $(DIR_LIB)\$(LIBNAME_DEBUG)
    echo Copying release\$(LIBNAME_RELEASE) to $(DIR_LIB)
    copy release\$(LIBNAME_RELEASE) $(DIR_LIB)\$(LIBNAME_RELEASE)
    echo Done


debug : $(DEBUG_DIRS) debug\$(LIBNAME_DEBUG)
    rename debug\$(LIBNAME_DEBUG) $(LIBNAME_DEBUG)

release :  $(RELEASE_DIRS) release\$(LIBNAME_RELEASE)
    rename release\$(LIBNAME_RELEASE) $(LIBNAME_RELEASE)

$(DEBUG_DIRS) :
    if not exist debug\ mkdir debug
    if not exist $@\ mkdir $@
    cd $(@B)
	$(MAKE) /C "DIR_PROJ=$(MAKEDIR)" "DEBUG=1" ..\$(@)
    cd ..

$(RELEASE_DIRS) :
    if not exist release\ mkdir release
    if not exist $@\ mkdir $@
    cd $(@B)
	$(MAKE) /C "DIR_PROJ=$(MAKEDIR)" "DEBUG=0" ..\$(@)
    cd ..

# MAIN LIBRARY, debug
debug\$(LIBNAME_DEBUG) :
	echo Creating $(@)
	del $(@)
	LIB /NOL @<<lib.lrf
debug\$(LIBNAME_DEBUG) +$(LIBNAMES_DEBUG: = &^
+)
debug\$(LIBNAME_DEBUG:.lib=.lst);
<<NOKEEP
	rename debug\$(LIBNAME_DEBUG) debug\$(LIBNAME_DEBUG)

# MAIN LIBRARY, release
release\$(LIBNAME_RELEASE) :
	echo Creating $(@)
	del $(@)
	LIB /NOL @<<lib.lrf
release\$(LIBNAME_RELEASE) +$(LIBNAMES_RELEASE: = &^
+)
release\$(LIBNAME_RELEASE:.lib=.lst);
<<NOKEEP
	rename release\$(LIBNAME_RELEASE) release\$(LIBNAME_RELEASE)

zip :
    echo Making distribution file $(ZIPRELEASENAME)
    mkdir clibc_16
    copy Makefile clibc_16
    copy Makefile.g clibc_16
    copy clibc_16.txt clibc_16
    copy clibc_16.inc clibc_16
    mkdir clibc_16\test
    copy test\main.c clibc_16\test
    copy test\testmod.asm clibc_16\test
    copy test\Makefile clibc_16\test
    for %%v in ($(DIRS)) do mkdir clibc_16\%%v
    for %%v in ($(DIRS)) do copy %%v\*.asm clibc_16\%%v
    for %%v in ($(DIRS)) do copy %%v\*.inc clibc_16\%%v
    for %%v in ($(DIRS)) do copy %%v\*.h clibc_16\%%v
    for %%v in ($(DIRS)) do copy %%v\Makefile clibc_16\%%v
    pkzip -rP clibc_16.zip clibc_16\*.*
    deltree /Y clibc_16
    move clibc_16.zip dist\$(ZIPRELEASENAME)
    echo Done.

clean :
    echo Cleaning source directories
    for %%v in ($(DIRS)) do erase %%v\*.obj
    for %%v in ($(DIRS)) do erase %%v\*.bak
    for %%v in ($(DIRS)) do erase %%v\*.lst
    for %%v in ($(DIRS)) do erase %%v\*.rlf
    echo Cleaning project directory
    erase *.lst
    erase *.exe
    erase *.dbg
    erase *.cod
    erase *.obj
    erase *.bak
    echo Cleaning test directory
    erase test\*.lst
    erase test\*.exe
    erase test\*.dbg
    erase test\*.cod
    erase test\*.obj
    erase test\*.bak
    echo Cleaning up build directory
    echo Deleting debug directory
    deltree /Y debug
    echo Deleting release directory
    deltree /Y release
    echo Deleting dist directory
    deltree /Y dist
    echo Deleting .h include directory $(DIR_C_INCLUDE)
    deltree /Y $(DIR_C_INCLUDE)
    echo Deleting .inc include directory $(DIR_ASM_INCLUDE)
    deltree /Y $(DIR_ASM_INCLUDE)
    echo Done.

# misc notes
# to add a source file:
#    add the .asm name to SRCFILES
#    add the corresponding entry from *.MAK
