1 # The ROS Top level Makefile
2 # Make sure that 'all' is the first target
4 #############################################################################
5 ########## Initial Setup so that we can build for different TARGETS #########
6 #############################################################################
8 ARCH_LINK := $(shell readlink kern/include/arch)
10 ARCH_LINK := $(shell basename $(ARCH_LINK))
11 TARGET_ARCH ?= $(ARCH_LINK)
13 ifeq ($(TARGET_ARCH),)
15 @echo "You must initially specify your target in the form TARGET_ARCH=<target>"
16 @echo "Current valid values for TARGET_ARCH are 'i686' and 'sparc'"
17 @echo "Subsequent calls for the same target can be made by simply invoking 'make'"
21 @if [ "$(ARCH_LINK)" != "$@" ];\
24 $(MAKE) realall -j $(MAKE_JOBS);\
26 $(MAKE) all -j $(MAKE_JOBS);\
29 #############################################################################
30 ########## Beginning of the guts of the real Makefile #######################
31 #############################################################################
33 # Default values for configurable Make system variables
38 # Make sure that 'all' is the first target when not erroring out
41 # Number of make jobs to spawn. Define it in Makelocal
44 # Give it a reasonable default path for initramfs to avoid build breakage
45 INITRAMFS_PATHS = kern/kfs
47 # Then grab the users Makelocal file to let them override Make system variables
48 # and set up other Make targets
52 TOP_DIR := $(shell pwd)
53 ARCH_DIR := $(TOP_DIR)/kern/arch
54 INCLUDE_DIR := $(TOP_DIR)/kern/include
55 DOXYGEN_DIR := $(TOP_DIR)/Documentation/doxygen
57 UNAME=$(shell uname -m)
59 # Cross-compiler ros toolchain
61 # This Makefile will automatically use the cross-compiler toolchain
62 # installed as '$(TARGET_ARCH)-ros-*', if one exists. If the host tools ('gcc',
63 # 'objdump', and so forth) compile for a 32-bit ELF target, that will
64 # be detected as well. If you have the right compiler toolchain installed
65 # using a different name, set GCCPREFIX explicitly in your Makelocal file
67 # Try to infer the correct GCCPREFIX
68 ifneq ($(TARGET_ARCH),)
70 TEST_PREFIX := $(TARGET_ARCH)-ros-
72 TEST_PREFIX := $(GCCPREFIX)
74 GCC_EXISTS = $(shell which $(TEST_PREFIX)gcc)
75 ifneq ($(GCC_EXISTS),)
76 GCCPREFIX := $(TEST_PREFIX)
78 ERROR := "*** Error: Couldn't find $(TEST_PREFIX) version of GCC/binutils."
89 # Default programs for compilation
90 USER_CFLAGS += -O2 -std=gnu99
91 ifeq ($(COMPILER),IVY)
92 KERN_CFLAGS += --deputy \
94 --sc-dynamic-is-error \
95 --sc-ops=$(INCLUDE_DIR)/ivy/sharc.h \
100 USER_CFLAGS += --deputy --enable-error-db
101 CC := ivycc --gcc=$(GCCPREFIX)gcc
103 CC := $(GCCPREFIX)gcc
109 OBJCOPY := $(GCCPREFIX)objcopy
110 OBJDUMP := $(GCCPREFIX)objdump
112 STRIP := $(GCCPREFIX)strip
115 EXTRAARGS ?= -std=gnu99 -Wno-attributes -fno-stack-protector -fgnu89-inline
118 ifneq ($(GCC_EXISTS),)
119 GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
122 # Universal compiler flags
123 # -fno-builtin is required to avoid refs to undefined functions in the kernel.
124 # Only optimize to -O1 to discourage inlining, which complicates backtraces.
125 KERN_CFLAGS += -D$(TARGET_ARCH) $(EXTRAARGS)
126 KERN_CFLAGS += -O2 -pipe -MD -fno-builtin -gstabs
127 KERN_CFLAGS += -Wall -Wno-format -Wno-unused -fno-strict-aliasing
128 KERN_CFLAGS += -nostdinc -I$(dir $(GCC_LIB))/include
130 # Universal loader flags
133 # List of directories that the */Makefrag makefile fragments will add to
136 ROS_ARCH_DIR ?= $(TARGET_ARCH)
139 @echo "TARGET_ARCH=$(TARGET_ARCH)"
142 ln -fs ../arch/$(ROS_ARCH_DIR) kern/include/arch
143 ln -fs arch/$(ROS_ARCH_DIR)/boot kern/boot
144 ln -fs $(ROS_ARCH_DIR) user/include/arch
145 @$(MAKE) -j $(MAKE_JOBS) all
147 # Include Makefrags for subdirectories
148 ifneq ($(TARGET_ARCH),)
149 include tests/Makefrag
150 include kern/Makefrag
153 ifeq ($(GCCPREFIX),$(TARGET_ARCH)-ros-)
154 GCC_ROOT := $(shell which $(GCCPREFIX)gcc | xargs dirname)/../
157 @$(MAKE) -j $(MAKE_JOBS) realtests
158 realtests: $(TESTS_EXECS)
159 # No longer automatically copying to the FS dir (deprecated)
160 # @mkdir -p fs/$(TARGET_ARCH)/tests
161 # cp -R $(OBJDIR)/$(TESTS_DIR)/* $(TOP_DIR)/fs/$(TARGET_ARCH)/tests
164 @cd user/parlib; $(MAKE); $(MAKE) install
165 @cd user/pthread; $(MAKE); $(MAKE) install
166 @cd user/c3po; $(MAKE); $(MAKE) install
169 @cd user/parlib; $(MAKE) clean;
170 @cd user/pthread; $(MAKE) clean;
171 @cd user/c3po; $(MAKE) clean;
172 @rm -rf $(OBJDIR)/$(TESTS_DIR)
176 # Eliminate default suffix rules
179 # Delete target files if there is an error (or make is interrupted)
182 # This magic automatically generates makefile dependencies
183 # for header files included from C source files we compile,
184 # and keeps those dependencies up-to-date every time we recompile.
185 # See 'mergedep.pl' for more information.
186 $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
188 @$(PERL) scripts/mergedep.pl $@ $^
190 # By including this file we automatically force the target that generates it
192 -include $(OBJDIR)/.deps
194 # Use doxygen to make documentation for ROS
196 @DOXYGEN_DIR=$(DOXYGEN_DIR) doxygen $(DOXYGEN_DIR)/rosdoc.cfg
197 @if [ ! -d $(DOXYGEN_DIR)/rosdoc/html/img ]; \
199 ln -s ../../img $(DOXYGEN_DIR)/rosdoc/html; \
203 rm -rf $(DOXYGEN_DIR)/rosdoc
207 @echo All clean and pretty!
211 @rm -f kern/include/arch
212 @rm -f user/include/arch
217 .PHONY: all always docs clean