2 # This makefile system follows the structuring conventions
3 # recommended by Peter Miller in his excellent paper:
5 # Recursive Make Considered Harmful
6 # http://aegis.sourceforge.net/auug97.pdf
11 INCLUDE_DIR := $(TOP_DIR)/include
12 UNAME=$(shell uname -m)
15 # Cross-compiler ros toolchain
17 # This Makefile will automatically use the cross-compiler toolchain
18 # installed as 'i386-ros-elf-*', if one exists. If the host tools ('gcc',
19 # 'objdump', and so forth) compile for a 32-bit x86 ELF target, that will
20 # be detected as well. If you have the right compiler toolchain installed
21 # using a different name, set GCCPREFIX explicitly in conf/env.mk
23 # try to infer the correct GCCPREFIX
25 GCCPREFIX := $(shell if i386-ros-elf-objdump -i 2>&1 | grep '^elf32-i386$$' >/dev/null 2>&1; \
26 then echo 'i386-ros-elf-'; \
27 elif objdump -i 2>&1 | grep 'elf32-i386' >/dev/null 2>&1; \
29 else echo "***" 1>&2; \
30 echo "*** Error: Couldn't find an i386-*-elf version of GCC/binutils." 1>&2; \
31 echo "*** Is the directory with i386-ros-elf-gcc in your PATH?" 1>&2; \
32 echo "*** If your i386-*-elf toolchain is installed with a command" 1>&2; \
33 echo "*** prefix other than 'i386-ros-elf-', set your GCCPREFIX" 1>&2; \
34 echo "*** environment variable to that prefix and run 'make' again." 1>&2; \
35 echo "*** To turn off this error, run 'gmake GCCPREFIX= ...'." 1>&2; \
36 echo "***" 1>&2; exit 1; fi)
39 # Default programs for compilation
40 CC := $(GCCPREFIX)ivycc --deputy
44 OBJCOPY := $(GCCPREFIX)objcopy
45 OBJDUMP := $(GCCPREFIX)objdump
49 # User defined constants passed on the command line
52 # Universal compiler flags
53 # -fno-builtin is required to avoid refs to undefined functions in the kernel.
54 # Only optimize to -O1 to discourage inlining, which complicates backtraces.
55 CFLAGS := $(CFLAGS) -D$(ARCH)
56 CFLAGS += -O -pipe -MD -fno-builtin -fno-stack-protector -gstabs
57 CFLAGS += -Wall -Wno-format -Wno-unused
59 # Universal loader flags
63 GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
65 # 64 Bit specific flags / definitions
66 ifeq ($(UNAME),x86_64)
69 GCC_LIB = $(shell $(CC) -print-libgcc-file-name | sed 's/libgcc.a/32\/libgcc.a/')
72 # List of directories that the */Makefrag makefile fragments will add to
75 # Make sure that 'all' is the first target
78 # Include Makefrags for subdirectories
83 # Eliminate default suffix rules
86 # Delete target files if there is an error (or make is interrupted)
89 # This magic automatically generates makefile dependencies
90 # for header files included from C source files we compile,
91 # and keeps those dependencies up-to-date every time we recompile.
92 # See 'mergedep.pl' for more information.
93 $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
95 @$(PERL) scripts/mergedep.pl $@ $^
97 -include $(OBJDIR)/.deps
99 # For deleting the build
106 .PHONY: all always clean