1 # Makefile for XTOS in <xtensa_tools_root>/xtensa-elf/src/xtos
3 # Copyright (c) 2000-2010 Tensilica Inc.
5 # Permission is hereby granted, free of charge, to any person obtaining
6 # a copy of this software and associated documentation files (the
7 # "Software"), to deal in the Software without restriction, including
8 # without limitation the rights to use, copy, modify, merge, publish,
9 # distribute, sublicense, and/or sell copies of the Software, and to
10 # permit persons to whom the Software is furnished to do so, subject to
11 # the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17 # EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
19 # IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
20 # CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
21 # TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
22 # SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
25 # This makefile assumes GNU make features
27 # Invoke this Makefile like this:
28 # cd <some build directory>
29 # make -f <this file> \
30 # MAKEFILE_SRC=<this file> \
31 # XTENSA_TOOLS_ROOT=<path to Xtensa Tools> \
32 # XTENSA_ROOT=<path to Xtensa core package> \
33 # INSTLIBDIR=<path to installation directory>
36 ifndef XTENSA_TOOLS_ROOT
37 $(error Please set XTENSA_TOOLS_ROOT to the path to Xtensa Tools)
39 # NOTE: For now, we assume $(XTENSA_TOOLS_ROOT)/bin is on the PATH.
41 $(error Please set XTENSA_ROOT to the path to your specific Xtensa core package)
44 $(error Please set INSTLIBDIR to the path where libraries and objects are installed)
45 #INSTLIBDIR = $(call fixpath,$(XTENSA_ROOT)/xtensa-elf/arch/lib)
48 # Select the specified Xtensa configuration:
49 export XTENSA_SYSTEM = $(XTENSA_ROOT)/config
50 export XTENSA_CORE = default
52 include $(XTENSA_TOOLS_ROOT)/misc/defs.mk
53 include $(XTENSA_ROOT)/misc/build.mk
56 $(error Please set MAKEFILE_SRC to the path to the XTOS Makefile.src)
59 # Native commands like $(MKPATH) and $(CP) need native directory separators:
60 #fixpath = $(subst /,$S,$(1))
62 XTCC = $(CC_FOR_TARGET)
65 .PHONY: all install clean
68 ASFLAGS = -O2 -g -mlongcalls
69 CFLAGS = -O2 -g -mlongcalls
72 # Compile "split" files in separate parts that can be linked independently.
73 # This allows keeping multiple related functions/etc together in one file
74 # without forcing linking of unused functions (the GNU linker takes entire
75 # object files; it does not currently provide automated dead code removal).
76 # Files are split with "#[el]if defined(__SPLIT__<tag>)" lines using normal
77 # C preprocessor syntax, where each <tag> must be unique and consist of
78 # lowercase alphanumeric and underscore characters only (no dash etc).
79 # The makefile function $(split_objs ...) returns the set of objects that
80 # result for a given list of splittable source files; each ends in a -.o
81 # suffix recognized by special rules further below.
83 split_objs = $(shell cd $(SRCDIR) && $(PERL) -ne '/__SPLIT__(\w+)/ and $$h{$$ARGV."--".$$1}++;\
84 END {foreach (sort keys %h) {s/\.(.)--/-$$1--/; print "$$_-.o\n";}}' $(1))
86 # Vectors, handlers, and other code to build:
87 PERLEVEL_INTVECTOR_OBJS = $(foreach N,2 3 4 5 6,int-vector-level$(N).o)
88 PERLEVEL_INTHANDLER_OBJS = $(foreach N,2 3 4 5 6,int-handler-level$(N).o)
89 PERLEVEL_INTINITLEV_OBJS = $(foreach N,1 2 3 4 5 6,int-init-level$(N).o)
91 reset-vector-unpack.o \
92 shared-reset-vector.o \
97 $(call split_objs, memerror-vector.S) \
98 $(PERLEVEL_INTVECTOR_OBJS) \
99 exc-alloca-handler.o \
102 exc-syscall-handler.o \
103 exc-syscall-c-handler.o \
107 int-lowpri-dispatcher.o \
115 $(call split_objs, deprecated.S tiny-refs.S) \
116 $(PERLEVEL_INTHANDLER_OBJS) \
117 $(PERLEVEL_INTINITLEV_OBJS)
118 # These objects have simulator and board variants:
119 XTOS_SIMBOARD_OBJS = \
125 exc-c-wrapper-handler.o \
128 XTOS_BOARD_OBJS = $(XTOS_SIMBOARD_OBJS)
129 XTOS_SIM_OBJS = $(XTOS_SIMBOARD_OBJS:.o=-sim.o)
131 # Optimize a few things for size rather than speed:
132 #FLAGS_exc-syscall-handler = -Os --no-target-align
137 _sharedvectors-for-reset.o \
143 libhandlers-board.a \
148 libhandler-reset-unpack.a \
150 ifdef TENSILICA_INTERNAL
151 TARGETS += libhandler-reset-mp.a
157 # Here's an example of how one could put a selected set of
158 # objects into a specific section:
161 # -mrename-section-.text=.xtos.text \
162 # -mrename-section-.literal=.xtos.literal \
163 # -mrename-section-.rodata=.xtos.rodata \
164 # -mrename-section-.data=.xtos.data
165 #$(XTOS_SIM_OBJS) : XTFLAGS = $(XTOSSECFLAGS)
167 libhandlers-sim.a: $(XTOS_SIM_OBJS) $(XTOS_COMMON_OBJS)
169 libhandlers-board.a: $(XTOS_BOARD_OBJS) $(XTOS_COMMON_OBJS)
171 libhandlers-min.a: user-vector-min.o tiny-refs-min.o
173 libhandlers-null.a: $(call split_objs, null-vectors.S) _vectors.o _sharedvectors.o
175 libnomovsp.a: null-alloca.o
177 libnosyscall.a: null-syscall.o
179 $(PERLEVEL_INTVECTOR_OBJS): int-vector-level%.o: int-vector.S
180 $(XTCC) -c $(ASFLAGS) $(FLAGS_int-vector-level$*) $(XTFLAGS) -D_INTERRUPT_LEVEL=$* -o $@ $<
182 $(PERLEVEL_INTHANDLER_OBJS): int-handler-level%.o: int-handler.S
183 $(XTCC) -c $(ASFLAGS) $(FLAGS_int-handler-level$*) $(XTFLAGS) -D_INTERRUPT_LEVEL=$* -o $@ $<
185 $(PERLEVEL_INTINITLEV_OBJS): int-init-level%.o: int-initlevel.S
186 $(XTCC) -c $(ASFLAGS) $(FLAGS_int-init-level$*) $(XTFLAGS) -D_INTERRUPT_LEVEL=$* -o $@ $<
189 # For split-source rules, determine various things from $* (extended basename):
191 SPLIT_SRC = $(patsubst %/,%,$(dir $(subst -c--,.c/,$(subst -S--,.S/,$*))))
192 SPLIT_FLAGS = $(FLAGS_$(basename $(SPLIT_SRC))) \
193 -D__SPLIT__$(notdir $(subst --,/,$*))
195 # (Okay we cheat a bit, CFLAGS matches ASFLAGS so this works; it's also simpler:)
197 $(XTCC) -c $(CFLAGS) $(SPLIT_FLAGS) $(XTFLAGS) -o $@ $(SRCDIR)/$(SPLIT_SRC)
199 $(XTCC) -c $(CFLAGS) $(SPLIT_FLAGS) $(XTFLAGS) -DSIMULATOR -o $@ $(SRCDIR)/$(SPLIT_SRC)
203 $(XTCC) -c $(ASFLAGS) $(FLAGS_$*) $(XTFLAGS) $<
206 $(XTCC) -c $(CFLAGS) $(FLAGS_$*) $(XTFLAGS) $<
209 $(XTCC) -c $(ASFLAGS) $(FLAGS_$*) $(XTFLAGS) -DSIMULATOR -o $@ $<
212 $(XTCC) -c $(CFLAGS) $(FLAGS_$*) $(XTFLAGS) -DSIMULATOR -o $@ $<
214 # Explicit rule for crt1-sim.o to avoid using %-sim.o rule above:
215 crt1-sim.o: crt1-sim.S
216 $(XTCC) -c $(ASFLAGS) $(FLAGS_$*) $(XTFLAGS) $<
219 # When building the reset vector, leave the literals in
220 # the text section, so that the reset vector can be placed
221 # at address 0 (there's no lower address for the literals).
222 # (Can't do that on Xtensa TX without load/store to IRAM/IROM.)
224 ifneq ($(XPAL_HAVE_IMEM_LOADSTORE),0)
225 FLAGS_reset-vector = -mtext-section-literals
226 FLAGS_shared-reset-vector = -mtext-section-literals
229 #reset-vector.o: reset-vector.S
230 # $(XTCC) -c $(ASFLAGS) $(XTFLAGS) $(FLAGS_reset-vector) -o $@ $<
231 reset-vector-unpack.o: reset-vector.S
232 $(XTCC) -c $(ASFLAGS) $(XTFLAGS) $(FLAGS_reset-vector) -DXTOS_UNPACK -o $@ $<
233 reset-vector-mp.o: reset-vector.S
234 $(XTCC) -c $(ASFLAGS) $(XTFLAGS) $(FLAGS_reset-vector) -DXTOS_MP -o $@ $<
236 # These libraries provide alternative reset vectors:
237 # With ROM unpacking (the default):
238 libhandler-reset-unpack.a: reset-vector-unpack.o
239 # Without any unpacking:
240 libhandler-reset.a: reset-vector.o
241 # With experimental MP unpacking:
242 libhandler-reset-mp.a: reset-vector-mp.o
249 -$(MKPATH) $(INSTLIBDIR)
250 $(CP) $(TARGETS) $(INSTLIBDIR)
255 # NOTE: Header file dependencies not specified!