blob: 465b930f625a73e7b939cb93c3a31f97f01e28bb [file] [log] [blame]
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +09001#
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
Masahiro Yamada33ff3602015-03-27 10:59:01 +09007# Default sed regexp - multiline due to syntax constraints
8define sed-y
9 "s:[[:space:]]*\.ascii[[:space:]]*\"\(.*\)\":\1:; \
10 /^->/{s:->#\(.*\):/* \1 */:; \
11 s:^->\([^ ]*\) [\$$#]*\([-0-9]*\) \(.*\):#define \1 \2 /* \3 */:; \
12 s:^->\([^ ]*\) [\$$#]*\([^ ]*\) \(.*\):#define \1 \2 /* \3 */:; \
13 s:->::; p;}"
14endef
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090015
Michal Mareke19b6e02015-03-27 10:59:03 +090016# Use filechk to avoid rebuilds when a header changes, but the resulting file
17# does not
18define filechk_offsets
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090019 (set -e; \
Masahiro Yamada33ff3602015-03-27 10:59:01 +090020 echo "#ifndef $2"; \
21 echo "#define $2"; \
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090022 echo "/*"; \
23 echo " * DO NOT MODIFY."; \
24 echo " *"; \
25 echo " * This file was generated by Kbuild"; \
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090026 echo " */"; \
27 echo ""; \
Michal Mareke19b6e02015-03-27 10:59:03 +090028 sed -ne $(sed-y); \
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090029 echo ""; \
Michal Mareke19b6e02015-03-27 10:59:03 +090030 echo "#endif" )
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090031endef
32
Masahiro Yamada33ff3602015-03-27 10:59:01 +090033#####
34# 1) Generate generic-asm-offsets.h
35
36generic-offsets-file := include/generated/generic-asm-offsets.h
37
38always := $(generic-offsets-file)
39targets := $(generic-offsets-file) lib/asm-offsets.s
40
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090041# We use internal kbuild rules to avoid the "is up to date" message from make
42lib/asm-offsets.s: lib/asm-offsets.c FORCE
43 $(Q)mkdir -p $(dir $@)
44 $(call if_changed_dep,cc_s_c)
45
Michal Mareke19b6e02015-03-27 10:59:03 +090046$(obj)/$(generic-offsets-file): lib/asm-offsets.s FORCE
47 $(call filechk,offsets,__GENERIC_ASM_OFFSETS_H__)
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090048
49#####
50# 2) Generate asm-offsets.h
51#
52
Masahiro Yamada8226dfd2014-03-18 16:38:13 +090053ifneq ($(wildcard $(srctree)/arch/$(ARCH)/lib/asm-offsets.c),)
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090054offsets-file := include/generated/asm-offsets.h
55endif
56
57always += $(offsets-file)
58targets += $(offsets-file)
Masahiro Yamada8226dfd2014-03-18 16:38:13 +090059targets += arch/$(ARCH)/lib/asm-offsets.s
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090060
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090061CFLAGS_asm-offsets.o := -DDO_DEPS_ONLY
62
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090063# We use internal kbuild rules to avoid the "is up to date" message from make
Masahiro Yamada8226dfd2014-03-18 16:38:13 +090064arch/$(ARCH)/lib/asm-offsets.s: arch/$(ARCH)/lib/asm-offsets.c FORCE
Masahiro Yamada5aed6ed2014-02-24 11:12:11 +090065 $(Q)mkdir -p $(dir $@)
66 $(call if_changed_dep,cc_s_c)
67
Michal Mareke19b6e02015-03-27 10:59:03 +090068$(obj)/$(offsets-file): arch/$(ARCH)/lib/asm-offsets.s FORCE
69 $(call filechk,offsets,__ASM_OFFSETS_H__)