2 # Makefile.inc - common make rules to build Prex
5 # Required environment variables
7 # PREX_SRC ... Root directory of source tree
8 # PREX_ARCH ... Architecture name
9 # PREX_PLATFORM ... Platform name
11 # Optional environment variables
13 # NDEBUG ... 0 for debug, 1 for release (default: 0)
14 # KTRACE ... 1 for the kernel function trace (default: 0)
15 # LIBGCC_PATH ... Full path for libgcc.a
16 # CROSS_COMPILE ... Prefix of tools for cross compile
18 # Variables in local Makefile
20 # TARGET ... Target file name
21 # TYPE ... Traget type
22 # e.g. OBJECT,LIBRARY,KERNEL,BINARY,EXEC,DRIVER,OS_IMAGE
23 # SUBDIRS ... List of subdirectories
24 # OBJS ... Object files (not for drivers)
25 # OBJS-y ... Object files
26 # OBJS-m ... Object files for modular driver (only for drivers)
27 # OBJS- ... Disabled Object files
28 # OBJS-$(CONFIG_FOO) ... Object enabled / disabled by conf/config.ARCH-PLATFORM
30 # MAP ... Name of map file
31 # DISASM ... Disassemble list file
32 # SYMBOL ... Symbol files
35 # Variables in conf/boot.conf (override in conf/config.ARCH-PLATFORM)
37 # DRIVER ... path to driver modules or undefined for no modules
38 # TASKS ... tasks included in kernel image
39 # RDFILES ... Files in RAM disk
41 # Variables in conf/config.ARCH-PLATFORM
43 # CONFIG_FOO=y ... enable feature FOO / build driver FOO into kernel
44 # CONFIG_FOO=m ... build driver FOO as a module
45 # CONFIG_FOO=* ... set config parameter FOO to *
48 # Option for cross compile
51 #CROSS_COMPILE = i386-elf-
52 #CROSS_COMPILE = arm-elf-
53 #CROSS_COMPILE = powerpc-eabi-
54 #CROSS_COMPILE = sh-elf-
55 #CROSS_COMPILE = mips-elf-
60 CC = $(CROSS_COMPILE)gcc
61 CPP = $(CROSS_COMPILE)cpp
62 AS = $(CROSS_COMPILE)as
63 LD = $(CROSS_COMPILE)ld
64 AR = $(CROSS_COMPILE)ar
65 OBJCOPY = $(CROSS_COMPILE)objcopy
66 OBJDUMP = $(CROSS_COMPILE)objdump
67 STRIP = $(CROSS_COMPILE)strip
76 ASMGEN = $(OBJDUMP) $@ --disassemble-all > $(DISASM)
80 # System dependent options
82 include $(PREX_SRC)/mk/own.mk
87 DEF_FLAGS = -D__$(PREX_ARCH)__ -D__$(PREX_PLATFORM)__ \
88 -D__ARCH__=$(PREX_ARCH) -D__PLATFORM__=$(PREX_PLATFORM) \
89 -U$(PREX_ARCH) -U$(PREX_PLATFORM)
92 CFLAGS += -fomit-frame-pointer
97 # Correct gcc behavior for some distributions.
98 SSP_FLAG ?= $(shell if $(CC) -fno-stack-protector -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "-fno-stack-protector"; fi)
100 CFLAGS += $(SSP_FLAG)
103 LDFLAGS += -Map $(MAP)
107 CFLAGS += -Wsign-compare
108 CFLAGS += -Werror-implicit-function-declaration
109 CFLAGS += -Wall -O2 -fno-strict-aliasing $(DEF_FLAGS)
110 CPPFLAGS += $(DEF_FLAGS)
112 #MAKEFLAGS += --no-print-directory
114 LINT_FLAGS = -D__lint__ $(DEF_FLAGS) -nolib -weak -fcnuse -nestcomment \
115 -retvalother -fullinitblock
118 # Specify path for libgcc.a
121 LIBGCC_PATH := $(dir $(shell $(CC) $(GLOBAL_CFLAGS) -print-libgcc-file-name))
128 $(CC) $(CFLAGS) $(CFLAGS_$@) $(EXTRA_CFLAGS) -c -o $@ $<
131 $(AS) $(ASFLAGS) $(ASFLAGS_$@) $(EXTRA_ASFLAGS) -o $@ $<
134 $(CPP) $(CPPFLAGS) $(CPPFLAGS_$@) $(EXTRA_CPPFLAGS) $< $*.tmp
135 $(AS) $(ASFLAGS) $(ASFLAGS_$@) $(EXTRA_ASFLAGS) -o $@ $*.tmp
141 all: $(SUBDIRS) $(TARGET)
144 # Check configuration
146 ifeq (0, ${MAKELEVEL})
147 # add dependency on config.h
148 $(SUBDIRS):$(PREX_SRC)/conf/config.h
150 $(PREX_SRC)/conf/config.h: dummy
151 @if [ ! -f $@ ]; then \
152 echo 'You must run `configure` before make.' ;\
158 # Rules to process sub-directory
162 $(MAKE) -C $@ $(MAKECMDGOALS)
165 # Rules to link a set of .o files into one .o file
167 ifeq ($(TYPE),OBJECT)
168 ifeq (,$(findstring __DRIVER__,$(CFLAGS)))
172 # OBJS unconditionally linked objects
173 # OBJS-y conditionally linked based on a CONFIG_* variable
174 # OBJS- disabled objects - associated CONFIG_* variable undefined
176 $(TARGET): $(OBJS) $(OBJS-y)
177 $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $^ $(LIBS)
179 ifneq (,$(strip $(OBJS-m)))
180 $(error $(OBJS-m) must not be OBJ-m, this is only for drivers)
187 # OBJS-y link objects for static drivers (typically set via CONFIG_*)
188 # OBJS-m link objects for modular drivers
189 # OBJS- disabled objects
190 # OBJS is no longer used for drivers
191 ifneq (,$(strip $(OBJS)))
192 $(error $(OBJS) must not be OBJS, this is _not_ for drivers)
195 # additional target for modular drivers
196 all: $(TARGET:.o=.mo)
198 # static driver objects
199 ifneq (,$(strip $(OBJS-y)))
201 $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $^
202 else # ensure an object file always exists
204 $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $@
207 # modular driver objects
208 ifneq (,$(strip $(OBJS-m)))
209 $(TARGET:.o=.mo): $(OBJS-m)
210 $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $^
212 $(TARGET:.o=.mo): dummy
213 $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $@
216 endif # driver objects
220 # Rules to compile library
222 ifeq ($(TYPE),LIBRARY)
223 $(TARGET): $(OBJS) ar-target
227 $(AR) $(EXTRA_ARFLAGS) rucs $(TARGET) $?
231 # Rules to compile kernel
233 ifeq ($(TYPE),KERNEL)
234 $(TARGET): $(OBJS) $(LIBS) $(LD_SCRIPT)
235 $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS) $(LIBS)
244 # Rules to compile device driver
246 ifeq ($(TYPE),DRIVER)
247 # additional target for modular drivers
248 all: $(TARGET:.o=.ko)
250 $(TARGET:.o=.ko): $(OBJS:.o=.mo) $(LD_SCRIPT)
251 $(LD) $(LDFLAGS) -T $(LD_SCRIPT) -o $@ $(OBJS:.o=.mo) $(LIBS)
256 $(STRIP) --strip-debug --strip-unneeded $@
258 # staticly linked drivers
260 $(LD) $(LDFLAGS) $(EXTRA_LDFLAGS) -r -o $@ $^
264 # Rules to compile binary file
266 ifeq ($(TYPE),BINARY)
267 $(TARGET): $(OBJS) $(LD_SCRIPT)
268 $(LD) $(LDFLAGS) -T $(LD_SCRIPT) $(EXTRA_LDFLAGS) -o $@ $(OBJS) $(LIBS)
273 $(OBJCOPY) $(OBJCOPYFLAGS) $@
277 # Rules to compile executable file
280 $(TARGET): $(OBJS) $(LIBS) $(LD_SCRIPT)
281 $(LD) $(LDFLAGS) -T $(LD_SCRIPT) $(EXTRA_LDFLAGS) -o $@ \
282 $(CRT0) $(OBJS) $(LIBS) $(LIBC) $(LIBGCC_PATH)libgcc.a
287 $(STRIP) --strip-debug --strip-unneeded $@
291 # Rules to create OS image
293 ifeq ($(TYPE),OS_IMAGE)
296 $(AR) rcS ramdisk.a $(RDFILES)
298 $(AR) rcS tmp.a $(KERNEL) $(DRIVER) $(TASKS) ramdisk.a
301 $(AR) rcS tmp.a $(KERNEL) $(DRIVER) $(TASKS)
304 cat $(LOADER) tmp.a > $@
309 -include Makefile.dep
311 C_SRCS = $(wildcard *.c) $(wildcard *.S)
317 depend dep: $(SUBDIRS)
318 $(RM) -f Makefile.dep
319 @(for d in $(C_SRCS) _ ; do \
320 if [ "$$d" != "_" ] ; then \
321 $(CPP) -M $(CPPFLAGS) $$d >> Makefile.dep; fi; \
328 @(for d in $(C_SRCS) _ ; do \
329 if [ "$$d" != "_" ] ; then \
330 $(LINT) $(LINT_FLAGS) $(INC_FLAGS) $$d; fi; \
338 $(RM) -f Makefile.dep $(TARGET) $(DISASM) $(MAP) $(SYMBOL) $(CLEANS)
339 ifneq (,$(strip $(OBJS) $(OBJS-y) $(OBJS-m) $(OBJS-)))
340 $(RM) -f $(sort $(OBJS) $(OBJS-y) $(OBJS-m) $(OBJS-))
342 ifeq ($(TYPE),DRIVER)
343 ifneq (,$(strip $(TARGET:.o=.ko) $(OBJS:.o=.mo)))
344 $(RM) -f $(sort $(TARGET:.o=.ko) $(OBJS:.o=.mo))
347 ifeq ($(TYPE),OBJECT)
348 ifneq (,$(findstring __DRIVER__,$(CFLAGS)))
349 $(RM) -f $(TARGET:.o=.mo)