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
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 # List of directories that the */Makefrag makefile fragments will add to
139 ROS_ARCH_DIR ?= $(TARGET_ARCH)
142 @echo "TARGET_ARCH=$(TARGET_ARCH)"
145 ln -fs ../arch/$(ROS_ARCH_DIR) kern/include/arch
146 ln -fs arch/$(ROS_ARCH_DIR)/boot kern/boot
147 ln -fs $(ROS_ARCH_DIR) user/include/arch
148 @$(MAKE) -j $(MAKE_JOBS) all
150 # Include Makefrags for subdirectories
151 ifneq ($(TARGET_ARCH),)
152 include user/Makefrag
153 include tests/Makefrag
154 include kern/Makefrag
157 ifeq ($(GCCPREFIX),$(TARGET_ARCH)-ros-)
158 GCC_ROOT := $(shell which $(GCCPREFIX)gcc | xargs dirname)/../
161 @$(MAKE) -j $(MAKE_JOBS) realtests
162 realtests: $(TESTS_EXECS)
163 # No longer automatically copying to the FS dir (deprecated)
164 # @mkdir -p fs/$(TARGET_ARCH)/tests
165 # cp -R $(OBJDIR)/$(TESTS_DIR)/* $(TOP_DIR)/fs/$(TARGET_ARCH)/tests
167 install-libs: $(ROS_USER_LIBS)
168 cp $(ROS_USER_LIBS) $(GCC_ROOT)/$(TARGET_ARCH)-ros/lib
169 cp $(ROS_USER_LIBS) $(TOP_DIR)/fs/$(TARGET_ARCH)/lib
170 cp -R $(USER_DIR)/include/* $(GCC_ROOT)/$(TARGET_ARCH)-ros/include
174 # Eliminate default suffix rules
177 # Delete target files if there is an error (or make is interrupted)
180 # This magic automatically generates makefile dependencies
181 # for header files included from C source files we compile,
182 # and keeps those dependencies up-to-date every time we recompile.
183 # See 'mergedep.pl' for more information.
184 $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
186 @$(PERL) scripts/mergedep.pl $@ $^
188 # By including this file we automatically force the target that generates it
190 -include $(OBJDIR)/.deps
192 # Use doxygen to make documentation for ROS
194 @DOXYGEN_DIR=$(DOXYGEN_DIR) doxygen $(DOXYGEN_DIR)/rosdoc.cfg
195 @if [ ! -d $(DOXYGEN_DIR)/rosdoc/html/img ]; \
197 ln -s ../../img $(DOXYGEN_DIR)/rosdoc/html; \
201 rm -rf $(DOXYGEN_DIR)/rosdoc
203 # For deleting the build
205 @rm -rf $(OBJDIR)/user
209 @echo All clean and pretty!
213 @rm -f kern/include/arch
214 @rm -f user/include/arch
219 .PHONY: all always docs clean