
# YOU DO NOT NEED TO CONFIGURE ANYTHING IN THIS FILE.
#
# RUN THE SHELL SCRIPT ./build.MudOS to generate the Makefiles, and follow
# its instructions.
#
############################################################################
#
# **** TARGETS AND THEIR CORRECT USAGE ****
#
# COMPILATION TARGETS:
# 
# all:		compile all the files
#
# install:	make all, then move the files to the correct directories
#
# remake: 	remove the object files and generated files, and recompile
# 		     NO reconfiguration is done, etc.
#
# depend:	automatically create dependency info
#
# Makefiles:	update Makefile.in and GNUmakefile.in from Makefile.master
#		(only necessary after making changes to Makefile.master)
#
# 'CLEAN' TARGETS:
#
# neat: 	remove object files and generated files (used by remake)
#
# clean:	in addition to neat, also remove .orig and .rej files,
#		cores, lint files, emacs backups, tag files, yacc debug
#		files, generated Makefiles, generated binaries, and
#		generated dependency info
#
# spotless:	make clean, then remove ALL CONFIGURATION AND CUSTOMIZATION
#		     useful for creating distributions
#
# ---- REALLY COMPLEX OPTIONS YOU PROBABLY DON'T WANT TO TOUCH -----
#
# NeXT: link with MallocDebug if you have a NeXT with NeXTOS 2.1 or later and
# you wish to search for memory leaks (see /NextDeveloper/Apps/MallocDebug).
# Note: linking with MallocDebug will cause the virtual size of the
# driver process to reach appoximately 40MB however the amount of real memory
# used will remain close to normal.
#EXTRALIBS=-lMallocDebug -lsys_s
#
# ---- DO NOT EDIT ANYTHING BELOW HERE UNLESS YOU KNOW ALOT ABOUT HOW
#      MUDOS WORKS INTERNALLY ----

OVERRIDES=$(MAKEOVERRIDES)

# **************************************************************************
# **** NOTE: If you add something here, also add it to the OBJ= rule below,
# **** or non-GNU makes will die
# **************************************************************************
SRC=grammar.tab.c lex.c main.c rc.c interpret.c simulate.c file.c object.c \
  backend.c array.c mapping.c comm.c ed.c regexp.c buffer.c crc32.c \
  malloc.c mallocwrapper.c class.c efuns_main.c efuns_port.c \
  call_out.c otable.c dumpstat.c stralloc.c hash.c \
  port.c reclaim.c parse.c simul_efun.c sprintf.c program.c \
  compiler.c avltree.c icode.c trees.c generate.c scratchpad.c \
  socket_efuns.c socket_ctrl.c qsort.c eoperators.c socket_err.c md.c \
  disassembler.c uvalarm.c $(STRFUNCS) \
  replace_program.c master.c function.c \
  debug.c crypt.c add_action.c eval.c fliconv.c console.c applies_table.c

all: cc.h files main_build
main_build2: $(DRIVER_BIN) addr_server portbind

main_build: files
	$(MAKE) main_build2

parallel:
	$(MAKE) -k -l -j 6 cc.h files
	$(MAKE) -k -l -j 6 main_build

OBJ=grammar.tab.o lex.o main.o rc.o interpret.o simulate.o file.o object.o \
  backend.o array.o mapping.o comm.o ed.o regexp.o buffer.o crc32.o \
  malloc.o mallocwrapper.o class.o efuns_main.o efuns_port.o \
  call_out.o otable.o dumpstat.o stralloc.o hash.o \
  port.o reclaim.o parse.o simul_efun.o sprintf.o program.o \
  compiler.o avltree.o icode.o trees.o generate.o scratchpad.o \
  socket_efuns.o socket_ctrl.o qsort.o eoperators.o socket_err.o md.o \
  disassembler.o uvalarm.o $(STRFUNCS) \
  replace_program.o master.o function.o \
  debug.o crypt.o add_action.o eval.o fliconv.o console.o applies_table.o

.c.o:
	$(CC) $(CFLAGS) $(OPTIMIZE) -c $*.c

# Some OS's can't deal with these being created during the make process?
malloc.o: malloc.c

mallocwrapper.o: mallocwrapper.c

lex.o: lex.c preprocess.c cc.h grammar.tab.c

grammar.tab.o: grammar.tab.c opcodes.h

which_makefile:
	echo MakeIsMake

grammar.tab.c: grammar.y
	$(YACC) grammar.y
	-rm -f grammar.tab.*
	sed "s/y.tab.c/grammar.tab.c/g" y.tab.c  > grammar.tab.c
	-mv y.tab.h grammar.tab.h

packages/packages.a: packages/parser.c packages/contrib.c
	(cd packages; $(MAKE) 'CC=$(CC)' 'CFLAGS=$(CFLAGS) $(OPTIMIZE)' 'RANLIB=$(RANLIB)' 'A=$(A)' 'O=$(O)')

$(DRIVER_BIN): packages/packages.a $(OBJ)
	-mv -f $(DRIVER_BIN) $(DRIVER_BIN).old
	$(PROOF) $(CC) $(CFLAGS) $(OPTIMIZE) $(OBJ) -o $(DRIVER_BIN) packages/packages.a $(EXTRALIBS) `cat system_libs`

addr_server: files addr_server.o socket_ctrl.o port.o addr_server.h
	$(CC) $(CFLAGS) $(OPTIMIZE) socket_ctrl.o addr_server.o port.o \
	-o addr_server `cat system_libs`

portbind: portbind.o
	$(CC) $(CFLAGS) $(OPTIMIZE) portbind.o -o portbind `cat system_libs`

remake: neat all

customize:
	-cp ../local_options .
	-cp ../system_libs .
	-cp ../configure.h .

depend: opcodes.h grammar.tab.c cc.h efunctions.h efun_defs.c configure.h
	makedepend *.c

cc.h: Makefile
	rm -f cc.h
	echo "/* this file automatically generated by the Makefile */" > cc.h
	echo '#define COMPILER "$(CC)"' >> cc.h
	echo '#define OPTIMIZE "$(OPTIMIZE)"' >> cc.h
	echo '#define CFLAGS   "$(CFLAGS) $(OPTIMIZE)"' >> cc.h
	echo '#define OBJDIR   "$(OBJDIR)"' >> cc.h

# the touches here are necessary to fix the modification times; link(2) does
# 'modify' a file
files: edit_source sysmalloc.c smalloc.c bsdmalloc.c debugmalloc.c wrappedmalloc.c options.h op_spec.c func_spec.c packages/Makefile.pre packages/GNUmakefile.pre configure.h grammar.y.pre
	./edit_source -options -malloc -build_func_spec '$(CPP) $(CFLAGS)' \
	              -process grammar.y.pre
	./edit_source -process packages/Makefile.pre
	./edit_source -process packages/GNUmakefile.pre
	./edit_source -build_efuns -build_applies
	touch mallocwrapper.c
	touch malloc.c
	touch files

make_func.tab.c: make_func.y cc.h
	$(YACC) $(YFLAGS) make_func.y
	-rm -f make_func.tab.c
	mv y.tab.c make_func.tab.c

configure.h: edit_source build.FluffOS
	-if test \( ! -r configure.h \) -o \( ! -r configuration \); then \
	    rm -f configuration; \
	    touch configuration; \
	fi
	if test "Machine `uname -a` Configure version 5" = "`cat configuration`"; then \
	    echo "Skipping configuration ..."; \
	else \
	    ./edit_source -configure; \
	    echo "Machine `uname -a` Configure version 5" > configuration; \
	fi

edit_source.o: edit_source.c preprocess.c cc.h

edit_source: edit_source.o hash.o make_func.tab.o
	$(CC) $(CFLAGS) edit_source.o hash.o make_func.tab.o -o edit_source

edit_source.o: edit_source.c
	$(CC) $(CFLAGS) -c $*.c

make_func.tab.o: make_func.tab.c
	$(CC) $(CFLAGS) -c $*.c

hash.o: hash.c
	$(CC) $(CFLAGS) $(OPTIMIZE) -c $*.c

tags: force
	ctags *.c *.y

TAGS: force
	etags *.c *.y

force:

install: all
	-mkdir $(INSTALL_DIR)
	$(INSTALL) $(DRIVER_BIN) $(INSTALL_DIR)
	$(INSTALL) addr_server $(INSTALL_DIR)
	$(INSTALL) portbind $(INSTALL_DIR)

Makefiles: Makefile.in GNUmakefile.in NMakefile.in

Makefile.in: edit_source Makefile.in.pre Makefile.master
	./edit_source -process Makefile.in.pre

GNUmakefile.in: edit_source GNUmakefile.in.pre Makefile.master
	./edit_source -process GNUmakefile.in.pre

NMakefile.in: edit_source NMakefile.in.pre Makefile.master
	./edit_source -process NMakefile.in.pre

nothing:

# remove local configuration
spotless: clean
	-rm -f configure.h local_options system_libs configuration
	-rm -f options_incl.h
	-rm -f *.diffs
	-find . -name "*~" -print | xargs rm

# get ready for recompile
neat:
	-(cd packages; $(MAKE) "A=$(A)" "O=$(O)" clean)
	-rm -rf $(OBJDIR) *.$(O) *.tab.c *.tab.h
	-rm -f efun_defs.c option_defs.c
	-rm -f opcodes.h efunctions.h opc.h efun_protos.h
	-rm -f malloc.c mallocwrapper.c
	-rm -f func_spec.cpp applies.h applies_table.c files
	-rm -f grammar.y comptest* a.out
	-rm -f packages/Makefile packages/GNUmakefile packages/packages

# remove everything except configuration
clean: neat
	-rm -f Makefile.MudOS GNUmakefile.MudOS
	-rm -f cc.h edit_source
	-rm -f core y.output testsuite/core testsuite/tmp/*
	-rm -f testsuite/OPCPROF.* testsuite/opc.*
	-rm -rf testsuite/binaries testsuite/single/swapfile.*
	-rm -f testsuite/OBJ_DUMP* testsuite/test_file testsuite/testfile
	-rm -f testsuite/tmp_eval_file.c testsuite/sf.o testsuite/ed_test
	-rm -f testsuite/log/log testsuite/log/debug.log testsuite/log/compile
	-find . -name "*~" -print | xargs rm
	-find . -name "*.orig" -print | xargs rm
	-find . -name "*.rej" -print | xargs rm
	-rm -f *.ln tags TAGS
	-rm -f $(DRIVER_BIN) $(DRIVER_BIN).old addr_server portbind
# DO NOT DELETE THIS LINE -- make depend depends on it.
