#
# 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 ---------------------------------------------------------

STUBS = o.astubs o.asstubs o.mstubs o.msstubs o.dstubs

STUB_ENTRY = o.xentry o.xentry_swi o.xsmall o.xsmall_swi
STUB_PERSONALITY = o.xapp o.xdll o.xmodule
STUB_OTHER = o.xcommon o.xdata

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

all: o.rdump o.swiv $(STUBS)
	submake *.Makefile

# --- The `rdump' library ---

o.rdump: o._rdump
	$(AR) -c o.rdump o._rdump
o._rdump: s.rdump
	$(ASSEMBLE) s.rdump

# --- Various flavours of C library stubs ---

ASTUBS_OBJ = o.xapp o.xsmall $(STUB_OTHER)
o.astubs: $(ASTUBS_OBJ)
	$(LD_AOF) $(ASTUBS_OBJ)
	$(FIXLINK)

ASSTUBS_OBJ = o.xapp o.xsmall_swi $(STUB_OTHER)
o.asstubs: $(ASSTUBS_OBJ)
	$(LD_AOF) $(ASSTUBS_OBJ)
	$(FIXLINK)

DSTUBS_OBJ = o.xdll o.xentry
o.dstubs: $(DSTUBS_OBJ)
	$(LD_AOF) $(DSTUBS_OBJ)
	$(FIXLINK)

MSTUBS_OBJ = o.xmodule o.xentry $(STUB_OTHER)
o.mstubs: $(MSTUBS_OBJ)
	$(LD_AOF) $(MSTUBS_OBJ)
	$(FIXLINK)

MSSTUBS_OBJ = o.xmodule o.xentry_swi $(STUB_OTHER)
o.msstubs: $(MSSTUBS_OBJ)
	$(LD_AOF) $(MSSTUBS_OBJ)
	$(FIXLINK)

# --- Installation ---

install:
	submake *.Makefile -- install

# --- Cleaning up ---

clean:
	-$(RM) o.*
	submake *.Makefile -- clean

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

# Dynamic dependencies:
o.xsmall: s.xentry
o.xapp: libs:header
o.xapp: libs:swis
o.xsmall_swi: s.xentry
o.xmodule: libs:header
o.xmodule: libs:swis
o.xentry_swi: s.xentry
o.xcommon: libs:header
o.xdll: libs:header
o.xdll: libs:swis
o._rdump: libs:header
o._rdump: libs:swis
o.swiv: libs:header
o.swiv: libs:swis
o.swiv: libs:s.xswi
o.swiv: libs:s.swihack
