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 # Then grab the users Makelocal file to let them override Make system variables
45 # and set up other Make targets
50 ARCH_DIR := $(TOP_DIR)/kern/arch
51 INCLUDE_DIR := $(TOP_DIR)/kern/include
52 DOXYGEN_DIR := $(TOP_DIR)/Documentation/doxygen
54 UNAME=$(shell uname -m)
56 # Cross-compiler ros toolchain
58 # This Makefile will automatically use the cross-compiler toolchain
59 # installed as '$(TARGET_ARCH)-ros-*', if one exists. If the host tools ('gcc',
60 # 'objdump', and so forth) compile for a 32-bit ELF target, that will
61 # be detected as well. If you have the right compiler toolchain installed
62 # using a different name, set GCCPREFIX explicitly in your Makelocal file
64 # Try to infer the correct GCCPREFIX
65 ifneq ($(TARGET_ARCH),)
67 TEST_PREFIX := $(TARGET_ARCH)-ros-
69 TEST_PREFIX := $(GCCPREFIX)
71 GCC_EXISTS = $(shell which $(TEST_PREFIX)gcc)
72 ifneq ($(GCC_EXISTS),)
73 GCCPREFIX := $(TEST_PREFIX)
75 ERROR := "*** Error: Couldn't find $(TEST_PREFIX) version of GCC/binutils."
86 # Default programs for compilation
87 ifeq ($(COMPILER),IVY)
88 KERN_CFLAGS += --deputy \
90 --sc-dynamic-is-error \
91 --sc-ops=$(INCLUDE_DIR)/ivy/sharc.h \
96 USER_CFLAGS += --deputy --enable-error-db
97 CC := ivycc --gcc=$(GCCPREFIX)gcc
105 OBJCOPY := $(GCCPREFIX)objcopy
106 OBJDUMP := $(GCCPREFIX)objdump
110 EXTRAARGS ?= -std=gnu99 -Wno-attributes -fno-stack-protector -fgnu89-inline
113 ifneq ($(GCC_EXISTS),)
114 GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
117 # Universal compiler flags
118 # -fno-builtin is required to avoid refs to undefined functions in the kernel.
119 # Only optimize to -O1 to discourage inlining, which complicates backtraces.
120 KERN_CFLAGS += -D$(TARGET_ARCH) $(EXTRAARGS)
121 KERN_CFLAGS += -O2 -pipe -MD -fno-builtin -gstabs
122 KERN_CFLAGS += -Wall -Wno-format -Wno-unused -fno-strict-aliasing
123 KERN_CFLAGS += -nostdinc -I$(dir $(GCC_LIB))/include
125 # Universal loader flags
128 # List of directories that the */Makefrag makefile fragments will add to
131 # List of directories that the */Makefrag makefile fragments will add to
134 ROS_ARCH_DIR ?= $(TARGET_ARCH)
137 @echo "TARGET_ARCH=$(TARGET_ARCH)"
140 ln -fs ../arch/$(ROS_ARCH_DIR) kern/include/arch
141 ln -fs arch/$(ROS_ARCH_DIR)/boot kern/boot
142 ln -fs $(ROS_ARCH_DIR) user/include/arch
143 @$(MAKE) -j $(MAKE_JOBS) all
145 # Include Makefrags for subdirectories
146 ifneq ($(TARGET_ARCH),)
147 include user/Makefrag
148 include tests/Makefrag
149 include kern/Makefrag
152 ifeq ($(GCCPREFIX),$(TARGET_ARCH)-ros-)
153 GCC_ROOT := $(shell which $(GCCPREFIX)gcc | xargs dirname)/../
156 @$(MAKE) -j $(MAKE_JOBS) realtests
157 realtests: $(TESTS_EXECS)
158 @mkdir -p fs/$(TARGET_ARCH)/tests
159 cp -R $(OBJDIR)/$(TESTS_DIR)/* $(TOP_DIR)/fs/$(TARGET_ARCH)/tests
161 install-libs: $(ROS_USER_LIBS)
162 cp $(ROS_USER_LIBS) $(GCC_ROOT)/$(TARGET_ARCH)-ros/lib
163 cp $(ROS_USER_LIBS) $(TOP_DIR)/fs/$(TARGET_ARCH)/lib
164 cp -R $(USER_DIR)/include/* $(GCC_ROOT)/$(TARGET_ARCH)-ros/include
168 # Eliminate default suffix rules
171 # Delete target files if there is an error (or make is interrupted)
174 # This magic automatically generates makefile dependencies
175 # for header files included from C source files we compile,
176 # and keeps those dependencies up-to-date every time we recompile.
177 # See 'mergedep.pl' for more information.
178 $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
180 @$(PERL) scripts/mergedep.pl $@ $^
182 # By including this file we automatically force the target that generates it
184 -include $(OBJDIR)/.deps
186 # Use doxygen to make documentation for ROS
188 @DOXYGEN_DIR=$(DOXYGEN_DIR) doxygen $(DOXYGEN_DIR)/rosdoc.cfg
189 @if [ ! -d $(DOXYGEN_DIR)/rosdoc/html/img ]; \
191 ln -s ../../img $(DOXYGEN_DIR)/rosdoc/html; \
195 rm -rf $(DOXYGEN_DIR)/rosdoc
197 # For deleting the build
199 @rm -rf $(OBJDIR)/user
203 @echo All clean and pretty!
207 @rm -f kern/include/arch
208 @rm -f user/include/arch
213 .PHONY: all always docs clean