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)" != "$@" ];\
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 # Then grab the users Makelocal file to let them override Make system variables
42 # and set up other Make targets
46 ARCH_DIR := $(TOP_DIR)/kern/arch
47 INCLUDE_DIR := $(TOP_DIR)/kern/include
48 DOXYGEN_DIR := $(TOP_DIR)/Documentation/doxygen
50 UNAME=$(shell uname -m)
52 # Cross-compiler ros toolchain
54 # This Makefile will automatically use the cross-compiler toolchain
55 # installed as '$(TARGET_ARCH)-ros-*', if one exists. If the host tools ('gcc',
56 # 'objdump', and so forth) compile for a 32-bit ELF target, that will
57 # be detected as well. If you have the right compiler toolchain installed
58 # using a different name, set GCCPREFIX explicitly in your Makelocal file
60 # Try to infer the correct GCCPREFIX
61 ifneq ($(TARGET_ARCH),)
63 TEST_PREFIX := $(TARGET_ARCH)-ros-
65 TEST_PREFIX := $(GCCPREFIX)
67 GCC_EXISTS = $(shell which $(TEST_PREFIX)gcc)
68 ifneq ($(GCC_EXISTS),)
69 GCCPREFIX := $(TEST_PREFIX)
71 ERROR := "*** Error: Couldn't find $(TEST_PREFIX) version of GCC/binutils."
82 # Default programs for compilation
83 ifeq ($(COMPILER),IVY)
84 KERN_CFLAGS := --deputy \
86 --sc-dynamic-is-error \
87 --sc-ops=$(INCLUDE_DIR)/ivy/sharc.h \
92 USER_CFLAGS := --deputy --enable-error-db
93 CC := ivycc --gcc=$(GCCPREFIX)gcc
101 OBJCOPY := $(GCCPREFIX)objcopy
102 OBJDUMP := $(GCCPREFIX)objdump
106 EXTRAARGS ?= -std=gnu99 -Wno-attributes -fno-stack-protector -fgnu89-inline
109 ifneq ($(GCC_EXISTS),)
110 GCC_LIB := $(shell $(CC) -print-libgcc-file-name)
113 # Universal compiler flags
114 # -fno-builtin is required to avoid refs to undefined functions in the kernel.
115 # Only optimize to -O1 to discourage inlining, which complicates backtraces.
116 CFLAGS := $(CFLAGS) -D$(TARGET_ARCH) $(EXTRAARGS)
117 CFLAGS += -O2 -pipe -MD -fno-builtin -gstabs
118 CFLAGS += -Wall -Wno-format -Wno-unused -fno-strict-aliasing
119 CFLAGS += -nostdinc -I$(dir $(GCC_LIB))/include
121 # Universal loader flags
124 # List of directories that the */Makefrag makefile fragments will add to
127 ROS_ARCH_DIR ?= $(TARGET_ARCH)
130 ln -fs ../arch/$(ROS_ARCH_DIR) kern/include/arch
131 ln -fs arch/$(ROS_ARCH_DIR)/boot kern/boot
134 # Include Makefrags for subdirectories
135 ifneq ($(TARGET_ARCH),)
136 include kern/Makefrag
137 include user/Makefrag
138 include tests/Makefrag
141 tests: $(TESTS_EXECS)
142 @mkdir -p fs/$(TARGET_ARCH)/tests
143 cp -R $(OBJDIR)/$(TESTS_DIR)/* fs/$(TARGET_ARCH)/tests
145 # Eliminate default suffix rules
148 # Delete target files if there is an error (or make is interrupted)
151 # This magic automatically generates makefile dependencies
152 # for header files included from C source files we compile,
153 # and keeps those dependencies up-to-date every time we recompile.
154 # See 'mergedep.pl' for more information.
155 $(OBJDIR)/.deps: $(foreach dir, $(OBJDIRS), $(wildcard $(OBJDIR)/$(dir)/*.d))
157 @$(PERL) scripts/mergedep.pl $@ $^
159 # By including this file we automatically force the target that generates it
161 -include $(OBJDIR)/.deps
163 # Use doxygen to make documentation for ROS
165 @DOXYGEN_DIR=$(DOXYGEN_DIR) doxygen $(DOXYGEN_DIR)/rosdoc.cfg
166 @if [ ! -d $(DOXYGEN_DIR)/rosdoc/html/img ]; \
168 ln -s ../../img $(DOXYGEN_DIR)/rosdoc/html; \
172 rm -rf $(DOXYGEN_DIR)/rosdoc
174 # For deleting the build
177 @echo All clean and pretty!
181 @rm -f kern/include/arch
186 .PHONY: all always docs clean