#
# makefile:
#       makefile for src/main directory.
#       For use with IBM NMAKE, which comes with the IBM compilers,
#       the Developer's Toolkit, and the DDK.
#
#       All the makefiles have been restructured with V1.0.0.
#
#       Called from:    main makefile
#
#       Input:          ./*.c
#
#       Output:         stub.exe
#
#       Edit "setup.in" to set up the make process.
#

# Say hello to yourself.
!if [@echo +++++ Entering $(MAKEDIR)]
!endif

# include setup (compiler options etc.)
!include ..\..\setup.in

# FIXED MACROS
# ------------
#
# You probably need not change the following.
#

# Define the suffixes for files which NMAKE will work on.
# .SUFFIXES is a reserved NMAKE keyword ("pseudotarget") for
# defining file extensions that NMAKE will recognize in inference
# rules.
.SUFFIXES: .cpp .obj .h

# OUTPUTDIR specifies the directory where all the output .OBJ
# files will be created in.
OUTPUTDIR = $(PROJECT_OUTPUT_DIR)\stub

!if [@md $(OUTPUTDIR) 2> NUL]
!endif

TARGETNAME=stub

# LINKOBJS contains the objects to be linked into stub.exe.
LINKOBJS = \
$(OUTPUTDIR)\stub.obj \
$(OUTPUTDIR)\linklist.obj \
$(OUTPUTDIR)\wiarchive.obj \
# $(OUTPUTDIR)\wicomp.obj \
$(OUTPUTDIR)\widecomp.obj \
$(OUTPUTDIR)\bs_base.obj \
# $(OUTPUTDIR)\blocksort.obj \
$(OUTPUTDIR)\bzlib.obj \
# $(OUTPUTDIR)\compress.obj \
$(OUTPUTDIR)\crctable.obj \
$(OUTPUTDIR)\decompress.obj \
$(OUTPUTDIR)\huffman.obj \
$(OUTPUTDIR)\randtable.obj \
!ifdef WPI_DEBUG
$(HELPERS_BASE)\src\helpers\pmprintf.lib
!endif

# The main target:
# If we're called from the main makefile, MAINMAKERUNNING is defined,
# and we'll set $(OBJS) as our targets (which will go on).
# Otherwise, we call the main makefile, which will again call ourselves later.
all:   \
# !ifndef MAINMAKERUNNING
#    callmainmake
#!else
    $(MODULESDIR)\$(TARGETNAME).exe
#!endif
    @echo ----- Leaving $(MAKEDIR)

callmainmake:
    @echo $(MAKEDIR)\makefile: Recursing to main makefile.
    @cd ..\..
    @nmake
    @echo $(MAKEDIR)\makefile: Returned from main makefile. Done.

# The "dep" target: run fastdep on the sources.
# "nmake dep" gets called from src\makefile if nmake dep
# is running on the main makefile.
dep:
    $(RUN_FASTDEP) *.cpp
    @echo ----- Leaving $(MAKEDIR)

# Now define inference rules for what to do with certain file
# types, based on their file extension.
# The syntax we need here is ".fromext.toext".
# So whenever NMAKE encounters a .toext file, it
# executes what we specify here.
# The ugly {} brackets are some awkward syntax for specifying
# files in other directories.

# Special macros used here: $(@B) is the current target w/out ext.

# -- compile C files to .OBJ files, using the CC macro above.
#    The output will be placed in the directory specified by
#    the OUTPUTDIR variable (set above).

.cpp.{$(OUTPUTDIR)}.obj:
        @echo $(MAKEDIR)\makefile: Compiling $(@B).cpp
!ifdef EMX
        $(CC_TINY) -o $(OUTPUTDIR)\$(@B).obj $(@B).cpp
!else
!ifndef PRECH
        $(CC_TINY) /Fo$(OUTPUTDIR)\$(@B).obj $(@B).cpp
!else
        $(CC_TINY) /fi"$(PRECH)\$(@B).pch" /si"$(PRECH)\$(@B).pch" /Fo$(OUTPUTDIR)\$(@B).obj $(@B).cpp
!endif
!endif

{..\wiarchive}.cpp.{$(OUTPUTDIR)}.obj:
        @echo $(MAKEDIR)\makefile: Compiling $(@B).cpp
!ifdef EMX
        $(CC_TINY) -o $(OUTPUTDIR)\$(@B).obj ..\wiarchive\$(@B).cpp
!else
!ifndef PRECH
        $(CC_TINY) /Fo$(OUTPUTDIR)\$(@B).obj ..\wiarchive\$(@B).cpp
!else
        $(CC_TINY) /fi"$(PRECH)\$(@B).pch" /si"$(PRECH)\$(@B).pch" /Fo$(OUTPUTDIR)\$(@B).obj ..\wiarchive\$(@B).cpp
!endif
!endif

{..\libbz2}.c.{$(OUTPUTDIR)}.obj:
        @echo $(MAKEDIR)\makefile: Compiling $(@B).c
!ifdef EMX
        $(CC_TINY) /DBZ_NO_STDIO -o $(OUTPUTDIR)\$(@B).obj ..\libbz2\$(@B).c
!else
!ifndef PRECH
        $(CC_TINY) /DBZ_NO_STDIO /Fo$(OUTPUTDIR)\$(@B).obj ..\libbz2\$(@B).c
!else
        $(CC_TINY) /DBZ_NO_STDIO /fi"$(PRECH)\$(@B).pch" /si"$(PRECH)\$(@B).pch" /Fo$(OUTPUTDIR)\$(@B).obj ..\libbz2\$(@B).c
!endif
!endif

$(OUTPUTDIR)\bs_base.obj: ..\base\$(@B).cpp
!ifndef PRECH
        $(CC_TINY) /Fo$(OUTPUTDIR)\$(@B).obj ..\base\$(@B).cpp
!else
        $(CC_TINY) /fi"$(PRECH)\$(@B).pch" /si"$(PRECH)\$(@B).pch" /Fo$* ..\..\src\base\$(@B).cpp
!endif

$(OUTPUTDIR)\linklist.obj: $(HELPERS_BASE)\src\helpers\$(@B).c
!ifndef PRECH
        $(CC_TINY) /Fo$(OUTPUTDIR)\$(@B).obj $(HELPERS_BASE)\src\helpers\$(@B).c
!else
        $(CC_TINY) /fi"$(PRECH)\$(@B).pch" /si"$(PRECH)\$(@B).pch" /Fo$* $(HELPERS_BASE)\src\helpers\$(@B).c
!endif

# The .OBJ-from-sources dependencies are now automatically
# created by "nmake dep" into the .depend include file.
# V0.9.12 (2001-05-30) [umoeller]

!ifndef NOINCLUDEDEPEND
!include .depend
!include ..\base\.depend
!endif

$(TARGETNAME).def: ..\..\include\bldlevel.h
    $(RUN_BLDLEVEL) $@ ..\..\include\bldlevel.h "WarpIN self-extracting archive EXE stub"

$(TARGETNAME)_emx.def: ..\..\include\bldlevel.h
    $(RUN_BLDLEVEL) $@ ..\..\include\bldlevel.h "WarpIN self-extracting archive EXE stub (EMX)"

$(OUTPUTDIR)\stub.res: $(@B).rc $(@B).ico
    $(RC) -r $(@B).rc $(OUTPUTDIR)\$(@B).res

# compose stub.exe
$(MODULESDIR)\$(TARGETNAME).exe: $(LINKOBJS) $(@B).def $(@B)_emx.def makefile $(OUTPUTDIR)\$(@B).res
    @echo $(MAKEDIR)\makefile: Now compiling and linking "$(@B)"
!ifdef EMX
    $(LINK) -o /OUT:$@  $(LINKOBJS) $(@B)_emx.def
!else
    $(LINK_EXE) /nodefault /OUT:$@ $(@B).def $(LINKOBJS) os2386.lib cppos30.lib
!endif
    $(RC) $(OUTPUTDIR)\$(@B).res $@
!ifndef WPI_DEBUG
!ifdef LXLITEPATH
    $(LXLITEPATH)\lxlite $@
!endif
!ifndef EMX
    @cd $(MODULESDIR)
    mapsym -l $(MAPDIR)\$(@B).map
    @cd $(MAKEDIR)
!endif
!endif


