Initial cut of the open ath9k htc firmware.
[open-ath9k-htc-firmware.git] / target_firmware / magpie_fw_dev / build / magpie_1_1 / sboot / athos / src / xtos / Makefile.src
1 # Makefile for XTOS in <xtensa_tools_root>/xtensa-elf/src/xtos
2
3 # Copyright (c) 2000-2010 Tensilica Inc.
4 #
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:
12 #
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
15 #
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.
23
24 #
25 #  This makefile assumes GNU make features
26 #
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>
34 #
35
36 ifndef XTENSA_TOOLS_ROOT
37 $(error Please set XTENSA_TOOLS_ROOT to the path to Xtensa Tools)
38 endif
39 #  NOTE:  For now, we assume $(XTENSA_TOOLS_ROOT)/bin is on the PATH.
40 ifndef XTENSA_ROOT
41 $(error Please set XTENSA_ROOT to the path to your specific Xtensa core package)
42 endif
43 ifndef INSTLIBDIR
44 $(error Please set INSTLIBDIR to the path where libraries and objects are installed)
45 #INSTLIBDIR = $(call fixpath,$(XTENSA_ROOT)/xtensa-elf/arch/lib)
46 endif
47
48 #  Select the specified Xtensa configuration:
49 export XTENSA_SYSTEM = $(XTENSA_ROOT)/config
50 export XTENSA_CORE = default
51
52 include $(XTENSA_TOOLS_ROOT)/misc/defs.mk
53 include $(XTENSA_ROOT)/misc/build.mk
54
55 ifndef SRCDIR
56 $(error Please set MAKEFILE_SRC to the path to the XTOS Makefile.src)
57 endif
58
59 #  Native commands like $(MKPATH) and $(CP) need native directory separators:
60 #fixpath = $(subst /,$S,$(1))
61
62 XTCC  = $(CC_FOR_TARGET)
63 XTAR  = xt-ar
64
65 .PHONY: all install clean
66
67 # Compilation flags
68 ASFLAGS  = -O2 -g -mlongcalls
69 CFLAGS   = -O2 -g -mlongcalls
70
71 #  File splitting:
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.
82 #
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))
85
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)
90 XTOS_COMMON_OBJS = \
91         reset-vector-unpack.o \
92         shared-reset-vector.o \
93         user-vector.o \
94         nmi-vector.o \
95         window-vectors.o \
96         reloc-vectors.o \
97         $(call split_objs, memerror-vector.S) \
98         $(PERLEVEL_INTVECTOR_OBJS) \
99         exc-alloca-handler.o \
100         exc-return.o \
101         exc-sethandler.o \
102         exc-syscall-handler.o \
103         exc-syscall-c-handler.o \
104         exc-table.o \
105         exit.o \
106         init.o \
107         int-lowpri-dispatcher.o \
108         int-sethandler.o \
109         intlevel-set.o \
110         intlevel-setmin.o \
111         intlevel-restore.o \
112         ints-on.o \
113         ints-off.o \
114         switch_context.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 = \
120         debug-vector.o \
121         double-vector.o \
122         kernel-vector.o \
123         interrupt-table.o \
124         exc-unhandled.o \
125         exc-c-wrapper-handler.o \
126         memep-initrams.o \
127         memep-enable.o
128 XTOS_BOARD_OBJS = $(XTOS_SIMBOARD_OBJS)
129 XTOS_SIM_OBJS = $(XTOS_SIMBOARD_OBJS:.o=-sim.o)
130
131 #  Optimize a few things for size rather than speed:
132 #FLAGS_exc-syscall-handler = -Os --no-target-align
133
134 TARGETS = \
135         _vectors.o \
136         _sharedvectors.o \
137         _sharedvectors-for-reset.o \
138         crt0-app.o \
139         crt1-boards.o \
140         crt1-tiny.o \
141         crt1-sim.o \
142         libhandlers-sim.a \
143         libhandlers-board.a \
144         libhandlers-min.a \
145         libhandlers-null.a \
146         libnomovsp.a \
147         libnosyscall.a \
148         libhandler-reset-unpack.a \
149         libhandler-reset.a
150 ifdef TENSILICA_INTERNAL
151 TARGETS += libhandler-reset-mp.a
152 endif
153
154 all: $(TARGETS)
155
156
157 #  Here's an example of how one could put a selected set of
158 #  objects into a specific section:
159 #
160 #XTOSSECFLAGS = \
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)
166
167 libhandlers-sim.a: $(XTOS_SIM_OBJS) $(XTOS_COMMON_OBJS)
168
169 libhandlers-board.a: $(XTOS_BOARD_OBJS) $(XTOS_COMMON_OBJS)
170
171 libhandlers-min.a: user-vector-min.o tiny-refs-min.o
172
173 libhandlers-null.a: $(call split_objs, null-vectors.S) _vectors.o _sharedvectors.o
174
175 libnomovsp.a: null-alloca.o
176
177 libnosyscall.a: null-syscall.o
178
179 $(PERLEVEL_INTVECTOR_OBJS): int-vector-level%.o: int-vector.S
180         $(XTCC) -c $(ASFLAGS) $(FLAGS_int-vector-level$*) $(XTFLAGS) -D_INTERRUPT_LEVEL=$* -o $@ $<
181
182 $(PERLEVEL_INTHANDLER_OBJS): int-handler-level%.o: int-handler.S
183         $(XTCC) -c $(ASFLAGS) $(FLAGS_int-handler-level$*) $(XTFLAGS) -D_INTERRUPT_LEVEL=$* -o $@ $<
184
185 $(PERLEVEL_INTINITLEV_OBJS): int-init-level%.o: int-initlevel.S
186         $(XTCC) -c $(ASFLAGS) $(FLAGS_int-init-level$*) $(XTFLAGS) -D_INTERRUPT_LEVEL=$* -o $@ $<
187
188
189 #  For split-source rules, determine various things from $* (extended basename):
190 #
191 SPLIT_SRC = $(patsubst %/,%,$(dir $(subst -c--,.c/,$(subst -S--,.S/,$*))))
192 SPLIT_FLAGS = $(FLAGS_$(basename $(SPLIT_SRC))) \
193                 -D__SPLIT__$(notdir $(subst --,/,$*))
194
195 #  (Okay we cheat a bit, CFLAGS matches ASFLAGS so this works; it's also simpler:)
196 %-.o:
197         $(XTCC) -c $(CFLAGS) $(SPLIT_FLAGS) $(XTFLAGS) -o $@ $(SRCDIR)/$(SPLIT_SRC)
198 %--sim.o:
199         $(XTCC) -c $(CFLAGS) $(SPLIT_FLAGS) $(XTFLAGS) -DSIMULATOR -o $@ $(SRCDIR)/$(SPLIT_SRC)
200
201
202 %.o: %.S
203         $(XTCC) -c $(ASFLAGS) $(FLAGS_$*) $(XTFLAGS) $<
204
205 %.o: %.c
206         $(XTCC) -c $(CFLAGS)  $(FLAGS_$*) $(XTFLAGS) $<
207
208 %-sim.o: %.S
209         $(XTCC) -c $(ASFLAGS) $(FLAGS_$*) $(XTFLAGS) -DSIMULATOR -o $@ $<
210
211 %-sim.o: %.c
212         $(XTCC) -c $(CFLAGS)  $(FLAGS_$*) $(XTFLAGS) -DSIMULATOR -o $@ $<
213
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) $<
217
218
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.)
223
224 ifneq ($(XPAL_HAVE_IMEM_LOADSTORE),0)
225 FLAGS_reset-vector = -mtext-section-literals
226 FLAGS_shared-reset-vector = -mtext-section-literals
227 endif
228
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 $@ $<
235 #
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
243
244 %.a:
245         -$(RM) $@
246         $(XTAR) rs $@ $^
247
248 install:
249         -$(MKPATH) $(INSTLIBDIR)
250         $(CP) $(TARGETS) $(INSTLIBDIR)
251
252 clean:
253         -$(RM) *.o *.a
254
255 # NOTE: Header file dependencies not specified!
256