]> rtime.felk.cvut.cz Git - omk.git/blob - snippets/config_h
Fixed a bug where LOCAL_CONFIG_H colide with default CFLAGS.
[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
8 # Syntax: $(call BUILD_CONFIG_H_template,<header_file_path>,<list_of_options_to_export>,<header_barrier>)
9 define BUILD_CONFIG_H_template
10
11 $(1) : $(wildcard $(CONFIG_FILE)) $(wildcard $(CONFIG_FILE)-default)
12         @$(QUIET_CMD_ECHO) "  CONFGEN $$(@:$(MAKERULES_DIR)/%=%)"
13         @if [ ! -d `dirname $(1).tmp` ] ; then \
14                 mkdir `dirname $(1).tmp` ; fi
15         @echo "/* Automatically generated from */" > "$(1).tmp"
16         @echo "/* config file: $$< */" >> "$(1).tmp"
17         @echo "#ifndef $(3)" >> "$(1).tmp"
18         @echo "#define $(3)" >> "$(1).tmp"
19         @( $(foreach x, $(shell echo '$($(2))' | sed -e 's/\<\([^ =]*\)\(=[^ ]\+\|\)\>/\1/g' ), \
20                 echo '$(x).$($(x))' ; ) echo ; ) | \
21                 sed -e '/^[^.]*\.n$$$$/d' -e '/^[^.]*\.$$$$/d' -e 's/^\([^.]*\)\.[ym]$$$$/\1.1/' | \
22                 sed -n -e 's/^\([^.]*\)\.\(.*\)$$$$/#define \1 \2/p' \
23                   >> "$(1).tmp"
24         @echo "#endif /*$(3)*/" >> "$(1).tmp"
25         @if cmp --quiet "$(1).tmp" "$(1)" ; then rm "$(1).tmp" ; \
26         else mv "$(1).tmp" "$(1)" ; \
27         echo Updated configuration "$(1)" ; fi
28
29 endef
30
31 ifdef LOCAL_CONFIG_H
32
33 # This must be declared after the default cflags are assigned!
34 # Override is used to override command line assignemnt.
35 override CFLAGS += -I.
36 $(eval $(call BUILD_CONFIG_H_template,$(LOCAL_CONFIG_H),default_CONFIG,_LOCAL_CONFIG_H) )
37
38 endif
39
40 # Special rules for configuration exported headers
41
42 #FIXME: The directory for headers should not be specified here.
43 $(foreach confh,$(config_include_HEADERS),$(eval $(call BUILD_CONFIG_H_template,$(addprefix $(USER_INCLUDE_DIR)/,$(confh)),$(basename $(notdir $(confh)))_DEFINES,\
44 _$(basename $(notdir $(confh)))_H \
45 )))
46
47 # Add some hooks to standard passes
48 include-pass-local: $(addprefix $(USER_INCLUDE_DIR)/,$(config_include_HEADERS))
49
50 clean-local: clean-local-config-h
51
52 clean-local-config-h:
53         @$(foreach confh,$(addprefix $(USER_INCLUDE_DIR)/,$(config_include_HEADERS)),\
54             if [ -e $(confh) ] ; then touch -t 200001010101 $(confh) ; fi ; \
55         )
56
57
58 # Local Variables:
59 # mode:makefile
60 # End: