#
# Makefile
#
#  1998 Straylight/Edgeware
#

#----- Licensing note -------------------------------------------------------
#
# This makefile is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This makefile is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this makefile.  If not, write to the Free Software Foundation,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.

#----- Compilation flags ----------------------------------------------------

# --- Uncomment to use the C4 tools ---

# OLD = o-

# --- C compilation ---

CC = $(OLD)cc -c -o $@
CFLAGS = -depend !Depend -throwback -ffah -Ilibs: -IC:
COMPILE = $(CC) $(CFLAGS)

# --- Assembling ---

AS = $(OLD)objasm -quit -to $@
ASFLAGS = -stamp -depend !Depend -throwback
ASSEMBLE = $(AS) $(ASFLAGS) -from

BAS = basasm

# --- Linking ---

LD = $(OLD)link -o $@
LD_APP = $(LD) -aif
LD_UTIL = $(LD) -bin -base 0
LD_MOD = $(LD) -bin -base 0
LD_BIN = $(LD) -bin -base 0
LD_DLL = $(LD) -rmf
LD_AOF = $(LD) -aof

# --- Making libraries ---

AR = $(OLD)libfile -o

CDLL = cdll

# --- Setting file types ---

SET_APP = SetType $@ FF8
SET_MOD = SetType $@ FFA
SET_UTIL = SetType $@ FFC
SET_DLL = SetType $@ FFD

# --- Other maintenance things ---

RM = ssrclean
INSTALL = inst
SETDATE = setdate
SQUEEZE = squeeze $@
DATE = %zdy %mo %ce%yr
MODDATE = %dy %m3 %ce%yr
CRIGHT =  %ce%yr Straylight
FIXLINK = fixlink $@

#----- Default rules --------------------------------------------------------

.SUFFIXES: .o .c .s .bs
.c.o:
	$(COMPILE) $<
.s.o:
	$(ASSEMBLE) $<
.bs.o:
	$(BAS) $< $@

#----- Object files ---------------------------------------------------------

PROGS = \
	enumerate hour pathutil test \
	each inst setdate setslot ssrclean submake \
	chdrgen headergen \
	buildstub fixlink msgaof resgen templaof

CULIB = o.culib

LIBS = $(CULIB) libs:aof.o.aof libs:o.astubs libs:o.swiv

#----- Compiling things -----------------------------------------------------

all: $(PROGS)

# --- Assembler utilities ---

ENUM_OBJ = o.enumerate
ENUM_VER = 1.03
enumerate: $(ENUM_OBJ)
	$(SETDATE) o.ver-enum version="$(ENUM_VER) [$(DATE)] ($(CRIGHT))"
	$(LD_UTIL) $(ENUM_OBJ) o.ver-enum
	$(SET_UTIL)

HOUR_OBJ = o.hour
HOUR_VER = 1.00
hour: $(HOUR_OBJ)
	$(SETDATE) o.ver-hour version="$(HOUR_VER) [$(DATE)] ($(CRIGHT))"
	$(LD_UTIL) $(HOUR_OBJ) o.ver-hour
	$(SET_UTIL)

PATH_OBJ = o.path_util o.pathutil
PATH_VER = 1.10
pathutil: $(PATH_OBJ)
	$(SETDATE) o.ver-path version="$(PATH_VER) [$(DATE)] ($(CRIGHT))"
	$(LD_UTIL) $(PATH_OBJ) o.ver-path
	$(SET_UTIL)

SLOT_OBJ = o.setslot
SLOT_VER = 1.00
setslot: $(SLOT_OBJ)
	$(SETDATE) o.ver-slot version="$(SLOT_VER) [$(DATE)] ($(CRIGHT))"
	$(LD_UTIL) $(SLOT_OBJ) o.ver-slot
	$(SET_UTIL)

TEST_OBJ = o.test
TEST_VER = 1.00
test: $(TEST_OBJ)
	$(SETDATE) o.ver-test version="$(TEST_VER) [$(DATE)] ($(CRIGHT))"
	$(LD_UTIL) $(TEST_OBJ) o.ver-test
	$(SET_UTIL)

# --- Various C programs ---

EACH_OBJ = o.each $(LIBS)
each: $(EACH_OBJ)
	$(LD_APP) $(EACH_OBJ)
	$(SQUEEZE)
	$(SET_APP)

INST_OBJ = o.inst $(LIBS)
inst: $(INST_OBJ)
	$(LD_APP) $(INST_OBJ)
	$(SQUEEZE)
	$(SET_APP)

SDATE_OBJ = o.setdate $(LIBS)
SDATE_VER = 1.00
setdate: $(SDATE_OBJ)
	$(SETDATE) o.ver-sdate _time="$(SDATE_VER) [$(DATE)] ($(CRIGHT))"
	$(LD_APP) $(SDATE_OBJ) o.ver-sdate
	$(SQUEEZE)
	$(SET_APP)

SSRC_OBJ = o.ssrclean $(LIBS)
ssrclean: $(SSRC_OBJ)
	$(LD_APP) $(SSRC_OBJ)
	$(SQUEEZE)
	$(SET_APP)

SUBMAKE_OBJ = o.submake $(LIBS)
submake: $(SUBMAKE_OBJ)
	$(LD_APP) $(SUBMAKE_OBJ)
	$(SQUEEZE)
	$(SET_APP)

# --- Sapphire header creation tools ---

HGEN_OBJ = o.headergen $(LIBS)
headergen: $(HGEN_OBJ)
	$(LD_APP) $(HGEN_OBJ)
	$(SQUEEZE)
	$(SET_APP)

CHGEN_OBJ = o.chdrgen $(LIBS)
chdrgen: $(CHGEN_OBJ)
	$(LD_APP) $(CHGEN_OBJ)
	$(SQUEEZE)
	$(SET_APP)

# --- Basic tools ---

buildstub: b.buildstub ex.buildstub
	ccrunch -0 -xlibs:bas.exports -xex.buildstub b.buildstub buildstub

fixlink: b.fixlink
	ccrunch -0 b.fixlink fixlink

msgaof: b.msgaof ex.msgaof
	ccrunch -0 -xlibs:bas.exports -xex.msgaof b.msgaof msgaof

resgen: b.resgen ex.resgen
	ccrunch -0 -xlibs:bas.exports -xex.resgen b.resgen resgen

templaof: b.templaof ex.templaof
	ccrunch -0 -xlibs:bas.exports -xex.templaof b.templaof templaof

# --- The common library ---

LIBOBJS = o.alloc o.cmdr o.gf o.glob
o.culib: $(LIBOBJS)
	$(AR) -c $(CULIB) $(LIBOBJS)

# --- Standard targets ---

install: $(PROGS)
	$(INSTALL) $(PROGS) <SSR$BinDir>
	$(INSTALL) enumerate hour pathutil <SSR$DLLDir>

clean:
	-$(RM) o.* $(PROGS)

#----- Dynamic dependencies -------------------------------------------------

# Dynamic dependencies:
setslot: s.setslot
setslot: libs:header
setslot: libs:swis
setslot: libs:stream
test: s.test
test: libs:header
test: libs:swis
test: libs:stream
o.enumerate: s.enumerate
o.enumerate: libs:swis
o.enumerate: libs:header
o.hour: s.hour
o.hour: libs:header
o.hour: libs:swis
o.hour: libs:stream
o.path_util: s.path_util
o.path_util: libs:header
o.path_util: libs:swis
o.path_util: sh.pathUtil
o.pathutil: s.pathutil
o.pathutil: libs:header
o.pathutil: libs:swis
o.test: s.test
o.test: libs:header
o.test: libs:swis
o.test: libs:stream
o.inst:	c.inst
o.inst:	libs:h.swis
o.inst:	libs:h.swiv
o.inst:	c:h.kernel
o.inst:	h.cmdr
o.setdate:	c.setdate
o.setdate:	libs:h.swis
o.setdate:	c:h.kernel
o.setdate:	libs:aof.h.aof
o.setdate:	libs:aof.h.chunk
o.setdate:	libs:h._time
o.setslot: s.setslot
o.setslot: libs:header
o.setslot: libs:swis
o.setslot: libs:stream
o.ssrclean:	c.ssrclean
o.ssrclean:	libs:h.swis
o.ssrclean:	libs:h.swiv
o.ssrclean:	c:h.kernel
o.ssrclean:	h.cmdr
o.chdrgen:	c.chdrgen
o.chdrgen:	c:h.kernel
o.alloc:	c.alloc
o.alloc:	h.alloc
o.cmdr:	c.cmdr
o.cmdr:	libs:h.swis
o.cmdr:	libs:h.swiv
o.cmdr:	c:h.kernel
o.cmdr:	h.alloc
o.cmdr:	h.cmdr
o.cmdr:	h.gf
o.cmdr:	h.glob
o.glob:	c.glob
o.glob:	libs:h.swis
o.glob:	libs:h.swiv
o.glob:	c:h.kernel
o.glob:	h.alloc
o.glob:	h.gf
o.glob:	h.glob
o.submake:	c.submake
o.submake:	libs:h.swis
o.submake:	libs:h.swiv
o.submake:	c:h.kernel
o.submake:	h.alloc
o.submake:	h.glob
o.headergen:	c.headergen
o.headergen:	c:h.kernel
o.headergen:	libs:h.swis
o.gf:	c.gf
o.gf:	libs:h.swis
o.gf:	libs:h.swiv
o.gf:	c:h.kernel
o.gf:	h.gf
each:	c.each
each:	libs:h.swis
each:	libs:h.swiv
each:	c:h.kernel
each:	h.glob
o.each:	c.each
o.each:	c:h.kernel
o.each:	libs:h.swis
o.each:	libs:h.swiv
o.each:	h.glob
