#
# Buildtemplate for V kernel
# m68k configuration-independent portion
# Tim Mann, January 27, 1984
#

#include ../../buildprefix

VPATH= ../m68k ../mi 

#ifdef X
#KNAME="xV Kernel"
KNAME="New & Improved xV Kernel"
#else X
KNAME="V Kernel"
#endif X

COMMONMI= init.b alien.b bpi.b dm.b enet.b kp.b ipc.b ikc.b ikcint.b \
  force.b hostcache.b groupipc.b lhost.b migrate.b migrate1.b mouse.b \
  naming.b null.b pm.b printx.b reboot.b time.b qk.b debug.b

COMMONMD= config.b machine.b trap.b exception.b console.b mice.b \
  msgtraps.b profile.b framebuffer.b _start.b

.SUFFIXES:

# how to compile a 68000 file
*.b: $*.c
	cc68 $(C68FLAGS) -c $*.c -o $@

# how to make an assembly file (Not deleting it or assembling it)
*.s: $*.c
	cc68 $(C68FLAGS) -S $*.c

# how to make an assembly listing
*.ls: $*.c
	cc68 $(C68FLAGS) -c -L $*.c

all: $(CONFIG)

# Sun2mem.c is compiled without the -O flag to get around an optimizer bug
# that is tickled in the bitfield operations in ClearModifiedPages
sun2mem.b: $(HOST)/sun2mem.c
	cc68 -v$(Xx)V -DMC68000 -DMC68010 -DSUN2 $(INCLPATH) -c \
		$(HOST)/sun2mem.c

# We search libV.a to find the runtime arithmetic routines
$(CONFIG): $(MIOBJECTS) $(MDOBJECTS)
	../newvers.sh $(KNAME) $(CONFIG)
	@echo -n "*** Linking version #"
	@cat version
	cc68 -c vers.c
	cc68 $(C68FLAGS) -o $(CONFIG) -X $(LD68FLAGS) vers.b \
		$(MIOBJECTS) $(MDOBJECTS) $(MDLIBS) ../../libc/m68k/libV.a
#	@echo "*** Making symbol table"
#	nm68 -n -h $(CONFIG) | grep -v " a " > symbols
	size68 -h $(CONFIG)
	@echo "***" $(CONFIG) complete.

mifiles: $(MIOBJECTS)

mdfiles: $(MDOBJECTS)

# How to make tags:
#   Tags should be made periodically, and also when you want 
#   to make sure that "tags" is up to date.
#   Sometimes it is necessary to delete "tags" in order to build
#   it (i.e. when you get the message "'tags' is up to date.").
#   The "tags" file copied into ../mi and ../m68k because ved uses 
#   the "tags" file in the current directory.
#   The "tags" file copied into ../mi and ../m68k is the most recent
#   "tags" file built for any particular object directory (eg. sun2+ec).

tags:
	csh -c \
	"ctags -tw {.,../m68k,../mi,../../libc/include/{mi,m68k}}/*.[ch]"
	cp tags ../mi/tags
	cp tags ../m68k/tags
	cp tags ../tags

# How to make the "dependencies" file using makedep.  We use -N to avoid
#   the tedium of recompiling the whole kernel every time there is a trivial
#   change in a system (V*.h) header file.  So beware if you change a
#   system header file that necessitates recompiling part of the kernel --
#   it will not be done automatically.
depend:
	makedep -N -e b -o dependencies -t m68k -I. -I$(HOST) -I$(MI) \
		*.c $(HOST)/*.c $(MI)/*.c

# Standard buildfile entries
install:
	-mv $(CONFIG).sav $(CONFIG).old
	cp $(CONFIG) $(CONFIG).sav

clean:
	rm -f *.o *.b *.s *.ls *.BAK *.CKP .emacs* .netupd*
	rm -f Vkernel.* symbols $(CONFIG) tags
