]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/config_h
35cd3aa0000481d00190ff39a365954a17184013
[omk.git] / snippets / config_h
1 # LOCAL_CONFIG_H   .. name of local config.h file generated from values
2 #                     of options defined in the current directory
3 # config_include_HEADERS .. names of global config files (possibly
4 #                     with subdirectories)
5 # xxx_DEFINES      .. list of config directives to be included in
6 #                     config header file of the name <somedir>/xxx.h
7 # DOXYGEN          .. if non-empty, generated headers includes Doxygen's @file
8 #                     command, so it is possible to document config
9 #                     variables.
10
11 # Syntax: $(call BUILD_CONFIG_H_template,<stamp_dir>,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
12 define BUILD_CONFIG_H_template
13
14 $(addprefix $(1)/,$(notdir $(addsuffix .stamp,$(2)))) : $(CONFIG_FILES)
15         @$(QUIET_CMD_ECHO) "  CONFGEN $$(@:%.stamp=%)"
16         @if [ ! -d `dirname $(2).tmp` ] ; then \
17                 mkdir -p `dirname $(2).tmp` ; fi
18         @echo "/* Automatically generated from */" > "$(2).tmp"
19         @echo "/* config files: $$(^:$(MAKERULES_DIR)/%=%) */" >> "$(2).tmp"
20         $(if $(DOXYGEN),@echo "/** @file */" >> "$(2).tmp")
21         @echo "#ifndef $(4)" >> "$(2).tmp"
22         @echo "#define $(4)" >> "$(2).tmp"
23         @( $(foreach x, $(shell echo '$($(3))' | tr 'x\t ' 'x\n\n' | sed -e 's/^\([^ =]*\)\(=[^ ]\+\|\)$$/\1/' ), \
24                 echo '$(x).$($(x))' ; ) echo ; ) | \
25                 sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
26                 sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
27                   >> "$(2).tmp"
28         @echo "#endif /*$(4)*/" >> "$(2).tmp"
29         @touch "$$@"
30         @if cmp --quiet "$(2).tmp" "$(2)" ; then rm "$(2).tmp"; \
31         else mv "$(2).tmp" "$(2)" ; \
32         echo "Updated configuration $(2)" ; fi
33
34 endef
35
36 ifdef LOCAL_CONFIG_H
37
38 # This must be declared after the default cflags are assigned!
39 # Override is used to override command line assignemnt.
40 override CFLAGS += -I.
41 $(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(USER_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
42
43 endif
44
45 # Special rules for configuration exported headers
46
47 #FIXME: The directory for headers should not be specified here.
48 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(USER_OBJS_DIR),$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
49 _$(basename $(notdir $(confh)))_H \
50 )))
51
52 config_h_stamp_files = $(addprefix $(USER_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
53
54 # Add some hooks to standard passes
55 include-pass-local: $(config_h_stamp_files)
56
57 ifneq ($(KERN_CONFIG_HEADERS_REQUIRED),)
58
59 ifdef LOCAL_CONFIG_H
60 $(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(KERN_OBJS_DIR)/$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
61 endif
62
63 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(KERN_OBJS_DIR),$(addprefix $(KERN_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
64 _$(basename $(notdir $(confh)))_H \
65 )))
66
67 kern_config_h_stamp_files = $(addprefix $(KERN_OBJS_DIR)/,$(notdir $(addsuffix .stamp,$(config_include_HEADERS) $(LOCAL_CONFIG_H))))
68
69 # Add some hooks to standard passes
70 include-pass-local: $(kern_config_h_stamp_files)
71
72 endif
73
74 clean-local: clean-local-config-h
75
76 clean-local-config-h:
77         @$(foreach confh,$(config_h_stamp_files) $(kern_config_h_stamp_files),\
78             if [ -e $(confh) ] ; then rm $(confh) ; fi ; \
79         )
80
81
82 # Local Variables:
83 # mode:makefile
84 # End: