]> rtime.felk.cvut.cz Git - omk.git/commitdiff
Support program specific CFLAGS, CXXCLAGS and CPPFLAGS
authorMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 22 Nov 2013 16:40:40 +0000 (17:40 +0100)
committerMichal Sojka <sojkam1@fel.cvut.cz>
Fri, 22 Nov 2013 16:40:40 +0000 (17:40 +0100)
doc/omk-manual.texinfo
snippets/linux.omk
tests/programs-cflags

index 7f92ff1fe41f9b1325ae78ce9fbb54b726446673..b3f60d434155e454f0ce5a2795e19efb8dbc7658 100644 (file)
@@ -359,13 +359,6 @@ source @file{test.c}.
   source.
 @end defvar
 
-@defvar xxx_GEN_SOURCES
-  Program sources generated (by other rules) in the build directory. See
-  the following example.
-  @verbatiminclude tests/programs/generated-sources/Makefile.omk
-
-@end defvar
-
 @defvar xxx_LIBS
   This variable contains a list of libraries the program @var{xxx} will
   be linked with.
@@ -375,6 +368,28 @@ source @file{test.c}.
   @end example
 @end defvar
 
+@defvar xxx_CFLAGS
+  CFLAGS specific for the compiler program. If this variable is set, its
+  value efectively overrides the value of AM_CFLAGS variable.
+@end defvar
+
+@defvar xxx_CXXFLAGS
+  CXXFLAGS specific for the compiler program. If this variable is set, its
+  value efectively overrides the value of AM_CXXFLAGS variable.
+@end defvar
+
+@defvar xxx_CPPFLAGS
+  CPPFLAGS specific for the compiler program. If this variable is set, its
+  value efectively overrides the value of AM_CPPFLAGS variable.
+@end defvar
+
+@defvar xxx_GEN_SOURCES
+  Program sources generated (by other rules) in the build directory. See
+  the following example.
+  @verbatiminclude tests/programs/generated-sources/Makefile.omk
+
+@end defvar
+
 @defvar lib_LOADLIBES
   This variable contains a list of libraries which needs to be linked to
   to all programs or shared libraries in this directory.
index 94400e18c7d6ec18c449875272577f0612e5fd36..3b2595f55960a89dc69e5ff44ccb466430c9a37c 100644 (file)
@@ -207,18 +207,18 @@ $(2).c $(2)-stubs.c $(2)-skels.c $(2)-common.c $(2).h: $(1) $$(wildcard $$(first
 endif
 endef
 
-# Syntax: $(call COMPILE_templates,<sources_abs>,<suffix>)
+# Syntax: $(call COMPILE_templates,<sources_abs>,<suffix>,<obj-prefix>)
 # Note: The newlines after $(call ) are IMPORTANT!!!
 define COMPILE_templates
-$(foreach src,$(filter %.c,$(1)),$(call COMPILE_c_o_template,$(src),$(notdir $(src:%.c=%$(2))),)
+$(foreach src,$(filter %.c,$(1)),$(call COMPILE_c_o_template,$(src),$(3)$(notdir $(src:%.c=%$(2))),)
 )
-$(foreach src,$(filter %.cc,$(1)),$(call COMPILE_cc_o_template,$(src),$(notdir $(src:%.cc=%$(2))),)
+$(foreach src,$(filter %.cc,$(1)),$(call COMPILE_cc_o_template,$(src),$(3)$(notdir $(src:%.cc=%$(2))),)
 )
-$(foreach src,$(filter %.cxx,$(1)),$(call COMPILE_cc_o_template,$(src),$(notdir $(src:%.cxx=%$(2))),)
+$(foreach src,$(filter %.cxx,$(1)),$(call COMPILE_cc_o_template,$(src),$(3)$(notdir $(src:%.cxx=%$(2))),)
 )
-$(foreach src,$(filter %.cpp,$(1)),$(call COMPILE_cc_o_template,$(src),$(notdir $(src:%.cpp=%$(2))),)
+$(foreach src,$(filter %.cpp,$(1)),$(call COMPILE_cc_o_template,$(src),$(3)$(notdir $(src:%.cpp=%$(2))),)
 )
-$(foreach src,$(filter %.S,$(1)),$(call COMPILE_S_o_template,$(src),$(notdir $(src:%.S=%$(2))),)
+$(foreach src,$(filter %.S,$(1)),$(call COMPILE_S_o_template,$(src),$(3)$(notdir $(src:%.S=%$(2))),)
 )
 endef
 
@@ -229,19 +229,26 @@ TARGET_IDL_SOURCES =  $(filter %.c,$($(1)_SERVER_IDL:%.idl=%-skels.c)) \
                       $(filter %.c,$($(1)_IDL:%.idl=%.c))
 TARGET_SOURCES = $($(1)_SOURCES) $($(1)_GEN_SOURCES) $(TARGET_IDL_SOURCES)
 TARGET_SOURCES_ABS = $($(1)_SOURCES:%=$(SOURCES_DIR)/%) $($(1)_GEN_SOURCES) $(TARGET_IDL_SOURCES)
-TARGET_OBJS  = $(sort $(addsuffix .o,$(basename $(notdir $(TARGET_SOURCES)))))
+TARGET_OBJ_PREFIX = $(if $($(1)_CFLAGS)$($(1)_CXXFLAGS)$($(1)_CPPFLAGS),$(1)-,)
+TARGET_OBJS  = $(sort $(addprefix $(TARGET_OBJ_PREFIX),$(addsuffix .o,$(basename $(notdir $(TARGET_SOURCES))))))
 TARGET_LOBJS = $(sort $(addsuffix .lo,$(basename $(notdir $(TARGET_SOURCES)))))
 TARGET_IDLS = $($(1)_SERVER_IDL) $($(1)_CLIENT_IDL) $($(1)_IDL)
+TARGET_CFLAGS   = $(if $($(1)_CFLAGS),$($(1)_CFLAGS),$(AM_CFLAGS))
+TARGET_CXXFLAGS = $(if $($(1)_CXXFLAGS),$($(1)_CXXFLAGS),$(AM_CXXFLAGS))
+TARGET_CPPFLAGS = $(if $($(1)_CPPFLAGS),$($(1)_CPPFLAGS),$(AM_CPPFLAGS))
 LINK_WITH_CXX = $(filter %.cc,$(TARGET_SOURCES))$(filter %.cxx,$(TARGET_SOURCES))$$(filter %.cpp,$(TARGET_SOURCES))
 
 # Syntax: $(call PROGRAM_template,<executable-name>,<dir>,<executable-suffix>,<linker-sript>)
 define PROGRAM_template
 $(foreach idl,$(TARGET_IDLS),$(call COMPILE_idl_template,$(SOURCES_DIR)/$(idl),$(idl:%.idl=%)))
 
-$(call COMPILE_templates,$(TARGET_SOURCES_ABS),.o)
+$(call COMPILE_templates,$(TARGET_SOURCES_ABS),.o,$(TARGET_OBJ_PREFIX))
 
+$(2)/$(1)$(3): AM_CFLAGS=$(TARGET_CFLAGS)
+$(2)/$(1)$(3): AM_CXXFLAGS=$(TARGET_CXXFLAGS)
+$(2)/$(1)$(3): AM_CPPFLAGS=$(TARGET_CPPFLAGS)
 $(2)/$(1)$(3): $(TARGET_OBJS)
-       @$(QUIET_CMD_ECHO) "  LINK    $$@"
+       @$(QUIET_CMD_ECHO) "  LINK    $$@ >$(1)<"
        $(Q) $(if $(LINK_WITH_CXX),$$(CXX),$$(CC)) \
          $$^ $$($(1)_LIBS:%=-l%) $$(LOADLIBES) $$(AM_LDFLAGS) $$(LDFLAGS) $$($(1)_LDFLAGS) -Wl,-rpath-link,$(USER_LIB_DIR) -Wl,-Map,$(USER_OBJS_DIR)/$(1).exe.map -o $$@
        @echo "$(2)/$(1)$(3): \\" >$(USER_OBJS_DIR)/$(1).exe.d
@@ -320,6 +327,7 @@ $(foreach prog,$(bin_PROGRAMS),$(eval $(call PROGRAM_template,$(prog),$(USER_BIN
 $(foreach script,$(bin_SCRIPTS),$(eval $(call SCRIPT_template,$(script),$(USER_BIN_DIR))))
 
 
+# $(foreach lib,$(lib_LIBRARIES),$(info $(call LIBRARY_template,$(lib))))
 $(foreach lib,$(lib_LIBRARIES),$(eval $(call LIBRARY_template,$(lib))))
 
 $(foreach lib,$(shared_LIBRARIES),$(eval $(call SOLIB_template,$(lib))))
index 744bd9a91fd30c9f3c835b7d79b82518b458b391..0d236e716ba231aa4810f717f98f19f7f0c905a2 100755 (executable)
@@ -20,12 +20,17 @@ test_SOURCES = test.c
 EOF
 }
 
-grepout() {
+grepbinout() {
     if [ $OMK_RULES = linux ]; then
        # The following should work only with Linux rules
-       _compiled/bin/test|grep $@
+       local bin=$1
+       shift
+       _compiled/bin/$bin|grep $@
     fi
 }
+grepout() {
+    grepbinout test $@
+}
 
 set -o pipefail
 
@@ -46,3 +51,37 @@ create_files
 echo "AM_CFLAGS=-DNUMBER=123" > config.omk
 WVPASS make
 WVPASS grepout 123
+
+WVSTART "Target specific CFLAGS"
+create_files
+cat > 'Makefile.omk' <<'EOF'
+bin_PROGRAMS = test
+test_SOURCES = test.c
+test_CFLAGS = -DNUMBER=123
+EOF
+WVPASS make V=1
+WVPASS grepout 123
+
+WVSTART "Target specific CFLAGS override AM_CFLAGS"
+create_files
+cat > 'Makefile.omk' <<'EOF'
+bin_PROGRAMS = test
+test_SOURCES = test.c
+test_CFLAGS = -DNUMBER=123
+AM_CFLAGS   = -DNUMBER=456
+EOF
+WVPASS make V=1
+WVPASS grepout 123
+
+WVSTART "Same source compiled twice with different CFLAGS"
+create_files
+cat > 'Makefile.omk' <<'EOF'
+bin_PROGRAMS = a b
+a_SOURCES = test.c
+a_CFLAGS = -DNUMBER=123
+b_SOURCES = test.c
+b_CFLAGS = -DNUMBER=456
+EOF
+WVPASS make V=1
+WVPASS grepbinout a 123
+WVPASS grepbinout b 456