1# Copyright (c) 2014-2015 Tommie Gannert
2#
3# See the LICENSE file.
4#
5
6lib_LIBRARIES = libhal.a
7
8libhal_a_SOURCES = \
9	attribute.c \
10	cache.c \
11	clock.S \
12	coherence.c \
13	debug.c \
14	debug_hndlr.S \
15	memcopy.S \
16	misc.c \
17	mmu.c \
18	mp_asm.S \
19	mpu_asm.S \
20	mpu.c \
21	set_region_translate.c \
22	syscache_asm.S \
23	windowspill_asm.S
24
25EXTRA_DIST = $(splittable_sources)
26CLEANFILES = \
27	$(split_sources) \
28	$(split_makefiles)
29
30# We split some files into chunks so the linker has really fine-grained
31# linking abilities, while the code is not split up into too small chunks.
32#
33# Each splittable file has lines like
34#
35#   #[el]if defined(__SPLIT__tag)
36#
37# and we generate one object file per such section.
38
39splittable_sources = \
40	cache_asm.S \
41	disass.c \
42	int_asm.S \
43	interrupts.c \
44	mem_ecc_parity.S \
45	miscellaneous.S \
46	state_asm.S \
47	state.c
48
49# The name of our generated split source files.
50# Used for CLEANFILES.
51
52split_sources = $(shell cd $(top_srcdir)/src && $(AWK) -F '[()]' ' \
53	/^\#.* defined\(__SPLIT__(\w+)\)/ { \
54		sub(/__SPLIT__/, ""); \
55		f = FILENAME; \
56		sub(/\.[^.]+/, "--" $$2 "&", f); \
57		print f; \
58	}' $(splittable_sources))
59
60# Generate one makefile per splittable source file.
61# Each one contains rules to create one source file per split,
62# and adds it to libhal as a dependency and to Automake's OBJECTS variable.
63# (The former is needed because these includes are placed after the generated
64# libhal.a rule expands *_OBJECTS for dependencies.
65
66if XTENSA_CALL0_ABI
67awk_ignore_nw := /__SPLIT__.*_nw/ && !/__SPLIT__get_intpending_nw/ { next; }
68else
69awk_ignore_nw :=
70endif
71
72.DELETE_ON_ERROR: %.splittmp
73%-split.mk: % Makefile
74	sort "$<" | uniq | $(AWK) -F '[()]' ' \
75		$(awk_ignore_nw) \
76		/^#.* defined\(__SPLIT__(\w+)\)/ { \
77			tag = $$2; \
78			sub(/__SPLIT__/, "", tag); \
79			srcbase = "$(basename $(notdir $<))"; \
80			srcsuffix = "$(suffix $<)"; \
81			print srcbase "--" tag srcsuffix ": $< Makefile"; \
82			print "\techo \"#define " $$2 "\" >\"$$@.splittmp\""; \
83			print "\techo \"#include \\\"$<\\\"\" >>\"$$@.splittmp\""; \
84			print "\tmv \"$$@.splittmp\" \"$$@\""; \
85			print "libhal.a: " srcbase "--" tag ".$$(OBJEXT)"; \
86			print "libhal_a_OBJECTS += " srcbase "--" tag ".$$(OBJEXT)"; \
87		}' >"$@.splittmp"
88	mv "$@.splittmp" "$@"
89
90split_makefiles := $(patsubst %, %-split.mk, $(splittable_sources))
91
92-include $(split_makefiles)
93