xref: /openbmc/u-boot/Kbuild (revision 3a4f6b60)
16a44d806SMasahiro Yamada#
26a44d806SMasahiro Yamada# Kbuild for top-level directory of U-Boot
36a44d806SMasahiro Yamada# This file takes care of the following:
46a44d806SMasahiro Yamada# 1) Generate generic-asm-offsets.h
56a44d806SMasahiro Yamada# 2) Generate asm-offsets.h
66a44d806SMasahiro Yamada
7490cf5f0SMasahiro Yamada# Default sed regexp - multiline due to syntax constraints
8490cf5f0SMasahiro Yamadadefine sed-y
9490cf5f0SMasahiro Yamada	"s:[[:space:]]*\.ascii[[:space:]]*\"\(.*\)\":\1:; \
10490cf5f0SMasahiro Yamada	/^->/{s:->#\(.*\):/* \1 */:; \
11490cf5f0SMasahiro Yamada	s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
12490cf5f0SMasahiro Yamada	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
13490cf5f0SMasahiro Yamada	s:->::; p;}"
14490cf5f0SMasahiro Yamadaendef
156a44d806SMasahiro Yamada
16*3a4f6b60SMichal Marek# Use filechk to avoid rebuilds when a header changes, but the resulting file
17*3a4f6b60SMichal Marek# does not
18*3a4f6b60SMichal Marekdefine filechk_offsets
196a44d806SMasahiro Yamada	(set -e; \
20490cf5f0SMasahiro Yamada	 echo "#ifndef $2"; \
21490cf5f0SMasahiro Yamada	 echo "#define $2"; \
226a44d806SMasahiro Yamada	 echo "/*"; \
236a44d806SMasahiro Yamada	 echo " * DO NOT MODIFY."; \
246a44d806SMasahiro Yamada	 echo " *"; \
256a44d806SMasahiro Yamada	 echo " * This file was generated by Kbuild"; \
266a44d806SMasahiro Yamada	 echo " */"; \
276a44d806SMasahiro Yamada	 echo ""; \
28*3a4f6b60SMichal Marek	 sed -ne $(sed-y); \
296a44d806SMasahiro Yamada	 echo ""; \
30*3a4f6b60SMichal Marek	 echo "#endif" )
316a44d806SMasahiro Yamadaendef
326a44d806SMasahiro Yamada
33490cf5f0SMasahiro Yamada#####
34490cf5f0SMasahiro Yamada# 1) Generate generic-asm-offsets.h
35490cf5f0SMasahiro Yamada
36490cf5f0SMasahiro Yamadageneric-offsets-file := include/generated/generic-asm-offsets.h
37490cf5f0SMasahiro Yamada
38490cf5f0SMasahiro Yamadaalways  := $(generic-offsets-file)
39490cf5f0SMasahiro Yamadatargets := $(generic-offsets-file) lib/asm-offsets.s
40490cf5f0SMasahiro Yamada
416a44d806SMasahiro Yamada# We use internal kbuild rules to avoid the "is up to date" message from make
426a44d806SMasahiro Yamadalib/asm-offsets.s: lib/asm-offsets.c FORCE
436a44d806SMasahiro Yamada	$(Q)mkdir -p $(dir $@)
446a44d806SMasahiro Yamada	$(call if_changed_dep,cc_s_c)
456a44d806SMasahiro Yamada
46*3a4f6b60SMichal Marek$(obj)/$(generic-offsets-file): lib/asm-offsets.s FORCE
47*3a4f6b60SMichal Marek	$(call filechk,offsets,__GENERIC_ASM_OFFSETS_H__)
486a44d806SMasahiro Yamada
496a44d806SMasahiro Yamada#####
506a44d806SMasahiro Yamada# 2) Generate asm-offsets.h
516a44d806SMasahiro Yamada#
526a44d806SMasahiro Yamada
53254d68b6SMasahiro Yamadaifneq ($(wildcard $(srctree)/arch/$(ARCH)/lib/asm-offsets.c),)
546a44d806SMasahiro Yamadaoffsets-file := include/generated/asm-offsets.h
556a44d806SMasahiro Yamadaendif
566a44d806SMasahiro Yamada
576a44d806SMasahiro Yamadaalways  += $(offsets-file)
586a44d806SMasahiro Yamadatargets += $(offsets-file)
59254d68b6SMasahiro Yamadatargets += arch/$(ARCH)/lib/asm-offsets.s
606a44d806SMasahiro Yamada
616a44d806SMasahiro YamadaCFLAGS_asm-offsets.o := -DDO_DEPS_ONLY
626a44d806SMasahiro Yamada
636a44d806SMasahiro Yamada# We use internal kbuild rules to avoid the "is up to date" message from make
64254d68b6SMasahiro Yamadaarch/$(ARCH)/lib/asm-offsets.s: arch/$(ARCH)/lib/asm-offsets.c FORCE
656a44d806SMasahiro Yamada	$(Q)mkdir -p $(dir $@)
666a44d806SMasahiro Yamada	$(call if_changed_dep,cc_s_c)
676a44d806SMasahiro Yamada
68*3a4f6b60SMichal Marek$(obj)/$(offsets-file): arch/$(ARCH)/lib/asm-offsets.s FORCE
69*3a4f6b60SMichal Marek	$(call filechk,offsets,__ASM_OFFSETS_H__)
70