Annotation of prex/mk/Makefile.inc, Revision 1.3
1.1 nbrk 1: #
2: # Makefile.inc - common make rules to build Prex
3: #
4:
5: #
6: # Supported environment variables
7: #
8: # SRCDIR ... Root directory of source tree
9: # ARCH ... Architecture name
10: # PLATFORM ... Platform name
11: # NDEBUG ... 0 for debug, 1 for release (default: 0)
12: # LIBGCC_PATH ... Directory for libgcc.a
13: # CROSS_COMPILE ... Prefix of tools for cross compile
14: #
15: # Variables in local Makefile
16: #
17: # TARGET ... Target file name
18: # TYPE ... Traget type
19: # e.g. OBJECT,LIBRARY,KERNEL,BINARY,EXEC,DRIVER,OS_IMAGE
20: # SUBDIR ... List of subdirectories
21: # OBJS ... Object files
22: # OBJS-y ... Object files (for drivers)
23: # LIBS ... Libraries
24: # MAP ... Name of map file
25: # DISASM ... Disassemble list file
26: # SYMBOL ... Symbol files
27: #
28:
29: #
30: # Option for cross compile
31: #
32: #CROSS_COMPILE=
33: #CROSS_COMPILE= i386-elf-
34: #CROSS_COMPILE= arm-elf-
35: #CROSS_COMPILE= powerpc-eabi-
36: #CROSS_COMPILE= sh-elf-
37: #CROSS_COMPILE= mips-elf-
38:
39: #
40: # Tools
41: #
42: CC= $(CROSS_COMPILE)gcc
43: CPP= $(CROSS_COMPILE)cpp
44: AS= $(CROSS_COMPILE)as
45: LD= $(CROSS_COMPILE)ld
46: AR= $(CROSS_COMPILE)ar
47: OBJCOPY= $(CROSS_COMPILE)objcopy
48: OBJDUMP= $(CROSS_COMPILE)objdump
49: STRIP= $(CROSS_COMPILE)strip
50: LINT= splint
1.2 nbrk 51: MAKE= gmake
1.1 nbrk 52: #SHELL= /bin/sh
53: ifdef SHELL_PATH
54: SHELL= $(SHELL_PATH)
55: endif
56: ifdef DISASM
57: ASMGEN= $(OBJDUMP) $@ --disassemble-all > $(DISASM)
58: endif
59:
60: #
61: # System dependent options
62: #
63: include $(SRCDIR)/mk/own.mk
64:
65: #
66: # Flags
67: #
68: DEFS= -D__$(ARCH)__ -D__$(PLATFORM)__ \
69: -D__ARCH__=$(ARCH) -D__PLATFORM__=$(PLATFORM) \
70: -U$(ARCH) -U$(PLATFORM)
71:
72: CFLAGS+= -Os -ansi -pedantic -Wall -Wundef -fno-strict-aliasing \
73: -Wstrict-prototypes -Wpointer-arith \
74: $(CONFIG_CFLAGS) $(DEFS)
75:
76: ifeq ($(NDEBUG),1)
77: CFLAGS+= -fomit-frame-pointer
78: else
79: CFLAGS+= -fno-omit-frame-pointer -g
80: DEFS+= -DDEBUG
81: endif
82:
1.3 ! nbrk 83: CPPFLAGS+= $(DEFS)
1.1 nbrk 84: ASFLAGS+= $(DEFS) -D__ASSEMBLY__
85: ifdef MAP
86: LDFLAGS+= -Map $(MAP)
87: endif
88: LDFLAGS+=
89: MAKEFLAGS+= -rR --no-print-directory
90: LINTFLAGS+= -D__lint__ $(DEFS) -weak -nolib -retvalother -fcnuse
91:
92: #
93: # Specify path for libgcc.a
94: #
95: ifndef LIBGCC_PATH
96: LIBGCC_PATH := $(dir $(shell $(CC) $(GLOBAL_CFLAGS) -print-libgcc-file-name))
97: endif
98: LIBGCC = $(LIBGCC_PATH)libgcc.a
99:
100: #
101: # Inference rules
102: #
103: %.o: %.c
104: $(CC) $(CFLAGS) -c -o $@ $<
105:
106: %.o: %.s
107: $(AS) -o $@ $<
108:
109: %.o: %.S
1.3 ! nbrk 110: # $(CPP) $(ASFLAGS) $< $*.tmp
! 111: $(CC) $(ASFLAGS) -c -o $@ $<
! 112: # $(AS) -o $@ $*.tmp
! 113: # rm -f $*.tmp
1.1 nbrk 114:
115: #
116: # Target
117: #
118: all: $(SUBDIR) $(TARGET)
119:
120: #
121: # Check configuration
122: #
123: ifeq (0, ${MAKELEVEL})
124: # add dependency on config.h
125: $(SUBDIR):$(SRCDIR)/conf/config.h
126:
127: $(SRCDIR)/conf/config.h: dummy
128: @if [ ! -f $@ ]; then \
129: echo 'You must run `configure` before make.' ;\
130: exit 1 ;\
131: fi
132: endif
133:
134: #
135: # Rules to process sub-directory
136: #
137: ifdef SUBDIR
138: .PHONY: $(SUBDIR)
139: $(SUBDIR): dummy
140: $(MAKE) -C $@
141: endif
142:
143: #
144: # Rules to link a set of .o files into one .o file
145: #
146: ifeq ($(TYPE),OBJECT)
147: $(TARGET): $(OBJS) $(OBJS-y)
148: $(LD) $(LDFLAGS) -r -o $@ $^
149: endif
150:
151: #
152: # Rules to compile library
153: #
154: ifeq ($(TYPE),LIBRARY)
155: $(TARGET): $(OBJS) ar-target
156:
157: .PHONY: ar-target
158: ar-target: $(OBJS)
159: $(AR) rucs $(TARGET) $?
160: $(STRIP) -x -R .comment -R .note $(TARGET)
161: endif
162:
163: #
164: # Rules to compile kernel
165: #
166: ifeq ($(TYPE),KERNEL)
167: $(TARGET): $(OBJS) $(LIBS) $(LDS_SCRIPT)
168: $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS) $(LIBGCC)
169: $(ASMGEN)
170: ifdef SYMBOL
171: cp $@ $(SYMBOL)
172: endif
173: $(STRIP) -s $@
174: endif
175:
176: #
177: # Rules to compile device driver
178: #
179: ifeq ($(TYPE),DRIVER)
180: $(TARGET): $(OBJS) $(OBJS-y) $(LDS_SCRIPT)
181: $(LD) --error-unresolved-symbols $(LDFLAGS) -T $(LD_SCRIPT) -o $@.tmp $(OBJS) $(LIBS) $(LIBGCC)
182: rm -f $@.tmp
183: $(LD) -r $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS) $(LIBGCC)
184: $(ASMGEN)
185: ifdef SYMBOL
186: cp $@ $(SYMBOL)
187: endif
188: $(STRIP) --strip-debug --strip-unneeded $@
189: endif
190:
191: #
192: # Rules to compile binary file
193: #
194: ifeq ($(TYPE),BINARY)
195: $(TARGET): $(OBJS) $(LDS_SCRIPT)
196: $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS) $(LIBGCC)
197: $(ASMGEN)
198: ifdef SYMBOL
199: cp $@ $(SYMBOL)
200: endif
201: $(OBJCOPY) $(OBJCOPYFLAGS) $@
202: endif
203:
204: #
205: # Rules to compile executable file
206: #
207: ifeq ($(TYPE),EXEC)
208: $(TARGET): $(OBJS) $(LIBS) $(LDS_SCRIPT)
209: $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ \
210: $(CRT0) $(OBJS) $(LIBS) $(LIBC) $(LIBGCC)
211: $(ASMGEN)
212: ifdef SYMBOL
213: cp $@ $(SYMBOL)
214: endif
215: $(STRIP) --strip-debug --strip-unneeded $@
216: endif
217:
218: #
219: # Rules to create OS image
220: #
221: ifeq ($(TYPE),OS_IMAGE)
222: $(TARGET): dummy
223: ifdef BOOTFILES
224: $(AR) rcS ramdisk.a $(BOOTFILES)
225: $(AR) t ramdisk.a
226: $(AR) rcS tmp.a $(KERNEL) $(DRIVER) $(BOOTTASKS) ramdisk.a
227: rm ramdisk.a
228: else
229: $(AR) rcS tmp.a $(KERNEL) $(DRIVER) $(BOOTTASKS)
230: endif
231: $(AR) t tmp.a
232: cat $(LOADER) tmp.a > $@
233: rm tmp.a
234: endif
235:
236:
237: -include Makefile.dep
238:
239: ifndef SRCS
240: SRCS = $(OBJS:.o=.c)
241: endif
242:
243: #
244: # Depend
245: #
246: .PHONY: depend dep
247: depend dep:
248: ifdef SUBDIR
249: @(for d in $(SUBDIR) _ ; do \
250: if [ "$$d" != "_" ] ; then $(MAKE) -C $$d depend; fi; \
251: done);
252: endif
253: rm -f Makefile.dep
254: @(for d in $(SRCS) _ ; do \
255: if [ "$$d" != "_" ] ; then \
256: $(CPP) -M $(CPPFLAGS) $$d >> Makefile.dep; fi; \
257: done);
258: #
259: # Lint
260: #
261: .PHONY: lint
262: lint:
263: ifdef SUBDIR
264: @(for d in $(SUBDIR) _ ; do \
265: if [ "$$d" != "_" ] ; then $(MAKE) -C $$d lint; fi; \
266: done);
267: endif
268: @(for d in $(SRCS) _ ; do \
269: if [ "$$d" != "_" ] ; then \
270: echo ; \
271: echo "Checking $$d" ; \
272: $(LINT) $(LINTFLAGS) $(INCLUDE) $$d; fi; \
273: done);
274:
275: #
276: # Clean up
277: #
278: .PHONY: clean
279: clean:
280: ifdef SUBDIR
281: @(for d in $(SUBDIR) _ ; do \
282: if [ "$$d" != "_" ] ; then $(MAKE) -C $$d clean; fi; \
283: done);
284: endif
285: rm -f Makefile.dep $(TARGET) $(OBJS) $(OBJS-y) $(DISASM) $(MAP) $(SYMBOL) $(CLEANS)
286:
287: .PHONY: dummy
CVSweb