#
# makefile:
#       makefile for TOOLS\XDOC 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 V0.9.0.
#
#       Called from:    main makefile
#
#       Input:          files in this directory
#
#       Output:         xdoc.exe, copied to parent directory (TOOLS\).
#
#       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.
OUTPUTDIR0 = $(PROJECT_OUTPUT_DIR)
OUTPUTDIR = $(OUTPUTDIR0)\exe_st

# redefine MODULESDIR in the case of xdoc, this should
# go to tools
MODULESDIR = $(PROJECT_BASE_DIR)\tools

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

TARGETNAME=xdoc

# LINKOBJS contains the objects to be linked into xdoc.exe.
LINKOBJS = \
$(OUTPUTDIR)\bs_string.obj \
$(OUTPUTDIR)\bs_string_base.obj \
$(OUTPUTDIR)\bs_string_conv.obj \
$(OUTPUTDIR)\bs_string_uni.obj \
$(OUTPUTDIR)\bs_base.obj \
$(OUTPUTDIR)\xdoc.obj \
$(OUTPUTDIR0)\subsys\cp.lib \
!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 \
!endif
    $(MODULESDIR)\$(TARGETNAME).exe
    @echo ----- Leaving $(MAKEDIR)

callmainmake:
    @echo $(MAKEDIR)\makefile: Recursing to main makefile.
    @cd ..\..
    @nmake base helpers
    @cd $(MAKEDIR)
    @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_NODEBUG) -o $(OUTPUTDIR)\$(@B).obj $(@B).cpp
!else
!ifndef PRECH
        $(CC_ST) /Fo$(OUTPUTDIR)\$(@B).obj $(@B).cpp
!else
        $(CC_ST) /fi"$(PRECH)\$(@B).pch" /si"$(PRECH)\$(@B).pch" /Fo$(OUTPUTDIR)\$(@B).obj $(@B).cpp
!endif
!endif

# main include path
INC = ..\..\include
# base include path
BSINC = $(INC)\base
# helpers include path
HLPINC = $(HELPERS_BASE)\include\helpers

# Now define dependencies for all our .OBJ files by telling NMAKE
# which .OBJ file depends on what. For each .OBJ we define what files
# will enforce a recompilation when they've been changed.
# This uses the inference rules defined above.

# Note that include\setup.h is specified with _all_ files, so
# you can enforce a complete recompile of XWorkplace if you update
# that file (just save it once).

$(OUTPUTDIR)\xdoc.obj: \
    $(INC)\setup.h $(INC)\bl_xdoc.h \
    $(HLPINC)\dosh.h $(HLPINC)\except.h $(HLPINC)\stringh.h $(HLPINC)\xstring.h \
    $(BSINC)\bs_refptr.h $(BSINC)\bs_string.h $(BSINC)\bs_errors.h \
    xdoc.h

# special target for BSString class...
$(OUTPUTDIR)\bs_string.obj: ..\..\src\base\$(@B).cpp
!ifndef PRECH
        $(CC_ST) /Fo$(OUTPUTDIR)\$(@B).obj ..\..\src\base\$(@B).cpp
!else
        $(CC_ST) /fi"$(PRECH)\$(@B).pch" /si"$(PRECH)\$(@B).pch" /Fo$(OUTPUTDIR)\$(@B).obj ..\..\src\base\$(@B).cpp
!endif

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

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

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

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


$(TARGETNAME).def: ..\..\include\bl_xdoc.h
    $(RUN_BLDLEVEL) $@ ..\..\include\bl_xdoc.h "xdoc source code documenter"

# compose xdoc.exe
$(MODULESDIR)\$(TARGETNAME).exe: $(LINKOBJS) $(@B).def makefile
    @echo $(MAKEDIR)\makefile: Now linking "$(@B)"
!ifdef EMX
    $(LINK) -o $(@B).exe $(LINKOBJS) $(@B)_emx.def
!else
    $(LINK) /noe /OUT:$(MODULESDIR)\$(@B).exe $(@B).def $(LINKOBJS)
!ifndef WPI_DEBUG
!ifndef EMX
!ifdef LXLITEPATH
    $(LXLITEPATH)\lxlite $(MODULESDIR)\$(@B).exe
!endif
    mapsym -l $(MAPDIR)\$(@B).map
    cmd.exe /c copy $(MODULESDIR)\$(TARGETNAME).exe $(HELPERS_BASE)
!endif
!endif
!endif


