1 # Makefile for XTOS in <xtensa_tools_root>/xtensa-elf/src/xtos
3 # Copyright (c) 2000-2007 by Tensilica Inc. ALL RIGHTS RESERVED.
4 # These coded instructions, statements, and computer programs are the
5 # copyrighted works and confidential proprietary information of Tensilica Inc.
6 # They may not be modified, copied, reproduced, distributed, or disclosed to
7 # third parties in any manner, medium, or form, in whole or in part, without
8 # the prior written consent of Tensilica Inc.
11 # This makefile assumes GNU make features
13 # Invoke this Makefile like this:
14 # cd <some build directory>
15 # make -f <this file> \
16 # MAKEFILE_SRC=<this file> \
17 # XTENSA_TOOLS_ROOT=<path to Xtensa Tools> \
18 # XTENSA_ROOT=<path to Xtensa core package> \
19 # INSTLIBDIR=<path to installation directory>
22 ifndef XTENSA_TOOLS_ROOT
23 $(error Please set XTENSA_TOOLS_ROOT to the path to Xtensa Tools)
25 # NOTE: For now, we assume $(XTENSA_TOOLS_ROOT)/bin is on the PATH.
27 $(error Please set XTENSA_ROOT to the path to your specific Xtensa core package)
31 #$(error Please set INSTLIBDIR to the path where libraries and objects are installed)
32 #INSTLIBDIR = $(call fixpath,$(XTENSA_ROOT)/xtensa-elf/arch/lib)
35 # Select the specified Xtensa configuration:
36 export XTENSA_SYSTEM = $(XTENSA_ROOT)/config
37 export XTENSA_CORE = default
39 include $(XTENSA_TOOLS_ROOT)/misc/defs.mk
42 $(error Please set MAKEFILE_SRC to the path to the XTOS Makefile.src)
45 # Native commands like $(MKPATH) and $(CP) need native directory separators:
46 #fixpath = $(subst /,$S,$(1))
48 XTCC = $(CC_FOR_TARGET)
54 ASFLAGS = -O2 -g -mlongcalls
55 CFLAGS = -O2 -g -mlongcalls
58 # Compile "split" files in separate parts that can be linked independently.
59 # This allows keeping multiple related functions/etc together in one file
60 # without forcing linking of unused functions (the GNU linker takes entire
61 # object files; it does not currently provide automated dead code removal).
62 # Files are split with "#[el]if defined(__SPLIT__<tag>)" lines using normal
63 # C preprocessor syntax, where each <tag> must be unique and consist of
64 # lowercase alphanumeric and underscore characters only (no dash etc).
65 # The makefile function $(split_objs ...) returns the set of objects that
66 # result for a given list of splittable source files; each ends in a -.o
67 # suffix recognized by special rules further below.
69 split_objs = $(shell cd $(SRCDIR) && $(PERL) -ne '/__SPLIT__(\w+)/ and $$h{$$ARGV."--".$$1}++;\
70 END {foreach (sort keys %h) {s/\.(.)--/-$$1--/; print "$$_-.o\n";}}' $(1))
72 # Vectors, handlers, and other code to build:
73 PERLEVEL_INTVECTOR_OBJS = $(foreach N,2 3 4 5 6,int-vector-level$(N).o)
74 PERLEVEL_INTHANDLER_OBJS = $(foreach N,2 3 4 5 6,int-handler-level$(N).o)
75 PERLEVEL_INTINITLEV_OBJS = $(foreach N,1 2 3 4 5 6,int-init-level$(N).o)
77 reset-vector-unpack.o \
82 $(call split_objs, memerror-vector.S) \
83 $(PERLEVEL_INTVECTOR_OBJS) \
84 exc-alloca-handler.o \
87 exc-syscall-handler.o \
88 exc-syscall-c-handler.o \
92 int-lowpri-dispatcher.o \
100 $(call split_objs, deprecated.S tiny-refs.S) \
101 $(PERLEVEL_INTHANDLER_OBJS) \
102 $(PERLEVEL_INTINITLEV_OBJS)
103 # These objects have simulator and board variants:
104 XTOS_SIMBOARD_OBJS = \
110 exc-c-wrapper-handler.o \
113 XTOS_BOARD_OBJS = $(XTOS_SIMBOARD_OBJS)
114 XTOS_SIM_OBJS = $(XTOS_SIMBOARD_OBJS:.o=-sim.o)
116 # Optimize a few things for size rather than speed:
117 #FLAGS_exc-syscall-handler = -Os --no-target-align
126 libhandlers-board.a \
132 ifdef TENSILICA_INTERNAL
133 TARGETS += libhandler-reset-mp.a
139 # Here's an example of how one could put a selected set of
140 # objects into a specific section:
143 # -mrename-section-.text=.xtos.text \
144 # -mrename-section-.literal=.xtos.literal \
145 # -mrename-section-.rodata=.xtos.rodata \
146 # -mrename-section-.data=.xtos.data
147 #$(XTOS_SIM_OBJS) : XTFLAGS = $(XTOSSECFLAGS)
149 libhandlers-sim.a: $(XTOS_SIM_OBJS) $(XTOS_COMMON_OBJS)
151 libhandlers-board.a: $(XTOS_BOARD_OBJS) $(XTOS_COMMON_OBJS)
153 libhandlers-min.a: user-vector-min.o tiny-refs-min.o
155 libhandlers-null.a: $(call split_objs, null-vectors.S) _vectors.o
157 libnomovsp.a: null-alloca.o
159 libnosyscall.a: null-syscall.o
161 $(PERLEVEL_INTVECTOR_OBJS): int-vector-level%.o: int-vector.S
162 $(XTCC) -c $(ASFLAGS) $(FLAGS_int-vector-level$*) $(XTFLAGS) -D_INTERRUPT_LEVEL=$* -o $@ $<
164 $(PERLEVEL_INTHANDLER_OBJS): int-handler-level%.o: int-handler.S
165 $(XTCC) -c $(ASFLAGS) $(FLAGS_int-handler-level$*) $(XTFLAGS) -D_INTERRUPT_LEVEL=$* -o $@ $<
167 $(PERLEVEL_INTINITLEV_OBJS): int-init-level%.o: int-initlevel.S
168 $(XTCC) -c $(ASFLAGS) $(FLAGS_int-init-level$*) $(XTFLAGS) -D_INTERRUPT_LEVEL=$* -o $@ $<
171 # For split-source rules, determine various things from $* (extended basename):
173 SPLIT_SRC = $(patsubst %/,%,$(dir $(subst -c--,.c/,$(subst -S--,.S/,$*))))
174 SPLIT_FLAGS = $(FLAGS_$(basename $(SPLIT_SRC))) \
175 -D__SPLIT__$(notdir $(subst --,/,$*))
177 # (Okay we cheat a bit, CFLAGS matches ASFLAGS so this works; it's also simpler:)
179 $(XTCC) -c $(CFLAGS) $(SPLIT_FLAGS) $(XTFLAGS) -o $@ $(SRCDIR)/$(SPLIT_SRC)
181 $(XTCC) -c $(CFLAGS) $(SPLIT_FLAGS) $(XTFLAGS) -DSIMULATOR -o $@ $(SRCDIR)/$(SPLIT_SRC)
185 $(XTCC) -c $(ASFLAGS) $(FLAGS_$*) $(XTFLAGS) $<
188 $(XTCC) -c $(CFLAGS) $(FLAGS_$*) $(XTFLAGS) $<
191 $(XTCC) -c $(ASFLAGS) $(FLAGS_$*) $(XTFLAGS) -DSIMULATOR -o $@ $<
194 $(XTCC) -c $(CFLAGS) $(FLAGS_$*) $(XTFLAGS) -DSIMULATOR -o $@ $<
196 # Explicit rule for crt1-sim.o to avoid using %-sim.o rule above:
197 crt1-sim.o: crt1-sim.S
198 $(XTCC) -c $(ASFLAGS) $(FLAGS_$*) $(XTFLAGS) $<
201 # When building the reset vector, leave the literals in
202 # the text section, so that the reset vector can be placed
203 # at address 0 (there's no lower address for the literals).
205 #FLAGS_reset-vector = -mtext-section-literals
207 reset-vector.o: reset-vector.S
208 $(XTCC) -c $(ASFLAGS) $(XTFLAGS) -mtext-section-literals -o $@ $<
209 reset-vector-unpack.o: reset-vector.S
210 $(XTCC) -c $(ASFLAGS) $(XTFLAGS) -mtext-section-literals -DXTOS_UNPACK -o $@ $<
211 reset-vector-mp.o: reset-vector.S
212 $(XTCC) -c $(ASFLAGS) $(XTFLAGS) -mtext-section-literals -DXTOS_MP -o $@ $<
214 # These libraries provide alternative reset vectors:
215 # Without any unpacking:
216 libhandler-reset.a: reset-vector.o
217 # With experimental MP unpacking:
218 libhandler-reset-mp.a: reset-vector-mp.o
225 # -$(MKPATH) $(INSTLIBDIR)
226 # $(CP) $(TARGETS) $(INSTLIBDIR)
231 # NOTE: Header file dependencies not specified!