1# Makefile for the link-time HAL in <xtensa_tools_root>/xtensa-elf/src/hal
2
3# Copyright (c) 1999-2013 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> XTENSA_TOOLS_ROOT=<path to Xtensa Tools> \
30#		XTENSA_ROOT=<path to Xtensa core package> \
31#		INSTLIBDIR=<path to installation directory>
32#
33
34ifndef XTENSA_TOOLS_ROOT
35$(error Please set XTENSA_TOOLS_ROOT to the path to Xtensa Tools)
36endif
37#  NOTE:  For now, we assume $(XTENSA_TOOLS_ROOT)/bin is on the PATH.
38ifndef XTENSA_ROOT
39$(error Please set XTENSA_ROOT to the path to your specific Xtensa core package)
40endif
41ifndef INSTLIBDIR
42$(error Please set INSTLIBDIR to the path where libraries and objects are installed)
43#INSTLIBDIR = $(call fixpath,$(XTENSA_ROOT)/xtensa-elf/arch/lib)
44endif
45
46#  Select the specified Xtensa configuration:
47export XTENSA_SYSTEM = $(XTENSA_ROOT)/config
48export XTENSA_CORE = default
49
50include $(XTENSA_TOOLS_ROOT)/misc/defs.mk
51
52ifndef SRCDIR
53$(error Please set MAKEFILE_SRC to the path to this Makefile.src)
54endif
55
56CFLAGS = -O2 -g -mlongcalls
57
58#  Uncomment this to compile deprecated (pre-T1020.2) beta HAL definitions:
59#CFLAGS += -DINCLUDE_DEPRECATED_HAL_CODE
60#  Uncomment this to compile deprecated (pre-T1040.2) debug-support definitions:
61#CFLAGS += -DINCLUDE_DEPRECATED_HAL_DEBUG_CODE
62#  Uncomment this to compile deprecated (pre-T1040.2) cache-support definitions:
63#CFLAGS += -DINCLUDE_DEPRECATED_HAL_CACHE_CODE
64
65
66#  Compile parts of these files separately, to avoid unnecessarily large
67#  objects without creating too many source files.
68#  Files are split with "#[el]if defined(__SPLIT__<tag>)" lines
69#  using normal C preprocessor syntax, where each <tag> must be unique and
70#  consist of lowercase alphanumeric and underscore characters only (no dash etc).
71
72SPLIT_SOURCES = interrupts.c int_asm.S cache_asm.S state_asm.S state.c mem_ecc_parity.S \
73		miscellaneous.S disass.c
74
75#  Determine split object files to create, of form <srcbasename>--<tag>.o :
76SPLIT_OBJS := $(shell cd $(SRCDIR) && $(PERL) -ne '/__SPLIT__(\w+)/ and $$h{$$ARGV."--".$$1}++;\
77 END {foreach (sort keys %h) {s/\..--/--/; print "$$_.o\n";}}' $(SPLIT_SOURCES))
78#  Make doesn't stop if $(shell ...) fails, so catch any such failure explicitly:
79ifeq ($(SPLIT_OBJS),)
80$(error Error invoking $(PERL) to split sources $(SPLIT_SOURCES))
81endif
82
83#  Call0 ABI means the xthal... and xthal..._nw functions are
84#  identical.  If we're building for Call0 ABI, omit the ..._nw
85#  functions (except for xthal_get_intpending_nw, an interrupt handler
86#  helper function for which there is no duplicate and which does not
87#  obey _any_ calling conventions).
88
89CALL0_ABI :=$(filter __XTENSA_CALL0_ABI__, $(shell echo '' | $(CC_FOR_TARGET) --xtensa-system=$(XTENSA_SYSTEM) --xtensa-core=$(XTENSA_CORE) -E -dM - ))
90ifneq ($(CALL0_ABI),)
91SPLIT_OBJS := $(filter-out %_nw.o,$(SPLIT_OBJS))
92SPLIT_OBJS := $(SPLIT_OBJS) int_asm--get_intpending_nw.o
93endif
94
95
96OBJS = \
97	cache.o			\
98	syscache_asm.o		\
99	attribute.o		\
100	coherence.o		\
101	clock.o			\
102	debug.o			\
103	disass.o                \
104	debug_hndlr.o		\
105	memcopy.o		\
106	misc.o			\
107	miscellaneous.o		\
108	mmu.o			\
109	mp_asm.o		\
110	windowspill_asm.o	\
111	set_region_translate.o	\
112	$(SPLIT_OBJS)
113
114HALLIB = libhal.a
115
116
117.PHONY: all install clean
118
119all: $(HALLIB)
120
121$(HALLIB): $(OBJS)
122
123#  For following rule, determine various things from $* (extended basename):
124SPLIT_SOURCE = $(filter $(patsubst %/,%,$(dir $(subst --,/,$*))).%,$(SPLIT_SOURCES))
125SPLIT_TAG    = $(notdir $(subst --,/,$*))
126SPLIT_FLAGS  = $(FLAGS_$(basename $(SPLIT_SOURCE)))
127
128$(SPLIT_OBJS): %.o:
129	$(CC_FOR_TARGET) -c $(CFLAGS) $(SPLIT_FLAGS) $(SRCDIR)/$(SPLIT_SOURCE) -D__SPLIT__$(SPLIT_TAG) -MMD -MF $*.d -o $@
130
131%.o: %.S
132	$(CC_FOR_TARGET) -c $(CFLAGS) $(FLAGS_$*) $< -o $@
133
134%.o: %.c
135	$(CC_FOR_TARGET) -c $(CFLAGS) $(FLAGS_$*) $< -o $@
136
137%.a:
138	-$(RM) $@
139	$(AR_FOR_TARGET) -rs $@ $^
140
141
142install: all
143	$(MKPATH) $(INSTLIBDIR)
144	$(CP) $(HALLIB) $(INSTLIBDIR)
145
146clean:
147	-$(RM) $(OBJS) $(HALLIB) *.d
148
149# NOTE: Header file dependencies not specified!
150-include *.d
151
152