forked from openmach/mach4
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakerules
268 lines (211 loc) · 8.72 KB
/
Makerules
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
#
# 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 [email protected] 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 >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