# # Copyright (c) 1994 The University of Utah and # the Computer Systems Laboratory (CSL). All rights reserved. # # Permission to use, copy, modify and distribute this software and its # documentation is hereby granted, provided that both the copyright # notice and this permission notice appear in all copies of the # software, derivative works or modified versions, and any portions # thereof, and that both notices appear in supporting documentation. # # THE UNIVERSITY OF UTAH AND CSL ALLOW FREE USE OF THIS SOFTWARE IN ITS "AS # IS" CONDITION. THE UNIVERSITY OF UTAH AND CSL DISCLAIM ANY LIABILITY OF # ANY KIND FOR ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE. # # CSL requests users of this software to return to csl-dist@cs.utah.edu any # improvements that they make and grant CSL redistribution rights. # # Author: Bryan Ford, University of Utah CSL # ifndef _mach4_makerules_ _mach4_makerules_ = yes # This makefile defines generic symbols and rules # used by the makefiles in the various mach4 subdirectories. # It is heavily dependent on GNU make running on something like Unix. # Building the game with different tools requires a different set of makefiles. # # GSRCDIR must be set to the directory of the generic mach4 source tree. # (The current directory is assumed to be the object directory.) # # OBJDIR must be set to the top-level object directory # (i.e. a series of `..'s indicating how deep we are at the moment). # # DEFINES can be set to a string of -D options (e.g. -DDEBUG). # INCDIRS can be a list of system include directories to be searched by #include <>'s. # LIBDIRS can be a list of library directories. # xxx_CPPFLAGS can be set to other flags for the C preprocessor and anything that uses it. # xxx_CFLAGS can be set to other flags for the C compiler. # xxx_LDFLAGS can be set to other flags for the linker. # # Replace xxx with HOST, TARGET, or ALL # depending on which rules you want to affect. # # The standard flags variables (CFLAGS, CPPFLAGS, etc.) # are used by the rules but never defined, # so you can supply them on the make command line # (e.g. `make CFLAGS=-save-temps'). # Always use the traditional Bourne shell for commands. SHELL := /bin/sh # Old defines that I hope to phase out DEFINES += -DMACH -DCMU # Compilation of Mach itself and its satellite programs # should always use the headers in the source and object directories # instead of any that might already be in the installation directory. INCDIRS += $(GSRCDIR)/include $(OBJDIR)/include HOST_INCDIRS += $(INCDIRS) ifeq ($(NO_LIBMACHSA_INC),yes) TARGET_INCDIRS += $(INCDIRS) else TARGET_INCDIRS += $(INCDIRS) $(GSRCDIR)/include/mach/sa endif # Where to get libraries from. LIBDIRS += $(OBJDIR)/lib # Use MIG from the object directories, not the installation directories. # Note that MIG runs on the host but generates code for the target. MIG = $(OBJDIR)/mig/mig export MIGDIR = $(OBJDIR)/mig # Command to make multiple levels of directories in one shot. # XXX install can do this too; would it be better? # Perhaps a job for autoconf? MKDIR = -mkdir -p # Some of the rules below may be used to build things # to be executed on either the host or the target. # The COMPILE_FOR variable is used to select HOST_* or TARGET_* variables. # Use TARGET_* by default. ifndef COMPILE_FOR COMPILE_FOR = TARGET endif TARGET_CC = $(CC) # Compilation flags # XXX -I- should be between SRCDIRS and INCDIRS ALL_CPPFLAGS += -MD $(DEFINES) -I- -I. $(addprefix -I,$(SRCDIRS)) HOST_CPPFLAGS += $(ALL_CPPFLAGS) $(addprefix -I,$(HOST_INCDIRS)) ifeq ($(STDINC),yes) TARGET_CPPFLAGS += $(ALL_CPPFLAGS) $(addprefix -I,$(TARGET_INCDIRS)) else TARGET_CPPFLAGS += $(ALL_CPPFLAGS) $(addprefix -I,$(TARGET_INCDIRS)) -nostdinc endif HOST_CFLAGS += $(HOST_CPPFLAGS) $(ALL_CFLAGS) -O TARGET_CFLAGS += $(TARGET_CPPFLAGS) $(ALL_CFLAGS) -O1 # MIG is never used to generate anything that will run on the host. TARGET_MIGFLAGS += $(TARGET_CPPFLAGS) ALL_LDFLAGS += $(addprefix -L,$(LIBDIRS)) HOST_LDFLAGS += $(ALL_LDFLAGS) TARGET_LDFLAGS += $(ALL_LDFLAGS) -nostdlib # Where to find source files SRCDIRS := $(SRCDIRS) space := $(empty) $(empty) VPATH := $(subst $(space),:,$(SRCDIRS)) # First find a list of every file that might possibly be a source file, # so we only have to scan the source directories once. FILES := $(foreach DIR,$(SRCDIRS),$(wildcard $(DIR)/*)) # C source files CFILES := $(filter %.c,$(FILES)) # How to compile them. %.o: %.c $($(COMPILE_FOR)_CC) -c $(CPPFLAGS) $(CFLAGS) $($(COMPILE_FOR)_CFLAGS) $< # Server-side presentation files SRVFILES := $(filter %.srv,$(FILES)) # Client-side presentation files CLIFILES := $(filter %.cli,$(FILES)) # Client-and-server presentation files PRESFILES := $(filter %.pres,$(FILES)) # C files automatically generated from these MIG definitions. GEN_CFILES += \ $(patsubst %.srv,%_server.c,$(notdir $(SRVFILES))) \ $(patsubst %.cli,%_user.c,$(notdir $(CLIFILES))) \ $(patsubst %.pres,%_user.c,$(notdir $(PRESFILES))) \ $(patsubst %.pres,%_server.c,$(notdir $(PRESFILES))) CLEAN_FILES += $(GEN_CFILES) \ $(patsubst %.srv,%_interface.h,$(notdir $(SRVFILES))) \ $(patsubst %.cli,%.h,$(notdir $(CLIFILES))) \ $(patsubst %.pres,%.h,$(notdir $(PRESFILES))) .PRECIOUS: $(GEN_CFILES) # How to generate MIG stubs from presentation files. %_interface.h %_server.c: %.srv $(MIG) $(MIGFLAGS) $(TARGET_MIGFLAGS) \ -header $*_interface.h -server $*_server.c -user /dev/null $< %.h %_user.c: %.cli $(MIG) $(MIGFLAGS) $(TARGET_MIGFLAGS) \ -header $*.h -user $*_user.c -server /dev/null $< %.h %_user.c %_server.c: %.pres $(MIG) $(MIGFLAGS) $(TARGET_MIGFLAGS) \ -header $*.h -user $*_user.c -server $*_server.c $< # How to generate symbol header files, # containing #define's for numeric constants # related to C structures on the target machine. # These are currently used in two ways: # # * When cross-compiling, MIG is compiled to be executed on the host, # but it needs to know the sizes of certain types on the target machine. # So a symbol header file is created with the cross-compiler, # and then used in compiling MIG for the host machine. # # * Assemblers don't know about C structures, # so machine-specific assembly language code # can use symbol header files instead. %.symc: %.sym $(AWK) -f $(GSRCDIR)/gensym.awk $< >$*.symc %.symc.o: %.symc $(TARGET_CC) -S $(CPPFLAGS) $(CFLAGS) \ $(TARGET_CFLAGS) -x c -o $@ $< %.h: %.symc.o sed <$< -e 's/^[^*].*$$//' | \ sed -e 's/^[*]/#define/' -e 's/mAgIc[^-0-9]*//' >$@ CLEAN_FILES += *.symc *.symc.o # How to install files into their final resting places. $(INSTALL_BINDIR)/%: % $(MKDIR) $(INSTALL_BINDIR) $(INSTALL) $< $@ $(INSTALL_LIBDIR)/%: % $(MKDIR) $(INSTALL_LIBDIR) $(INSTALL) $< $@ $(INSTALL_BOOTDIR)/%: % $(MKDIR) $(INSTALL_BOOTDIR) $(INSTALL) $< $@ $(INSTALL_INCDIR)/%.h: $(OBJDIR)/include/%.h $(MKDIR) $(patsubst %/,%,$(dir $@)) $(INSTALL) -m 644 $< $@ # Always fully build everything before trying to install anything install: all # Get rid of a bunch of nasty built-in implicit rules, # to avoid bogus circular dependencies and make things go faster. # Use the `-r' command line option to make to get even better performance. .SUFFIXES: # The generated object files have the same prefix names as the source files, # except they live in the current (object) directory. # Compile MIG files before other C source files, # because they create header files used in the other sources. GEN_OBJFILES += \ $(patsubst %.c,%.o,$(GEN_CFILES)) \ $(patsubst %.c,%.o,$(notdir $(CFILES))) # Sometimes pre-compiled object files are included in source directories # because their source code is proprietary. OBJFILES += $(GEN_OBJFILES) # This is to eliminate duplicate files, # which might appear when files are being overridden. OBJFILES := $(sort $(OBJFILES)) # Only clean the object files we generated (GEN_OBJFILES), # not all the object files (OBJFILES). CLEAN_FILES += $(GEN_OBJFILES) .PRECIOUS: $(GEN_OBJFILES) # To install, at the very least we also want to make everything. install: all # How to clean out the automatically built stuff in an object directory. clean: rm -rf *.d *.bak *.kmod tags depend $(CLEAN_FILES) # How to update the dependency file in an object directory. # This funny bit of magic (hopefully the most obscure thing here) # basically replaces the `md' program in ODE. # The `sed' line removes the dependencies being replaced, # the `for' line tacks the new dependencies to the end of the file, # and then the individual dependency files are deleted. comma := , depend: $(wildcard *.d) @if test -f depend; then sed $(patsubst %.d,-e '/^%\.o/$(comma)/^#/d',$^) depend.new; fi; true @(for file in $^ /dev/null; do (cat $$file; echo '#'); done) >>depend.new @mv -f depend.new depend @if test "" != "$^"; then rm -f $^; fi; true # Include the dependency graph (if it exists). -include depend endif