-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathGNUmakefile.global
More file actions
534 lines (456 loc) · 13.3 KB
/
Copy pathGNUmakefile.global
File metadata and controls
534 lines (456 loc) · 13.3 KB
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
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
##
## Global Makefile for kernel and utilities. When invoked, the
## following variables can be set:
##
## TOP - Top of build directory
## SRCFILES - All source files for main target
## EXTRAOBJ - Extra object files to include in the main target
## PROG - program to build
## LIB - library to build (if PROG not set)
## AUXPROGS - auxiliary programs to build
## AUXCSRCS - auxiliary C files for dependencies
## OBJDIR - build in OBJDIR rather than current directory
## SUBDIRS - recurse into sub directories
## DEFS - any command line defines needed
## EXTRACLN - extra files to clean
## EXTRATRG - extra targets to make by default
## EXTRAINC - extra -I flags for compile command line
## DOPROF - when set to "yes" c files are built with profiling information
## DOBBPROF - when set to "yes" c files are built with basic block profiling
## UNINITOK - files for which to ignore uninitialized variable warnings
## UNUSEDOK - files for which unused variables are ok
## BADFORMATOK - files for which not to check args/types of printf, etc.
## WARNOK - files for which warnings are ok
## NOPROF - files not to profile
## NOBBPROF - files not to basic block profile
## NOOPT - files not to optimize
## PAXINSTALL - files to install with 'pax -r -w -luv'
## PAXINSTALLPREFIX - where to put the PAXINSTALL files
## LNPROGINSTALL - uses LN instead of 'install' to install programs
## LNLIBINSTALL - uses LN instead of 'install' to install libraries
LNPROGINSTALL = 1
LNLIBINSTALL = 1
include $(TOP)/ARCH
##
## Commands:
##
ifdef LINUX
CROSS=
else
CROSS =
endif
###############
# SET THIS TO YOUR VERSION OF GCC OR LEAVE IT COMMENTED OUT TO USE THE
# DEFAULT VERSION
##############
ifndef CC_VER
ifdef LINUX
CC_VER =
endif
ifdef OPENBSD
#CC_VER = -V 2.7.2.1
CC_VER = -V 2.8.1
endif
endif
CC = $(CROSS)cc $(CC_VER) -pipe -m32 -march=i386 -fomit-frame-pointer
NCC = cc $(CC_VER) -pipe -m32 -march=i386
GCC_LIB = `$(CC) -m32 -print-libgcc-file-name`
AS = $(CROSS)as
AR = $(CROSS)ar
RM = rm
LD = $(CROSS)ld
STRIP_PROG = $(CROSS)strip # named so as not to conflict with internal STRIP
CP = cp
MV = mv
INSTALL = install
RANLIB = $(CROSS)ranlib
BINPWD = /bin/pwd
PAX = pax
LN = ln
YACC = yacc
export NM $(CROSS)nm # lorder needs this set in the env
LORDER = $(TOP)/tools/lorder/lorder
ifdef LINUX
# tsort under LINUX seems to be broken
TSORT = cat
# which means that lorder isn't too usefull...
LORDER = echo
else
TSORT = tsort -q
endif
##
## Flags:
##
# A couple programs I've encountered bail on duplicate debug symbols with -g
ifndef DBG
DBG = -g -O6
endif
ifndef INC
INC = -nostdinc -I$(TOP)/include -I$(TOP)/sys $(EXTRAINC)
endif
WFLAGS += -Wall -Wno-comments -Wno-parentheses -Wno-char-subscripts $(EXTRAWFLAGS) # -Werror
EXTRADEFS =
ifdef VOS_DEBUG_LOCK # compile with debugging lock for vos
EXTRADEFS += -DVOS_DEBUG_LOCK
endif
ifdef EXO_SMP # compile with SMP on
EXTRADEFS += -D__SMP__
endif
ifdef EXO_ASH # compile with ASH on
EXTRADEFS += -D__ASH__
endif
ifdef EXO_PAM # compile with PAM on
EXTRADEFS += -D__PAM__
endif
ifdef EXO_ENCAP # force data encapsulation at compile time
EXTRADEFS += -D__ENCAP__
endif
ifdef EXO_HOST # compile as host
EXTRADEFS += -D__HOST__
endif
CFLAGS = $(DBG) $(INC) $(DEFS) -DEXOPC $(EXTRADEFS) $(WFLAGS)
ifndef LDFLAGS
ifndef LDADDR
LDADDR = 800020
endif # LDADDR
LDFLAGS = $(DBG) -static -N -Ttext $(LDADDR) -nostdlib
endif
LD_RULE = $(CC) -o $@ $(LDFLAGS) --start-group $^ --end-group $(GCC_LIB)
export HOME := /you/may/not/rely/on/HOME/in/exokernel/makefiles
##
## Targets always supported
##
all::
TARGETS = all install clean clobber
.PHONY: $(TARGETS)
FORCE:
@:
.PHONY: FORCE
##
## Get rid of any built-in suffix rules.
##
.SUFFIXES:
##
## Current directory. Use environment var PWD if it maps to the
## current directory (possibly through some simlinks or automount
## file systems). Otherwise, just use `$(BINPWD)`.
##
ifndef CURDIR
export CURDIR := ${shell curdir=`$(BINPWD)`; \
case "$(PWD)" in \
/*$) test "`cd $(PWD) && $(BINPWD)`" = "$$curdir" \
&& curdir=$(PWD) ;; \
esac; \
echo $$curdir}
endif # !CURDIR
##
## Figure out where to install based on where we are in the tree.
##
ifeq ($(DOINSTALL),yes)
ifndef INSTALLPREFIX
export INSTALLPREFIX := $(notdir $(patsubst %/, %, $(dir $(CURDIR))))
ifneq ($(filter $(INSTALLPREFIX), lib include),)
INSTALLPREFIX := usr/$(INSTALLPREFIX)
endif # INSTALLPREFIX is neither lib nor include
endif # INSTALLPREFIX
export DOINSTALL
endif # !DOINSTALL
##
## Now the fun begins. Build in $(OBJDIR) if it's defined
##
DOOBJDIR :=
ifdef OBJDIR
ifndef INOBJDIR
DOOBJDIR := yes
endif
endif
ifneq ($(PREORDER),yes)
ifneq ($(INOBJDIR),yes)
## Make subdirectories if $(SUBDIRS) is set
ifdef SUBDIRS
REALSUBDIRS := $(filter \
$(patsubst %/, %, $(shell ls -d $(SUBDIRS:=/) 2> /dev/null)), \
$(SUBDIRS))
$(TARGETS)::
@set -e; for dir in $(REALSUBDIRS); do \
(cd $$dir && $(MAKE) $(filter-out all, $@) \
CURDIR=$(CURDIR)/$$dir); \
done
clean::
ifdef SRCFILES
$(RM) -f $(AUXPROGS) $(PROG) $(LIB) $(EXTRACLN) \
core *.s *.o *.a *.d *~ *.core *.aout
else # !SRCFILES
rm -f *~ *.core core *.aout
endif # !SRCFILES
endif # SUBDIRS
endif # INOBJDIR
endif # !PREORDER
ifeq ($(DOOBJDIR),yes)
export OLDTOP := $(CURDIR)/$(TOP)
export OLDVPATH := $(VPATH)
$(TARGETS):: $(OBJDIR)
$(OBJDIR):
mkdir -p $@
OBJDIRRULE = \
@cd $(OBJDIR) && \
$(MAKE) -f $(CURDIR)/GNUmakefile $(filter-out all, $@) \
TOP=$(OLDTOP) CURDIR=$(CURDIR) INOBJDIR=yes SUBDIRS=
.PHONY: $(TARGETS) $(OBJDIR)
$(TARGETS)::
$(OBJDIRRULE)
%.o %.s:
$(OBJDIRRULE)
clean::
$(RM) -f $(addsuffix /*~, . $(VPATH)) \
$(addsuffix /*.aout, . $(VPATH)) \
$(addsuffix /*.core, . $(VPATH)) \
$(addsuffix /core, . $(VPATH))
-rmdir $(OBJDIR)
else # $(DOOBJDIR) empty
all:: $(EXTRATRG)
##
## If $(INOBJDIR) is defined, we should build from $(CURDIR).
##
ifeq ($(INOBJDIR),yes)
VPATHABS := $(filter /%, $(OLDVPATH))
VPATHREL := $(filter-out /%, $(OLDVPATH))
VPATH := $(addprefix $(CURDIR)/, . $(VPATHREL)) $(VPATHABS)
endif
##
## Static patern rules
##
# Don't fail when a stale ".d" file contains non-existent header files.
# This rule will cause the ".o" file to be remade, which will both cause
# an error if there really is a missing ".h" file, and rebuild the ".d"
# file.
%.h:
@:
%.o: %.S
$(CC) -MD -c $(INC) $(EXTRADEFS) $(DEFS) $<
# for some reason $(strip ...) works but $($(STRIP) ...) does not under LINUX
UNUSED_F=$(strip $(patsubst $(<F),-Wno-unused,$(filter $(<F), $(notdir $(UNUSEDOK)))))
UNINIT_F=$(strip $(patsubst $(<F), -Wno-uninitialized, $(filter $(<F), $(notdir $(UNINITOK)))))
BADFORMAT_F=$(strip $(patsubst $(<F), -Wno-format, $(filter $(<F), $(notdir $(BADFORMATOK)))))
WARNOK_F=$(strip $(patsubst $(<F),-Wno-error,$(filter $(<F), $(notdir $(WARNOK)))))
OPT_F =$(strip $(patsubst $(<F),-O0,$(filter $(<F), $(notdir $(NOOPT)))))
ifeq ($(DOPROF),yes)
FRAMEP_F=$(strip $(patsubst $(<F), ,$(patsubst ,-fno-omit-frame-pointer,$(filter $(<F), $(notdir $(NOPROF))))))
PROF_F =$(strip $(patsubst $(<F), ,$(patsubst ,-pg,$(filter $(<F), $(notdir $(NOPROF))))))
PROFDEF =$(strip $(patsubst $(<F), ,$(patsubst ,-DEXOPROFILE,$(filter $(<F), $(notdir $(NOPROF))))))
endif
ifeq ($(DOBBPROF),yes)
BBPROF =$(strip $(patsubst $(<F), ,$(patsubst ,-a,$(filter $(<F), $(notdir $(NOBBPROF))))))
endif
CC_COMPILE_RULE = $(CC) -MD -c $(PROF_F) $(PROFDEF) $(BBPROF) $(CFLAGS) $(OPT_F) $(FRAMEP_F) $(UNUSED_F) $(UNINIT_F) $(BADFORMAT_F) $(WARNOK_F) $<
%.o: %.c
$(CC_COMPILE_RULE)
%.o: %.s
$(CC) -c $<
## Get rid of debugging symbols
$(patsubst %.gdb, %, $(filter %.gdb, $(PROG))): %: %.gdb
rm -f $(notdir $@) $(notdir $@~)
$(CP) $< $(notdir $@~) && \
$(STRIP_PROG) $(notdir $@~) && mv -f $(notdir $@~) $(notdir $@)
## For embedding one program in another
%.b.c: %.b
rm -f $@
$(TOP)/tools/bintoc/bintoc $< $*_bin > $@~ && $(MV) -f $@~ $@
%.b.s: %.b
rm -f $@
$(TOP)/tools/bintoc/bintoc -S $< $*_bin > $@~ && $(MV) -f $@~ $@
## For examining compiler output
CC_COMPILE_2ASM_RULE = $(CC) -S -fverbose-asm $(PROF_F) $(PROFDEF) $(filter-out -g, $(CFLAGS)) $(OPT_F) $(FRAMEP_F) $(UNUSED_F) $(UNINIT_F) $(BADFORMAT_F) $(WARNOK_F) $<
%.s: %.c FORCE
$(CC_COMPILE_2ASM_RULE)
##
## Install rules
##
ifeq ($(DOINSTALL),yes)
ifdef EXODEST
ifndef EXTRAINSTALLPREFIX
EXTRAINSTALLPREFIX = etc
endif # EXTRAINSTALLPREFIX
ifndef EXTRAINSTALLPERMS
EXTRAINSTALLPERMS = 0444
endif # EXTRAINSTALLPERMS
ifdef OPENBSD
PAXCOMMAND = pax -r -w -luv
endif
ifdef LINUX
PAXCOMMAND = cp -R
endif
install:: all
ifdef PAXINSTALL
$(INSTALL) -d $(EXODEST)/$(PAXINSTALLPREFIX)/
($(PAXCOMMAND) $(PAXINSTALL) $(EXODEST)/$(PAXINSTALLPREFIX)/ || \
true)
endif # PAXINSTALL
ifdef EXTRAINSTALL
$(INSTALL) -d $(EXODEST)/$(EXTRAINSTALLPREFIX)/
$(INSTALL) -c -m $(EXTRAINSTALLPERMS) $(EXTRAINSTALL) \
$(EXODEST)/$(EXTRAINSTALLPREFIX)/
endif # EXTRAINSTALL
ifdef PROG
$(INSTALL) -d $(EXODEST)/$(INSTALLPREFIX)
ifdef LNPROGINSTALL
$(LN) -f $(PROG) $(EXODEST)/$(INSTALLPREFIX)
else
$(INSTALL) -c -s -m 0555 $(PROG) $(EXODEST)/$(INSTALLPREFIX)/
endif # !LNPROGINSTALL
endif # !PROG
ifdef LIB
$(INSTALL) -d $(EXODEST)/$(INSTALLPREFIX)
ifdef LNLIBINSTALL
$(LN) -f $(LIB) $(EXODEST)/$(INSTALLPREFIX)
else
$(INSTALL) -c -m 0444 $(LIB) $(EXODEST)/$(INSTALLPREFIX)/
endif # !LNLIBINSTALL
endif # LIB
else # !EXODEST
install::
@echo You must set EXODEST before making $@.
@false
endif # !EXODEST
endif # DOINSTALL
##
## Make target if there is one
##
AUXCSRCS += $(AUXPROGS:=.c)
ifdef SRCFILES
## Break $(SRCFILES) into each kind of file
SFILES := $(filter %.S, $(SRCFILES))
sFILES := $(filter %.s, $(SRCFILES))
CFILES := $(filter %.c, $(SRCFILES))
OBJFILES := $(SFILES:.S=.o) $(sFILES:.s=.o) $(CFILES:.c=.o) $(EXTRAOBJ)
##
## Build a program or library
##
ifdef PROG
all:: $(PROG)
ifdef INITPROG
BOUNCE = $(TOP)/lib/csu/bounce_initp.o
CRT0 = $(TOP)/lib/csu/crt0_initp.o
else
BOUNCE = $(TOP)/lib/csu/bounce.o
CRT0 = $(TOP)/lib/csu/crt0.o
endif #INITPROG
ifndef NOLIB
ifdef STATIC
$(PROG): $(CRT0) $(SFILES:.S=.o) $(sFILES:.s=.o) \
$(CFILES:.c=.o) $(EXTRAOBJ) $(TOP)/lib/libc/obj/libc.a $(LIBS)
else # not STATIC
$(PROG): $(BOUNCE) $(SFILES:.S=.o) $(sFILES:.s=.o) \
$(CFILES:.c=.o) $(EXTRAOBJ) $(TOP)/bin/shlib/libexos.so_stub.o $(LIBS)
endif # STATIC
else
$(PROG): $(SFILES:.S=.o) $(sFILES:.s=.o) $(CFILES:.c=.o) $(EXTRAOBJ)
endif
ifdef PRE_LINK
$(PRE_LINK)
endif # PRE_LINK
$(LD_RULE)
ifdef POST_LINK
$(POST_LINK)
endif # POST_LINK
else # no PROG
ifdef LIB
all:: $(LIB)
#NLIBOBJS := $(sort $(SFILES:.S=.o) $(CFILES:.c=.o) $(EXTRAOBJ))
#OLIBOBJS := $(sort $(filter-out __.SYMDEF, \
# $(shell test -f $(LIB) && ar t $(LIB))))
$(LIB): $(SFILES:.S=.o) $(CFILES:.c=.o) $(EXTRAOBJ)
ifdef STATIC
ifneq ($(NLIBOBJS), $(OLIBOBJS))
@$(RM) -f $@
@objs=`$(LORDER) $^ | $(TSORT)`; \
echo $(AR) cq $(LIB) $$objs; \
$(AR) cq $(LIB) $$objs
else # NLIBOBJS == OLIBOBJS
@if [ "`echo $? | wc -w`" -gt 7 ]; then \
rm -f $@; \
objs=`$(LORDER) $^ | $(TSORT)`; \
echo $(AR) cq $(LIB) $$objs; \
$(AR) cq $(LIB) $$objs; \
else \
echo $(AR) r $@ $?; \
$(AR) r $@ $?; \
fi
endif # NLIBOBJS == OLIBOBJS
$(RANLIB) $@
endif # STATIC
endif # LIB
endif # no PROG
endif # $(SRCFILES)
##
## Build auxiliary programs with the native C compiler
##
ifdef AUXPROGS
$(AUXPROGS): %: %.o
$(NCC) $(EXTRADEFS) $(AUXDEFS) -o $@ $^
$(patsubst %, %.o, $(AUXPROGS)): %.o: %.c $(AUXDEP)
$(NCC) $(EXTRADEFS) $(AUXDEFS) -MD -c -g -O $(WFLAGS) $(WARNOK_F) $(AUXINC) $<
endif
##
## Automatically maintain all dependencies so we don't need to
## worry about things like "make depend".
##
## Dependencies for each source file are kept in a corresponding
## ".d" file (which is generated as a side effect of compilation
## when the -MD flag is supplied).
##
## We only need to include ".d" files which correspond to existing
## ".o" files, as missing ".o" files will need to be regenerated
## anyway. Therefore we include in this makefile only the list of
## ".d" files in $(INCFILES), which is set to the list of all ".d"
## files with existing ".o" files.
##
## One small problem with this is that a ".d" file might get
## deleted while the ".o" still exists. Such missing ".d" files,
## listed in $(REQDFILES), are therefore manually regenerated.
##
DFILES := $(notdir $(SFILES:.S=.d) $(CFILES:.c=.d) $(AUXCSRCS:.c=.d))
INCDFILES := $(filter $(DFILES), $(patsubst %.o, %.d, $(wildcard *.o)))
REQDFILES := $(filter-out $(wildcard *.d), $(INCDFILES))
$(filter $(SFILES:.S=.d), $(REQDFILES)): %.d: %.S
$(CC) -M -c $(INC) $(EXTRADEFS) $(DEFS) $< > $@
$(filter $(CFILES:.c=.d), $(REQDFILES)): %.d: %.c
$(CC) -M -c $(INC) $(EXTRADEFS) $(DEFS) $< > $@
$(filter $(AUXCSRCS:.c=.d), $(REQDFILES)): %.d: %.c
$(NCC) -M -c $(EXTRADEFS) -DAUXUTIL $< > $@
ifneq ($(INCDFILES),)
include $(INCDFILES)
endif
##
## Clean and clobber
##
.PHONY: clean clobber
ifndef SUBDIRS
clean::
$(RM) -f $(AUXPROGS) $(sort $(PROG:.gdb=) $(PROG)) $(LIB) $(EXTRACLN) \
core *.s *.o *.a *.d *~ *.core *.aout
clobber: clean
endif
endif # no $(DOOBJDIR)
ifeq ($(PREORDER),yes)
ifneq ($(INOBJDIR),yes)
## Make subdirectories if $(SUBDIRS) is set
ifdef SUBDIRS
$(TARGETS)::
@set -e; for dir in $(SUBDIRS); do \
(cd $$dir && $(MAKE) $(filter-out all, $@) \
CURDIR=$(CURDIR)/$$dir); \
done
clean::
ifdef SRCFILES
$(RM) -f $(AUXPROGS) $(PROG) $(LIB) $(EXTRACLN) \
core *.s *.o *.a *.d *~ *.core *.aout
else # !SRCFILES
rm -f *~ *.core core *.aout
endif # !SRCFILES
endif # SUBDIRS
endif # INOBJDIR
endif # PREORDER
##
## Make docs
##