#
# makefile:
#       makefile for src/engine directory.
#       For use with IBM NMAKE, which comes with the IBM compilers,
#       the Developer's Toolkit, and the DDK.
#
#       The engine dir is all new with V0.9.14 (2001-07-26) [umoeller].
#
#       Called from:    main makefile
#
#       Input:          ./*.cpp
#
#       Output:         ../bin/enginelib.lib, wpirtl.dll, wpirtli.lib
#
#       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)

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

# The OBJS macro contains all the .OBJ files which need to be
# created from the files in this directory.
# These will be put into BIN\.
OBJS = \
$(OUTPUTDIR)\fe_rexx.obj \
$(OUTPUTDIR)\fe_script.obj \
$(OUTPUTDIR)\fe_script_old.obj \
$(OUTPUTDIR)\fe_base.obj \
$(OUTPUTDIR)\fe_archive.obj \
$(OUTPUTDIR)\fe_database.obj \
$(OUTPUTDIR)\fe_job.obj \
$(OUTPUTDIR)\fe_package.obj \
$(OUTPUTDIR)\fe_package_arc.obj \
$(OUTPUTDIR)\fe_package_db.obj \
$(OUTPUTDIR)\fe_engine.obj \
$(OUTPUTDIR)\fe_cid.obj

# all objects and libs for WPIRTL.DLL
RUNTIME_OBJS = \
# base objects:
$(OUTPUTDIR)\baselib.lib \
# engine objects:
$(OUTPUTDIR)\enginelib.lib \
# other objects:
$(HELPERS_OUTPUT_DIR_MT)\*.obj \
$(OUTPUTDIR)\exe_st\wiarchive.lib \
$(OUTPUTDIR)\subsys\libbz2.lib \
!ifdef WPI_DEBUG
$(HELPERS_BASE)\src\helpers\pmprintf.lib \
!ifdef KLIB_LIBS
$(KLIB_LIBS)\kLib.lib\kLib.lib \
$(KLIB_LIBS)\kHeapDbgVACWrappers.lib\kHeapDbgVACWrappers.lib
!endif
!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
#    $(OBJS)
    $(OUTPUTDIR)\$(RTL_DLL_NAME)i.lib
# changed (99-10-24) [umoeller]
!endif
    @echo ----- Leaving $(MAKEDIR)

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

$(OUTPUTDIR)\enginelib.lib: $(OBJS)
!ifdef EMX
    emxomfar cr $* $(OBJS)
!else
    !ilib /nologo $* -+$?,,
!endif

# 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) -o $(OUTPUTDIR)\$(@B).obj $(@B).cpp
!else
!ifndef PRECH
        $(CC) /Fo$(OUTPUTDIR)\$(@B).obj $(@B).cpp
!else
        $(CC) /fi"$(PRECH)\$(@B).pch" /si"$(PRECH)\$(@B).pch" /Fo$(OUTPUTDIR)\$(@B).obj $(@B).cpp
!endif
!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
!endif

# here comes the sick stuff: building WPIRTL.DLL and associated
# libs

wpirtl_base.def: ..\..\include\bldlevel.h
    $(RUN_BLDLEVEL) $@ ..\..\include\bldlevel.h "WarpIN runtime library (backend, helpers, C runtime)"

# compose wpirtl.def by copying wpirtl_base.def and the cppfilt output together
# changed V0.9.13 (2001-06-27) [umoeller]: now using -o -n to force import by ordinal
wpirtl.def: $(OUTPUTDIR)\baselib.lib $(OUTPUTDIR)\enginelib.lib $(OUTPUTDIR)\exe_st\wiarchive.lib wpirtl_base.def
    cppfilt -b -p -o 1000 -n $(OUTPUTDIR)\baselib.lib $(OUTPUTDIR)\enginelib.lib $(OUTPUTDIR)\exe_st\wiarchive.lib > $(OUTPUTDIR)\wpirtl.tmp
    cmd.exe /c copy wpirtl_base.def /a + $(OUTPUTDIR)\wpirtl.tmp wpirtl.def

# compose runtime DLL: this contains...
# -- VAC C runtime
# -- helpers code
# -- the entire backend
# -- pmprintf, if needed
$(MODULESDIR)\$(RTL_DLL_NAME).dll: $(RUNTIME_OBJS) wpirtl.def
    @echo Linking $@...
    $(LINK) /noe /out:$@ @<<
wpirtl.def $(RUNTIME_OBJS) rexx.lib
<<KEEP
!ifndef WPI_DEBUG
!ifndef EMX
    @cd $(MODULESDIR)
    mapsym -l $(MAPDIR)\$(@B).map
    @cd $(MAKEDIR)
!endif
!endif

# and its import library
$(OUTPUTDIR)\$(RTL_DLL_NAME)i.lib: $(MODULESDIR)\$(RTL_DLL_NAME).dll wpirtl.def
    implib /nologo /noi $@ wpirtl.def


