#############################################################################
#
#                   Copyright (C) 1998 SciTech Software.
#                           All rights reserved.
#
# Descripton:   Global makefile to build SciTech MGL libraries and install
#               archive components.
#
#############################################################################

# Determine if this is the build server or an engineer machine

.IMPORT .IGNORE: BUILDSERVER

# Comment this out to convert to non-beta build

#BETA_FLAG   = BETA=1

# Define directories for build

.IF $(UNIX_HOST)

SCRIPTS     = $(PRIVATE)/scripts/mgl/
BUILDS      = /builds/mgl/
SOURCE      = $(SCITECH)/src/
EXAMPLES    = $(SCITECH)/examples/
ARCHIVE_EXT	= .tar.gz

.ELSE

SCRIPTS     = $(PRIVATE)\scripts\mgl\
BUILDS      = \builds\mgl\
SOURCE      = $(SCITECH)\src\
EXAMPLES    = $(SCITECH)\examples\
ARCHIVE_EXT	= .exe

.ENDIF

# Define version number for the build

MGLVER      = 5.0.0
.IF $(BETA_FLAGS)
NAME_TAIL	= $(MGLVER)-b2$(ARCHIVE_EXT)
.ELSE
NAME_TAIL	= $(MGLVER)$(ARCHIVE_EXT)
.ENDIF

# Define the names of all install archives

MGLBASE     = mgl-base-$(NAME_TAIL)
MGLFONT     = mgl-font-$(NAME_TAIL)
MGLSRC      = mgl-src-$(NAME_TAIL)
MGLDEMO     = mgl-demo-$(NAME_TAIL)
OGLDEMO     = mgl-ogldemo-$(NAME_TAIL)
MGLD_BC50   = mgl-dos-bc50-$(NAME_TAIL)
MGLD_DJ20   = mgl-dos-dj20-$(NAME_TAIL)
MGLD_VC50   = mgl-dos-vc50-$(NAME_TAIL)
MGLD_VC60   = mgl-dos-vc60-$(NAME_TAIL)
MGLD_WC10   = mgl-dos-wc10-$(NAME_TAIL)
MGLD_WC11   = mgl-dos-wc11-$(NAME_TAIL)
MGLW_BC50   = mgl-win-bc50-$(NAME_TAIL)
MGLW_VC50   = mgl-win-vc50-$(NAME_TAIL)
MGLW_VC60   = mgl-win-vc60-$(NAME_TAIL)
MGLW_WC10   = mgl-win-wc10-$(NAME_TAIL)
MGLW_WC11   = mgl-win-wc11-$(NAME_TAIL)

# Define command line to build the library.

.IF $(MULTIPLE)
MKALL       = mkall
DEBUG		:= 1
.ELSE
MKALL       = install -u
.ENDIF

# Common targets for all OS'es

T_SYNC      =   targets/sync
T_PM        =   targets/pm
T_GCONSOLE  =   targets/gconsole
T_NUCLEUS   =   targets/nucleus
T_TECH      =   targets/tech
T_MVIS      =   targets/mvis
T_FIXED     =   targets/fixed
T_MESA      =   targets/mesa
T_MESAGLU   =   targets/mesaglu
T_GLUT      =   targets/glut
T_GM        =   targets/gm
T_LIBJPEG   =   targets/libjpeg
T_FREETYPE  =   targets/freetype
T_MGL       =   targets/mgl
T_SDDHELP   =   targets/sddhelp
T_MGLDOS    =   targets/mgldos
T_MGLWIN    =   targets/mglwin
T_MGLOS2    =   targets/mglos2
T_MGLLNX    =   targets/mgllinux
T_MGLX11    =   targets/mglx11
T_MGLQNX    =   targets/mglqnx
T_MGLPH     =   targets/mglph
T_MGLSMX    =   targets/mglsmx
T_MGLDOS_S  =   targets/mgldos_s
T_MGLWIN_S  =   targets/mglwin_s
T_MGLOS2_S  =   targets/mglos2_s
T_MGLLNX_S  =   targets/mgllnx_s
T_MGLQNX_S  =   targets/mglqnx_s
T_OGLDOS_S  =   targets/ogldos_s
T_OGLWIN_S  =   targets/oglwin_s
T_OGLOS2_S  =   targets/oglos2_s
T_OGLLNX_S  =   targets/ogllnx_s
T_OGLQNX_S  =   targets/oglqnx_s
T_WISE      =   targets/wise
T_BUILDINC  =   targets/buildinc

# Target to continue build of all libraries for current compiler

.PHONY single:
	@dmake all_single

# Target to build all libraries for current compiler.

.PHONY build: rmtargets
	@dmake all_single

# Target to build all libraries, for all compilers

.PHONY buildall:  rmtargets
	@dmake MULTIPLE=1 all

# Target to build libraries for one compiler

all_single: $(T_PM) $(T_GCONSOLE) $(T_TECH) $(T_MVIS) $(T_FIXED) \
			$(T_MESA) $(T_MESAGLU) $(T_GM) $(T_LIBJPEG) \
			$(T_FREETYPE) $(T_MGL)
#$(T_GLUT)
	@$(ECHO) =============================================================================
	@$(ECHO) DONE: Single compiler MGL build completed successfully!

# Target to build libraries for all compilers

all:    $(T_SYNC) $(T_PM) $(T_GCONSOLE) $(T_NUCLEUS) $(T_TECH) $(T_MVIS) \
		$(T_FIXED) $(T_MESA) $(T_MESAGLU) $(T_GLUT) $(T_GM) $(T_LIBJPEG) \
		$(T_FREETYPE) \
		$(T_SDDHELP) $(T_MGLDOS) $(T_MGLWIN) $(T_MGLOS2) $(T_MGLLNX) \
		$(T_MGLX11) $(T_MGLQNX) $(T_MGLPH) $(T_MGLDOS_S) $(T_MGLWIN_S) \
		$(T_MGLOS2_S) $(T_MGLLNX_S) $(T_MGLQNX_S) $(T_OGLDOS_S) \
		$(T_OGLWIN_S) $(T_OGLOS2_S) $(T_OGLLNX_S) $(T_OGLQNX_S) $(T_WISE) \
		$(T_BUILDINC)
	@$(RM) -f mk0*
	@$(ECHO) =============================================================================
	@$(ECHO) DONE: Full MGL build completed successfully!

# Targets to build each component

$(T_SYNC):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Syncing files to depot
        @+p4 sync
	@$(CP) done $(T_SYNC)

$(T_PM):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building PM Library
	@cdit $(SOURCE)pm dmake $(MKALL)
	@$(CP) done $(T_PM)

$(T_GCONSOLE):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Graphical Console Library
	@cdit $(SOURCE)gconsole dmake $(MKALL)
	@$(CP) done $(T_GCONSOLE)

$(T_NUCLEUS):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Nucleus Loader Library
	@cdit $(SOURCE)nucleus dmake $(MKALL)
	@$(CP) done $(T_NUCLEUS)

$(T_SDDHELP):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building SDD Helper Device Driver
.IF $(USE_OS232)
	@cdit $(PRIVATE)/src/sddos2/sddhelp dmake mksdd
.ELSE
	@cdit $(PRIVATE)/src/sdd9x/sddhelp dmake mksdd
.ENDIF
	@$(CP) done $(T_SDDHELP)

$(T_TECH):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Techniques Class Library
	@cdit $(SOURCE)tech dmake $(MKALL)
	@$(CP) done $(T_TECH)

$(T_MVIS):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building MegaVision GUI Library
	@cdit $(SOURCE)mvis dmake $(MKALL)
	@$(CP) done $(T_MVIS)

$(T_FIXED):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Vector/Matrix Library
	@cdit $(SOURCE)fixed dmake $(MKALL)
	@$(CP) done $(T_FIXED)

$(T_MESA):
.IF $(DEBUG)
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Mesa OpenGL Library
	@cdit $(SOURCE)mesa dmake $(MKALL)
.ENDIF	
	@$(CP) done $(T_MESA)

$(T_MESAGLU):
.IF $(DEBUG)
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Mesa OpenGL Utility Library
	@cdit $(SOURCE)mesaglu dmake $(MKALL)
.ENDIF	
	@$(CP) done $(T_MESAGLU)

$(T_GLUT):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building MGL GLUT Library
	@cdit $(SOURCE)glut dmake $(MKALL)
	@$(CP) done $(T_GLUT)

$(T_GM):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Game Framework Library
	@cdit $(SOURCE)gm dmake $(MKALL)
	@$(CP) done $(T_GM)

$(T_LIBJPEG):
.IF $(DEBUG)
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building JPEG Library
	@cdit $(SOURCE)libjpeg dmake $(MKALL)
.ENDIF
	@$(CP) done $(T_LIBJPEG)

$(T_FREETYPE):
.IF $(DEBUG)
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building FreeType Library
	@cdit $(SOURCE)freetype dmake $(MKALL)
.ENDIF
	@$(CP) done $(T_FREETYPE)

$(T_MGL):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Core MGL Library
	@cdit $(SOURCE)mgl dmake install -u
	@cdit $(SOURCE)mgl dmake installcpp -u
	@$(CP) done $(T_MGL)

$(T_MGLDOS):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Core MGL DOS Library
	@cdit $(SOURCE)mgl dmake mkdos
	@$(CP) done $(T_MGLDOS)

$(T_MGLWIN):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Core MGL Windows Library
	@cdit $(SOURCE)mgl dmake mkwin
	@$(CP) done $(T_MGLWIN)

$(T_MGLOS2):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Core MGL OS/2 Library
	@cdit $(SOURCE)mgl dmake mkos2
	@$(CP) done $(T_MGLOS2)

$(T_MGLLNX):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Core MGL Linux Library
	@cdit $(SOURCE)mgl dmake mklinux
	@$(CP) done $(T_MGLLNX)

$(T_MGLX11):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Core MGL X11 Library
	@cdit $(SOURCE)mgl dmake mkx11
	@$(CP) done $(T_MGLX11)

$(T_MGLQNX):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Core MGL QNX Library
	@cdit $(SOURCE)mgl dmake mkqnx
	@$(CP) done $(T_MGLQNX)

$(T_MGLPH):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Core MGL QNX Photon Library
	@cdit $(SOURCE)mgl dmake mkphoton
	@$(CP) done $(T_MGLPH)

$(T_MGLSMX):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Core MGL smx Library
	@cdit $(SOURCE)mgl dmake mksmx
	@$(CP) done $(T_MGLSMX)

$(T_MGLDOS_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building MGL DOS Samples Programs
	@cdit $(EXAMPLES)mgl dmake mkdos
	@$(CP) done $(T_MGLDOS_S)

$(T_MGLWIN_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building MGL Windows Samples Programs
	@cdit $(EXAMPLES)mgl dmake mkwin
	@$(CP) done $(T_MGLWIN_S)

$(T_MGLOS2_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building MGL OS/2 Samples Programs
	@cdit $(EXAMPLES)mgl dmake mkos2
	@$(CP) done $(T_MGLOS2_S)

$(T_MGLLNX_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building MGL Linux Samples Programs
	@cdit $(EXAMPLES)mgl dmake mklinux
	@$(CP) done $(T_MGLLNX_S)

$(T_MGLQNX_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building MGL QNX Samples Programs
	@cdit $(EXAMPLES)mgl dmake mkqnx
	@$(CP) done $(T_MGLQNX_S)

$(T_OGLDOS_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building OpenGL DOS Samples Programs
	@cdit $(EXAMPLES)opengl dmake mkdos
	@$(CP) done $(T_OGLDOS_S)

$(T_OGLWIN_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building OpenGL Windows Samples Programs
	@cdit $(EXAMPLES)opengl dmake mkwin
	@$(CP) done $(T_OGLWIN_S)

$(T_OGLOS2_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building OpenGL OS/2 Samples Programs
	@cdit $(EXAMPLES)opengl dmake mkos2
	@$(CP) done $(T_OGLOS2_S)

$(T_OGLLNX_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building OpenGL Linux Samples Programs
	@cdit $(EXAMPLES)opengl dmake mklinux
	@$(CP) done $(T_OGLLNX_S)

$(T_OGLQNX_S):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building OpenGL QNX Samples Programs
	@cdit $(EXAMPLES)opengl dmake mkqnx
	@$(CP) done $(T_OGLQNX_S)

$(T_WISE):
	@$(ECHO) =============================================================================
	@$(ECHO) START: Building Wise install archives
	@runwise $(SCRIPTS)mksetup.wse
	@runwise $(SCRIPTS)mglbase.wse
	@copy $(SCRIPTS)mglbase.exe $(BUILDS)$(MGLBASE)
	@runwise $(SCRIPTS)mglfont.wse
	@copy $(SCRIPTS)mglfont.exe $(BUILDS)$(MGLFONT)
	@runwise $(SCRIPTS)mglsrc.wse
	@copy $(SCRIPTS)mglsrc.exe $(BUILDS)$(MGLSRC)
	@runwise $(SCRIPTS)mgldm.wse
	@copy $(SCRIPTS)mgldm.exe $(BUILDS)$(MGLDEMO)
	@runwise $(SCRIPTS)ogldm.wse
	@copy $(SCRIPTS)ogldm.exe $(BUILDS)$(OGLDEMO)
	@runwise $(SCRIPTS)mgldos-bc4.wse
	@copy $(SCRIPTS)mgldos-bc4.exe $(BUILDS)$(MGLD_BC45)
	@runwise $(SCRIPTS)mgldos-bc5.wse
	@copy $(SCRIPTS)mgldos-bc5.exe $(BUILDS)$(MGLD_BC50)
	@runwise $(SCRIPTS)mgldos-dj2.wse
	@copy $(SCRIPTS)mgldos-dj2.exe $(BUILDS)$(MGLD_DJ20)
	@runwise $(SCRIPTS)mgldos-vc4.wse
	@copy $(SCRIPTS)mgldos-vc4.exe $(BUILDS)$(MGLD_VC42)
	@runwise $(SCRIPTS)mgldos-vc5.wse
	@copy $(SCRIPTS)mgldos-vc5.exe $(BUILDS)$(MGLD_VC50)
	@runwise $(SCRIPTS)mgldos-vc6.wse
	@copy $(SCRIPTS)mgldos-vc6.exe $(BUILDS)$(MGLD_VC60)
	@runwise $(SCRIPTS)mgldos-wc10.wse
	@copy $(SCRIPTS)mgldos-wc10.exe $(BUILDS)$(MGLD_WC10)
	@runwise $(SCRIPTS)mgldos-wc11.wse
	@copy $(SCRIPTS)mgldos-wc11.exe $(BUILDS)$(MGLD_WC11)
	@runwise $(SCRIPTS)mglwin-bc4.wse
	@copy $(SCRIPTS)mglwin-bc4.exe $(BUILDS)$(MGLW_BC45)
	@runwise $(SCRIPTS)mglwin-bc5.wse
	@copy $(SCRIPTS)mglwin-bc5.exe $(BUILDS)$(MGLW_BC50)
	@runwise $(SCRIPTS)mglwin-vc4.wse
	@copy $(SCRIPTS)mglwin-vc4.exe $(BUILDS)$(MGLW_VC42)
	@runwise $(SCRIPTS)mglwin-vc5.wse
	@copy $(SCRIPTS)mglwin-vc5.exe $(BUILDS)$(MGLW_VC50)
	@runwise $(SCRIPTS)mglwin-vc6.wse
	@copy $(SCRIPTS)mglwin-vc6.exe $(BUILDS)$(MGLW_VC60)
	@runwise $(SCRIPTS)mglwin-dp2.wse
	@copy $(SCRIPTS)mglwin-dp2.exe $(BUILDS)$(MGLW_DP20)
	@runwise $(SCRIPTS)mglwin-wc10.wse
	@copy $(SCRIPTS)mglwin-wc10.exe $(BUILDS)$(MGLW_WC10)
	@runwise $(SCRIPTS)mglwin-wc11.wse
	@copy $(SCRIPTS)mglwin-wc11.exe $(BUILDS)$(MGLW_WC11)
	@$(CP) done $(T_WISE)

$(T_BUILDINC):
	@$(ECHO) =============================================================================
.IF $(BUILDSERVER)
	@$(ECHO) START: Incrementing build number
	@cdit bldinc build bc45-d16 bldinc.exe -u OPT=1 $(BETA_FLAG)
    @-$(SOURCE)\bldinc\bldinc.exe
.ENDIF
	@$(CP) done $(T_BUILDINC)

# Target to remove all target build flags

rmtargets:
	@$(RM) -f targets/*
	
