#####################################################################
#
#       This is a makefile for PPT. (C) Janne Jalkanen 1995
#
#       This makefile is meant to be used with Matthew Dillon's
#       DMAKE utility.
#
#       $Id: dmakefile,v 6.6 2000/04/16 22:08:12 jj Exp $
#
#####################################################################
#
#   Generic paths and stuff.
#

RELEASE = descartes1

#   The directory in which PPT source code is backed up
#   on 'dmake backup'. The slash or colon in the end MUST exist.
BACKUPDIR = data:backup/

#   This is the distribution directory, where the distribution
#   will be done on 'dmake dist'.
#   A directory called "ppt" will NOT be created there.
#   The archiving command needs that this is at the top
#   directory of a device.
DISTDIR   = TMP:PPT

#   This is where the developer stuff is compiled
DEVDIR    = $(DISTDIR)_dev

#   This is where the non-free stuff is put to
NONFREEDIR= $(DISTDIR)_nonfree

#   The directory in which the distribution archive will be
#   put.
ARCHIVEDIR= RAM:

#   The main directory
MAINDIR   = work:source/c/ppt

#   Externals source directory
EXTSRCDIR = $(MAINDIR)/pluginsrc

#   Float gadget include files
FLOATGADGET=floatgadget

#   PowerUP include files
POWERUP=usr:lang/PPCRelease/include

#   Object directories. OD is for the debugging version and
#   ROD is for the release version with no debug code.
OD        = dtmp:pptscd
ROD       = dtmp:pptsc
R2OD      = $(ROD)_020

# GST files for SAS/C
GST   = defs.gst
RGST  = rdefs.gst
R2GST = $(RGST)

# Main executables
MAIN   = pptd
MFILE  = T:defs.m
RMAIN  = ppt
RMFILE = T:rdefs.m
R2MFILE= T:r2defs.m
R2MAIN = ppt020

#   Example files. These are currently scanned for autodoc
#   entries
EXAMPLES  = $(EXTSRCDIR)/sample_effect/sample_effect.c \
            $(EXTSRCDIR)/sample_loader/loader.c


#####################################################################
#
#   Compilers and their options used.
#   This is for the debug-version
#

#CC     = dcc
#COPTS  = -proto -Ht:defs.m=defs.h -mi -DDEBUG_MODE -d1 -ms
CC     = SC
COPTS  = NOICONS IDIR=dinclude:pd IDIR=include IDIR=$(FLOATGADGET) IDIR=$(POWERUP) \
         CONSTLIB NOSTKCHK STREQV STRMERGE IGNORE=304 NOCHKABORT \
         IGNORE=104 MATH=S MEMSIZE=HUGE IDIR=/imageclass

# a68k makes erroneous code!
#AS     = das
#ASOPTS =
AS     = SC
ASOPTS = DEBUG=LINE

# LINK   = dcc
# LINKOPTS = -lbgui -lm
LINK   = SC LINK
LINKOPTS = MATH=S

#
# If using Fortify, then link together with the
# following files.
#
FORTOBJS = /fortify/fortify.o
FORTLITEOBJS = /fortify/fortifylite.o
#FORTCOPTS = -DFORTIFY
#FORTLOPTS = -lpptsupp -L$(MAINDIR)/linklib
FORTCOPTS  = Define=FORTIFY
FORTLOPTS  = LIB=$(MAINDIR)/linklib/pptsupp.lib

#
#  Debugger version.
#
#  NB: It is compiled for my system, ie. 060
#
#DCOPTS = -d1
#LDFLAGS= $(LINKOPTS) $(FORTLOPTS) -s
DCOPTS = DEF=DEBUG_MODE DEBUG=SF ERRORREXX GST=$(GST) CPU=68000 DEF=PARANOID_MALLOC
LDFLAGS = $(LINKOPTS) $(FORTLOPTS) ADDSYM

#
#  Release version
#
#  NB:  If compiling for 020+, then remove utillib from the command line
#
#RCOPTS = -ms -mi -proto -H$(RMFILE)=defs.h
RCOPTS  = OPT OPTSCHED DEBUG=LINE PARMS=R CPU=000 UTILLIB \
          GST=include:all.gst

R2COPTS = OPT OPTSCHED DEBUG=LINE PARMS=R CPU=020 NOUTILLIB \
          GST=include:all.gst

RLDFLAGS= $(LINKOPTS) $(FORTLOPTS)

R2LDFLAGS= $(LINKOPTS) $(FORTLOPTS)

STRIP   = SLINK $(RMAIN) TO $(RMAIN).strip STRIPDEBUG NOICONS
STRIP2  = SLINK $(R2MAIN) TO $(R2MAIN).strip STRIPDEBUG NOICONS

#
#  Non-optimized code
#
SLOWCFLAGS = NOOPTSCHED

#####################################################################
#
#  End of configurational stuff.  This section defines the
#  differences in compilers.
#
#  Syntax options
#

# DCC
#OBJNAME = -o
#COMPILE = -c
#LINKTO  = -o

# SAS
OBJNAME = OBJNAME
COMPILE =
LINKTO  = TO

#####################################################################
#
#   C sources and assembler source codes.
#

SRCS = initexit.c \
       debug.c \
       load.c \
       edit.c \
       frame.c \
       main.c \
       select.c \
       input.c \
       toolbar.c \
       filter.c others.c message.c memory.c errors.c support.c infowin.c vm.c \
       render.c preview.c display.c rendermod.c dither.c dispdevs.c colormap.c palette.c \
       external.c prefs.c save.c palette_edit.c rexx.c ppt_cat.c \
       askreq.c gui.c extensions.c dropareaclass.c renderareaclass.c colors.c \
       getargs.c \
       rectangleselect.c pointselect.c ellipseselect.c freeselect.c

# These are compiled with profiling on
PROFSRCS = dummy.c

# These are not compiled with optimization on.

#SLOWSRCS = debug.c

ASSYS = render2.a


# Any change in these files forces a recompile as all sources
# depend on these.

# HDRS = ppt_real.h defs.h ppt_cat.h
HDRS = ppt_real.h defs.h

# A change in these headers forces a recompile of the pre-generated
# header files.

MHDRS = defs.h ppt_real.h protos.h machine-protos.h \
        render.h rexx.h ppt_cat.h gui.h include/askreq.h pptmessage.h toolbar.h

# These files version on version & gfx information

VSRCS = main.c gui.c prefs.c palette_edit.c askreq.c initexit.c external.c \
        display.c others.c toolbar.c rexx.c

#
#   Object files.
#

COBJS = $(SRCS:"*.c":"$(OD)/*.o")
AOBJS = $(ASSYS:"*.a":"$(OD)/*.o")
#SLOWOBJS = $(SLOWSRCS:"*.c":"$(OD)/*.o")
SLOWOBJS =
PROFOBJS = $(PROFSRCS:"*.c":"$(OD)/*.o")

# Those who depend on version & gfx information
VOBJS  = $(VSRCS:"*.c":"$(OD)/*.o")

# Render objects, depend on render.h
RENDOBJS = $(OD)/colormap.o $(OD)/palette.o $(OD)/rendermod.o $(OD)/dispdevs.o \
           $(OD)/dither.o $(OD)/palette_edit.o $(OD)/main.o


#
# Debug version
#

CFLAGS = $(COPTS) $(DCOPTS) $(FORTCOPTS)
#CFLAGS = $(COPTS) $(DCOPTS)
OBJS   = $(COBJS) $(AOBJS) $(FORTOBJS) $(SLOWOBJS) $(PROFOBJS)

#
#   Release version
#

RCFLAGS = $(COPTS) $(RCOPTS) $(FORTCOPTS)
RCOBJS  = $(SRCS:"*.c":"$(ROD)/*.o")
#RSLOWOBJS= $(SLOWSRCS:"*.c":"$(ROD)/*.o")
RSLOWOBJS=
RPROFOBJS = $(PROFSRCS:"*.c":"$(ROD)/*.o")
ROBJS   = $(RCOBJS) $(AOBJS) $(FORTLITEOBJS) $(RSLOWOBJS) $(RPROFOBJS)
RVOBJS  = $(VSRCS:"*.c":"$(ROD)/*.o")

#
#   020 Optimized, release version
#

R2CFLAGS = $(COPTS) $(R2COPTS) $(FORTCOPTS)
R2COBJS  = $(SRCS:"*.c":"$(R2OD)/*.o")
#RSLOWOBJS= $(SLOWSRCS:"*.c":"$(R2OD)/*.o")
R2SLOWOBJS=
R2PROFOBJS = $(PROFSRCS:"*.c":"$(R2OD)/*.o")
R2OBJS   = $(R2COBJS) $(AOBJS) $(FORTLITEOBJS) $(R2SLOWOBJS) $(R2PROFOBJS)
R2VOBJS  = $(VSRCS:"*.c":"$(R2OD)/*.o")


#####################################################################
#
#   End of configuration, now begins the compiler stuff
#

all : $(OD) $(GST) $(MFILE) $(MAIN) $(EXTSRCDIR)
        @List $(MAIN) NOHEAD
        @beep
        @Avail FLUSH >NIL:

release : $(ROD) $(RMFILE) $(RMAIN) $(EXTSRCDIR)
        @List $(RMAIN) NOHEAD
        @beep

release020 : $(R2OD) $(R2MFILE) $(R2MAIN) $(EXTSRCDIR)
        @List $(R2MAIN) NOHEAD
        @beep


$(OD) : $(OD)
        Makedir %(left)

$(ROD) : $(ROD)
        Makedir %(left)

$(R2OD): $(R2OD)
        Makedir %(left)

# Link phase

$(MAIN) : $(OBJS) $(VOBJS)
        @echo "Linking..." %(left)
        @$(LINK) $(OBJS) $(LINKTO) %(left) $(LDFLAGS)

$(RMAIN) : $(ROBJS)
        @echo "Linking..." %(left)
        @$(LINK) $(ROBJS) $(LINKTO) %(left) $(RLDFLAGS)

$(R2MAIN) : $(R2OBJS)
        @echo "Linking..." %(left)
        @$(LINK) $(R2OBJS) $(LINKTO) %(left) $(R2LDFLAGS)

#
# Compile phase
#

$(COBJS) : $(SRCS)
        @echo "Compiling" %(right)
        @$(CC) $(CFLAGS) %(right) $(OBJNAME) %(left) $(COMPILE)

#$(SLOWOBJS) : $(SLOWSRCS)
#        $(CC) $(CFLAGS) %(right) $(OBJNAME) %(left) $(COMPILE) $(SLOWCFLAGS)

$(PROFOBJS) : $(PROFSRCS)
        @echo "Compiling with profiling" %(right)
        @$(CC) $(CFLAGS) %(right) $(OBJNAME) %(left) $(COMPILE) PROFILE

$(AOBJS) : $(ASSYS)
        @echo "Assembling" %(right)
        @$(AS) $(ASOPTS) %(right) $(OBJNAME) %(left)

$(VOBJS) :: version.h gui.h

$(RENDOBJS) :: render.h

$(OD)/rexx.o :: rexx.h

$(OD)/external.o :: misc.h

$(RCOBJS) : $(SRCS)
        @echo "Compiling" %(right)
        @$(CC) $(RCFLAGS) %(right) $(OBJNAME) %(left) $(COMPILE)

#$(RSLOWOBJS) : $(SLOWSRCS)
#        $(CC) $(RCFLAGS) %(right) $(OBJNAME) %(left) $(COMPILE) $(SLOWCFLAGS)

$(RPROFOBJS) : $(PROFSRCS)
        @echo "Compiling with profiling" %(right)
        @$(CC) $(RCFLAGS) %(right) $(OBJNAME) %(left) $(COMPILE) PROFILE

$(COBJS) $(PROFOBJS) :: $(HDRS)

$(RCOBJS) $(RPROFOBJS) :: $(HDRS)

$(RVOBJS) :: version.h gui.h

$(ROD)/rexx.o :: rexx.h

$(ROD)/external.o :: misc.h

## 020

$(R2COBJS) : $(SRCS)
        @echo "Compiling" %(right)
        @$(CC) $(R2CFLAGS) %(right) $(OBJNAME) %(left) $(COMPILE)

#$(R2SLOWOBJS) : $(SLOWSRCS)
#        $(CC) $(R2CFLAGS) %(right) $(OBJNAME) %(left) $(COMPILE) $(SLOWCFLAGS)

$(R2PROFOBJS) : $(PROFSRCS)
        @echo "Compiling with profiling" %(right)
        @$(CC) $(R2CFLAGS) %(right) $(OBJNAME) %(left) $(COMPILE) PROFILE

$(R2COBJS) $(R2PROFOBJS) :: $(HDRS)

$(R2VOBJS) :: version.h gui.h

$(R2OD)/rexx.o :: rexx.h

$(R2OD)/external.o :: misc.h


# Externals

$(EXTSRCDIR) : include/ppt.h
        cd $(EXTSRCDIR)
        @dmake install

$(MFILE) : $(MHDRS)
        Delete $(MFILE) >NIL:

$(RMFILE) : $(MHDRS)
        Delete $(RMFILE) > NIL:

$(GST) : $(MHDRS)
        @echo "Rebuilding GST:" %(left)
        @Delete $(GST) >NIL:
        @SC MAKEGST=$(GST) $(COPTS) $(DCOPTS) gst.c IGNORE=105

$(RGST) : $(MHDRS)
        @echo "Rebuilding GST:" %(left)
        @Delete $(RGST) >NIL:
        @SC MAKEGST=$(RGST) $(COPTS) gst.c IGNORE=105

$(R2GST) : $(MHDRS)
        @echo "Rebuilding GST:" %(left)
        @Delete $(R2GST) >NIL:
        @SC MAKEGST=$(R2GST) $(COPTS) gst.c IGNORE=105

gst : $(GST) $(RGST) $(R2GST)

ext :
        cd $(EXTSRCDIR)
        @dmake install

# Make prototypes file

proto : $(SRCS) $(PROFSRCS)
        makeproto -o machine-protos.h $(SRCS) $(PROFSRCS)

# Makes a backup from everything except for object files.

backup :
        lha -re u $(BACKUPDIR)ppt.lha ~((pptd|ppt|ppt020|#?.(o|lnk|gst|effect|iomod|debug|library|library_e)))
        Copy IMPORTANT_README $(BACKUPDIR)
        @beep

# RCS update

rcs :
        ci -l -q *.c

# This makes a distribution

dist : all release release020 $(DISTDIR) docs bguilibs modinfo non-free
        Copy $(RMAIN) $(RMAIN).debug
        Copy $(R2MAIN) $(R2MAIN).debug
        $(STRIP)
        $(STRIP2)
        Copy $(RMAIN).strip $(RMAIN)
        Delete $(RMAIN).strip
        Copy $(R2MAIN).strip $(R2MAIN)
        Delete $(R2MAIN).strip
        dupdate $(MAINDIR) $(DISTDIR) FORCE
        Cd $(DISTDIR)
        Copy $(MAINDIR)/ppt_dir.info /PPT.info
        pgps -b ppt ppt020 -u jalkanen
        lha -r u $(ARCHIVEDIR)PPT_dist.lha $(DISTDIR)/#? /PPT.info
        Copy $(DISTDIR)/ReleaseNotes $(DISTDIR)/README $(DISTDIR)/HISTORY $(ARCHIVEDIR)
        Cd $(MAINDIR)
        Copy $(ARCHIVEDIR)PPT_dist.lha tmp:pptarchive/pptdist.lha
        lha u tmp:pptarchive/pptdist.lha $(RMAIN).debug $(R2MAIN).debug
        lha -x u $(ARCHIVEDIR)PPT_security.lha modules/EmbedFile.effect modules/ExtractFile.effect README_security
        @beep

strip :
        Copy $(RMAIN) $(RMAIN).debug
        $(STRIP)
        Copy $(RMAIN).strip $(RMAIN)
        Delete $(RMAIN).strip

debugdist : all
        slink $(MAIN) TO $(MAIN).strip NOICONS STRIPDEBUG
        copy $(MAIN) $(MAIN).debug
        copy $(MAIN).strip $(MAIN)
        Delete $(MAIN).strip
        lha a ram:ppt_debug.lha $(MAIN) README_DEBUG

$(DISTDIR) : $(DISTDIR)
        MakeDir $(DISTDIR)

$(DEVDIR) : $(DEVDIR)
        MakeDir $(DEVDIR)

$(NONFREEDIR) : $(NONFREEDIR)
        MakeDir $(NONFREEDIR)

# And this can be used to construct the link libraries

linklib:
        @cd linklib
        @dmake
        @beep

# Use this to make a new pragma library
#  MODE=3 => #ifndef PRAGMAS_XXX_PRAGMAS_H ... #endif

pragmas:
        cd include
        fd2pragma fd/pptsupp_lib.fd TO pragmas/pptsupp_pragmas.h MODE=3
        fd2pragma fd/module_lib.fd  TO pragmas/module_pragmas.h  MODE=3
        fd2pragma fd/effect_lib.fd  TO pragmas/effect_pragmas.h  MODE=3
        fd2pragma fd/iomod_lib.fd   TO pragmas/iomod_pragmas.h   MODE=3
        fd2inline fd/pptsupp_lib.fd clib/pptsupp_protos.h > inline/pptsupp.h
        fd2inline fd/module_lib.fd clib/module_protos.h > inline/module.h
        fd2inline fd/effect_lib.fd clib/effect_protos.h > inline/effect.h
        fd2inline fd/iomod_lib.fd clib/iomod_protos.h > inline/iomod.h
        @cd /

# This will build the ppt catalog strings

ppt_cat.c : Catalogs/ppt.cd
        FlexCat Catalogs/ppt.cd ppt_cat.c=Catalogs/ppt_c.sd

ppt_cat.h : Catalogs/ppt.cd
        FlexCat Catalogs/ppt.cd ppt_cat.h=Catalogs/ppt_h.sd

locale: catcode catalogs

catcode:
        FlexCat Catalogs/ppt.cd ppt_cat.c=Catalogs/ppt_c.sd
        FlexCat Catalogs/ppt.cd ppt_cat.h=Catalogs/ppt_h.sd

catalogs:
        cd Catalogs
        FlexCat ppt.cd suomi/ppt.ct CATALOG suomi/ppt.catalog
        cd /

refreshcatalogs:
        cd Catalogs
        FlexCat ppt.cd suomi/ppt.ct NEWCTFILE suomi/ppt.ct

# This will reconstruct the developer docs.

docs:
        adoc -I -c $(SRCS) linklib/debug/debug.c > docs/support_all.doc
        adoc -I -c $(EXAMPLES) > docs/externals.doc
        Delete dme.refs
        autorefs dme.refs docs/support_all.doc docs/externals.doc

devdocs:
        adoc --yank-type "u" -I -c $(SRCS) linklib/debug/debug.c > docs/support.doc
        adoc -I -c $(EXAMPLES) > docs/externals.doc

#
# Support stuff
#

modinfo : ModuleInfo/moduleinfo

ModuleInfo/moduleinfo : ppt_real.h
        cd ModuleInfo
        @dmake install
        @cd /

#
# Developer archive
#

devarc : devdocs pragmas $(DEVDIR)
        dupdate $(MAINDIR) $(DEVDIR) FORCE DISTFILE .DistFiles_dev
        lha -r u $(ARCHIVEDIR)PPT_dev.lha $(DEVDIR)/#?

ppcdev :
        lha -re u ram:PPT_ppcdev.lha pluginsrc/sample_effect_ppc/~(#?.(o|effect))

#
# Non-free stuff
#

non-free : $(NONFREEDIR)
        dupdate $(MAINDIR) $(NONFREEDIR) FORCE DISTFILE .DistFiles_nonfree
        cd $(NONFREEDIR)
        lha -r u $(ARCHIVEDIR)PPT_nonfree.lha #?
        cd $(MAINDIR)

# This can be used to force recompile

force : touch all

touch :
        Touch defs.h

#
#   Extract the real ppt.h file
#

ppt.h : ppt_real.h
        extract ppt_real.h    include/ppt.h
        extract pptmessage.h  include/pptmessage.h
        touch $(EXTSRCDIR)

#
#   PGP signatures
#

pgpsig : dist
        @cd $(DISTDIR)
        pgp -sba ppt -u jalkanen

#
#   BGUI libraries to the add-on place
#

bguilibs :
        cd floatgadget
        @smake install
        @cd /
        copy sys:classes/gadgets/bgui_float.gadget libs/
        copy sys:classes/gadgets/bgui_bitmap.image libs/

#
#   Use this to name a release.  Set the $RELEASE to point at this.
#

namerelease :
        rcs -n$(RELEASE): *.[ch] dmakefile install ReleaseNotes Catalogs/ppt.cd Docs/#?.guide

showsizes : showsizes.c
        $(CC) $(CFLAGS) %(right) LINK

