xref: /openbmc/u-boot/Kbuild (revision bf7716d6)
1#
2# Kbuild for top-level directory of U-Boot
3# This file takes care of the following:
4# 1) Generate generic-asm-offsets.h
5# 2) Generate asm-offsets.h
6
7#####
8# 1) Generate generic-asm-offsets.h
9
10generic-offsets-file := include/generated/generic-asm-offsets.h
11
12always  := $(generic-offsets-file)
13targets := $(generic-offsets-file) lib/asm-offsets.s
14
15quiet_cmd_generic-offsets = GEN     $@
16define cmd_generic-offsets
17	(set -e; \
18	 echo "#ifndef __GENERIC_ASM_OFFSETS_H__"; \
19	 echo "#define __GENERIC_ASM_OFFSETS_H__"; \
20	 echo "/*"; \
21	 echo " * DO NOT MODIFY."; \
22	 echo " *"; \
23	 echo " * This file was generated by Kbuild"; \
24	 echo " *"; \
25	 echo " */"; \
26	 echo ""; \
27	 sed -ne $(sed-y) $<; \
28	 echo ""; \
29	 echo "#endif" ) > $@
30endef
31
32# We use internal kbuild rules to avoid the "is up to date" message from make
33lib/asm-offsets.s: lib/asm-offsets.c FORCE
34	$(Q)mkdir -p $(dir $@)
35	$(call if_changed_dep,cc_s_c)
36
37$(obj)/$(generic-offsets-file): lib/asm-offsets.s Kbuild
38	$(Q)mkdir -p $(dir $@)
39	$(call cmd,generic-offsets)
40
41#####
42# 2) Generate asm-offsets.h
43#
44
45ifneq ($(wildcard $(srctree)/$(CPUDIR)/$(SOC)/asm-offsets.c),)
46offsets-file := include/generated/asm-offsets.h
47endif
48
49always  += $(offsets-file)
50targets += $(offsets-file)
51targets += $(CPUDIR)/$(SOC)/asm-offsets.s
52
53
54# Default sed regexp - multiline due to syntax constraints
55define sed-y
56	"/^->/{s:->#\(.*\):/* \1 */:; \
57	s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
58	s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
59	s:->::; p;}"
60endef
61
62CFLAGS_asm-offsets.o := -DDO_DEPS_ONLY
63
64quiet_cmd_offsets = GEN     $@
65define cmd_offsets
66	(set -e; \
67	 echo "#ifndef __ASM_OFFSETS_H__"; \
68	 echo "#define __ASM_OFFSETS_H__"; \
69	 echo "/*"; \
70	 echo " * DO NOT MODIFY."; \
71	 echo " *"; \
72	 echo " * This file was generated by Kbuild"; \
73	 echo " *"; \
74	 echo " */"; \
75	 echo ""; \
76	 sed -ne $(sed-y) $<; \
77	 echo ""; \
78	 echo "#endif" ) > $@
79endef
80
81# We use internal kbuild rules to avoid the "is up to date" message from make
82$(CPUDIR)/$(SOC)/asm-offsets.s: $(CPUDIR)/$(SOC)/asm-offsets.c FORCE
83	$(Q)mkdir -p $(dir $@)
84	$(call if_changed_dep,cc_s_c)
85
86$(obj)/$(offsets-file): $(CPUDIR)/$(SOC)/asm-offsets.s
87	$(call cmd,offsets)
88