Annotation of prex-old/mk/Makefile.inc, Revision 1.4
1.1 nbrk 1: #
2: # Makefile.inc - common make rules to build Prex
3: #
4:
5: # Supported environment variables
6: #
7: # SRCDIR ... Root directory of source tree
8: # ARCH ... Architecture name
9: # PLATFORM ... Platform name
10: # NDEBUG ... 0 for debug, 1 for release (default: 0)
11: # LIBGCC_PATH ... Full path for libgcc.a
12: # CROSS_COMPILE ... Prefix of tools for cross compile
13: #
14: # Variables in local Makefile
15: #
16: # TARGET ... Target file name
17: # TYPE ... Traget type
18: # e.g. OBJECT,LIBRARY,KERNEL,BINARY,EXEC,DRIVER,OS_IMAGE
19: # SUBDIR ... List of subdirectories
20: # OBJS ... Object files
21: # OBJS-y ... Object files (for drivers)
22: # LIBS ... Libraries
23: # MAP ... Name of map file
24: # DISASM ... Disassemble list file
25: # SYMBOL ... Symbol files
26: #
27:
28: #
29: # Option for cross compile
30: #
31: #CROSS_COMPILE=
32: #CROSS_COMPILE= i386-elf-
33: #CROSS_COMPILE= arm-elf-
34: #CROSS_COMPILE= powerpc-eabi-
35: #CROSS_COMPILE= sh-elf-
36: #CROSS_COMPILE= mips-elf-
1.4 ! nbrk 37: #CROSS_COMPILE= avr32-
1.1 nbrk 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.3 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 -fno-strict-aliasing \
73: -Wall -Wundef -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 -DDEBUG -g
80: endif
81:
82: CPPFLAGS+= $(DEFS)
83: ASFLAGS+= $(DEFS) -D__ASSEMBLY__
84: ifdef MAP
85: LDFLAGS+= -Map $(MAP)
86: endif
87: LDFLAGS+=
88: MAKEFLAGS+= -rR --no-print-directory
89: LINTFLAGS+= -D__lint__ $(DEFS) -nolib -weak -fcnuse -nestcomment \
90: -retvalother -fullinitblock
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
110: $(CPP) $(ASFLAGS) $< $*.tmp
111: $(AS) -o $@ $*.tmp
112: rm -f $*.tmp
113:
114: #
115: # Target
116: #
117: all: $(SUBDIR) $(TARGET)
118:
119: #
120: # Check configuration
121: #
122: ifeq (0, ${MAKELEVEL})
123: # add dependency on config.h
124: $(SUBDIR):$(SRCDIR)/conf/config.h
125:
126: $(SRCDIR)/conf/config.h: dummy
127: @if [ ! -f $@ ]; then \
128: echo 'You must run `configure` before make.' ;\
129: exit 1 ;\
130: fi
131: endif
132:
133: #
134: # Rules to process sub-directory
135: #
136: ifdef SUBDIR
137: .PHONY: $(SUBDIR)
138: $(SUBDIR): dummy
139: $(MAKE) -C $@
140: endif
141:
142: #
143: # Rules to link a set of .o files into one .o file
144: #
145: ifeq ($(TYPE),OBJECT)
146: $(TARGET): $(OBJS) $(OBJS-y)
147: $(LD) $(LDFLAGS) -r -o $@ $^
148: endif
149:
150: #
151: # Rules to compile library
152: #
153: ifeq ($(TYPE),LIBRARY)
154: $(TARGET): $(OBJS) ar-target
155:
156: .PHONY: ar-target
157: ar-target: $(OBJS)
158: $(AR) rucs $(TARGET) $?
159: $(STRIP) -x -R .comment -R .note $(TARGET)
160: endif
161:
162: #
163: # Rules to compile kernel
164: #
165: ifeq ($(TYPE),KERNEL)
166: $(TARGET): $(OBJS) $(LIBS) $(LDS_SCRIPT)
167: $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS) $(LIBGCC)
168: $(ASMGEN)
169: ifdef SYMBOL
170: cp $@ $(SYMBOL)
171: endif
172: $(STRIP) -s $@
173: endif
174:
175: #
176: # Rules to compile device driver
177: #
178: ifeq ($(TYPE),DRIVER)
179: $(TARGET): $(OBJS) $(OBJS-y) $(LDS_SCRIPT)
180: $(LD) --error-unresolved-symbols $(LDFLAGS) -T $(LD_SCRIPT) -o $@.tmp $(OBJS) $(LIBS) $(LIBGCC)
181: rm -f $@.tmp
182: $(LD) -r $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS) $(LIBGCC)
183: $(ASMGEN)
184: ifdef SYMBOL
185: cp $@ $(SYMBOL)
186: endif
187: $(STRIP) --strip-debug --strip-unneeded $@
188: endif
189:
190: #
191: # Rules to compile binary file
192: #
193: ifeq ($(TYPE),BINARY)
194: $(TARGET): $(OBJS) $(LDS_SCRIPT)
195: $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS) $(LIBGCC)
196: $(ASMGEN)
197: ifdef SYMBOL
198: cp $@ $(SYMBOL)
199: endif
200: $(OBJCOPY) $(OBJCOPYFLAGS) $@
201: endif
202:
203: #
204: # Rules to compile executable file
205: #
206: ifeq ($(TYPE),EXEC)
207: $(TARGET): $(OBJS) $(LIBS) $(LDS_SCRIPT)
208: $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ \
209: $(CRT0) $(OBJS) $(LIBS) $(LIBC) $(LIBGCC)
210: $(ASMGEN)
211: ifdef SYMBOL
212: cp $@ $(SYMBOL)
213: endif
214: $(STRIP) --strip-debug --strip-unneeded $@
215: endif
216:
217: #
218: # Rules to create OS image
219: #
220: ifeq ($(TYPE),OS_IMAGE)
221: $(TARGET): dummy
222: ifdef BOOTFILES
223: $(AR) rcS ramdisk.a $(BOOTFILES)
224: $(AR) t ramdisk.a
225: $(AR) rcS tmp.a $(KERNEL) $(DRIVER) $(BOOTTASKS) ramdisk.a
226: rm ramdisk.a
227: else
228: $(AR) rcS tmp.a $(KERNEL) $(DRIVER) $(BOOTTASKS)
229: endif
230: $(AR) t tmp.a
231: cat $(LOADER) tmp.a > $@
232: rm tmp.a
233: endif
234:
235:
236: -include Makefile.dep
237:
238: C_SRCS = $(wildcard *.c) $(wildcard *.S)
239:
240: #
241: # Depend
242: #
243: .PHONY: depend dep
244: depend dep:
245: ifdef SUBDIR
246: @(for d in $(SUBDIR) _ ; do \
247: if [ "$$d" != "_" ] ; then $(MAKE) -C $$d depend; fi; \
248: done);
249: endif
250: rm -f Makefile.dep
251: @(for d in $(C_SRCS) _ ; do \
252: if [ "$$d" != "_" ] ; then \
253: $(CPP) -M $(CPPFLAGS) $$d >> Makefile.dep; fi; \
254: done);
255: #
256: # Lint
257: #
258: .PHONY: lint
259: lint:
260: @(for d in $(C_SRCS) _ ; do \
261: if [ "$$d" != "_" ] ; then \
262: $(LINT) $(LINTFLAGS) $(INCLUDE) $$d; fi; \
263: done);
264:
265: #
266: # Clean up
267: #
268: .PHONY: clean
269: clean:
270: ifdef SUBDIR
271: @(for d in $(SUBDIR) _ ; do \
272: if [ "$$d" != "_" ] ; then $(MAKE) -C $$d clean; fi; \
273: done);
274: endif
275: rm -f Makefile.dep $(TARGET) $(OBJS) $(OBJS-y) $(DISASM) $(MAP) $(SYMBOL) $(CLEANS)
276:
277: .PHONY: dummy
CVSweb