Author: Laszlo Kajan <lkajan@rostlab.org>
Description: use hardening flags from environment
Forwarded: http://lists.alioth.debian.org/pipermail/debian-med-packaging/2012-August/016975.html
--- a/cif-file/Makefile
+++ b/cif-file/Makefile
@@ -141,5 +141,5 @@ $(L_MOD_LIB): $(OBJ_FILES)
 
 # Rule for making object files
 %.o: $(SRC_DIR)/%.C
-	libtool --mode=compile $(CCC) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
+	libtool --mode=compile $(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
 
--- a/cif-file-util/Makefile
+++ b/cif-file-util/Makefile
@@ -141,5 +141,5 @@ $(L_MOD_LIB): $(OBJ_FILES)
 
 # Rule for making object files
 %.o: $(SRC_DIR)/%.C
-	libtool --mode=compile $(CCC) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
+	libtool --mode=compile $(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
 
--- a/cif-parser/Makefile
+++ b/cif-parser/Makefile
@@ -181,17 +181,17 @@ obj/%Parser.o $(SRC_DIR)/%Parser.h: $(SR
 	sh -c 'cd $(SRC_DIR); $(YACC) $(${^F:.y=_YACC_FLAGS}) ../$<'
 	mv $(^:.y=.tab.c) $(^:.y=.c)
 	mv $(^:.y=.tab.h) $(^:.y=.h)
-	libtool --mode=compile $(CC) $(CFLAGS_NONANSI) -c $(^:.y=.c) -o obj/$(*)Parser.o
+	libtool --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS_NONANSI) -c $(^:.y=.c) -o obj/$(*)Parser.o
 
 obj/%Scanner.o: $(SRC_DIR)/%Scanner.l $(OBJ_DIR)/%Parser.o $(SRC_DIR)/%Parser.h
 	$(LEX) $($(@F:.o=_LEX_FLAGS)) -t $(SRC_DIR)/$(@F:.o=.l) > $(SRC_DIR)/$(@F:.o=.c)
-	libtool --mode=compile $(CC) $(CFLAGS_NONANSI) -c $(SRC_DIR)/$(@F:.o=.c) -o $(OBJ_DIR)/$(@F)
+	libtool --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS_NONANSI) -c $(SRC_DIR)/$(@F:.o=.c) -o $(OBJ_DIR)/$(@F)
 
 
 # Rule for making other object files
 obj/%ScannerBase.o: $(SRC_DIR)/%ScannerBase.C $(SRC_DIR)/%Parser.h
-	libtool --mode=compile $(CCC) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$(@F)
+	libtool --mode=compile $(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$(@F)
 
 obj/%.o: $(SRC_DIR)/%.C
-	libtool --mode=compile $(CCC) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$(@F)
+	libtool --mode=compile $(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$(@F)
 
--- a/common/Makefile
+++ b/common/Makefile
@@ -153,5 +153,5 @@ $(L_MOD_LIB): $(OBJ_FILES)
 
 # Rule for making object files
 %.o: $(SRC_DIR)/%.C
-	libtool --mode=compile $(CCC) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
+	libtool --mode=compile $(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
 
--- a/dict-obj-file/Makefile
+++ b/dict-obj-file/Makefile
@@ -142,7 +142,7 @@ clean: clean_build clean_test
 
 # Rule for making executables
 %: $(OBJ_DIR)/%.o $(M_MOD_LIB) $(ALL_DEP_LIBS)
-	$(CCC) $(LDFLAGS) $< $(M_MOD_LIB) $(ALL_DEP_LIBS) $(MALLOCLIB) -lm -o $(L_BIN_DIR)/$@
+	$(CCC) $(CPPFLAGS) $(LDFLAGS) $< $(M_MOD_LIB) $(ALL_DEP_LIBS) $(MALLOCLIB) -lm -o $(L_BIN_DIR)/$@
 	@cp -f $(L_BIN_DIR)/$@ $(M_BIN_DIR)/$@
 
 
@@ -203,10 +203,10 @@ $(L_MOD_LIB): $(OBJ_OTHER_FILES)
 
 # Rule for making object files
 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.C
-	$(CCC) $(C++FLAGS) -c $< -o $@
+	$(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $@
 
 
 # Phony rule for making object files
 %.o: $(SRC_DIR)/%.C
-	libtool --mode=compile $(CCC) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
+	libtool --mode=compile $(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
 
--- a/etc/make.platform.gnu4
+++ b/etc/make.platform.gnu4
@@ -108,8 +108,8 @@ NON_ANSI_C_FLAG=
 C_WARNINGS=$(WARNINGS)
 
 # C compiler flags
-CFLAGS=$(OPT) $(ABI) $(PIC) $(ANSI_C_FLAG) $(C_WARNINGS) $(DEFINES) $(INCLUDES)
-CFLAGS_NONANSI=$(OPT) $(ABI) $(PIC) $(NON_ANSI_C_FLAG) $(DEFINES) $(INCLUDES) 
+CFLAGS_NONANSI := $(CFLAGS) $(OPT) $(ABI) $(PIC) $(NON_ANSI_C_FLAG) $(DEFINES) $(INCLUDES)
+CFLAGS += $(OPT) $(ABI) $(PIC) $(ANSI_C_FLAG) $(C_WARNINGS) $(DEFINES) $(INCLUDES)
 
 ## C++ compiler
 ## This part defines C++ compiler information
@@ -128,14 +128,14 @@ C_PLUS_WARNINGS=$(WARNINGS) $(NO_DEPRECA
 EXT=C
 
 # C++ compiler flags
-C++FLAGS=$(OPT) $(ABI) $(PIC) $(ANSI_C_PLUS_FLAG) $(C_PLUS_WARNINGS) \
+C++FLAGS= $(CXXFLAGS) $(OPT) $(ABI) $(PIC) $(ANSI_C_PLUS_FLAG) $(C_PLUS_WARNINGS) \
   $(DEFINES) $(INCLUDES)
-C++FLAGS_NONANSI=$(OPT) $(ABI) $(PIC) $(NON_ANSI_C_PLUS_FLAG) \
+C++FLAGS_NONANSI= $(CXXFLAGS) $(OPT) $(ABI) $(PIC) $(NON_ANSI_C_PLUS_FLAG) \
   $(C_PLUS_WARNINGS) $(DEFINES) $(INCLUDES)
 
 # C++FLAGS_RELAXED should be set to avoid warnings reported by third party
 # source code that is not maintained by PDB
-C++FLAGS_RELAXED=$(OPT) $(ABI) $(PIC) $(ANSI_C_PLUS_FLAG) $(NO_DEPRECATED) \
+C++FLAGS_RELAXED= $(CXXFLAGS) $(OPT) $(ABI) $(PIC) $(ANSI_C_PLUS_FLAG) $(NO_DEPRECATED) \
   $(DEFINES) $(INCLUDES)
 
 ## Fortran compiler
@@ -158,8 +158,8 @@ F77LIBS=
 STATIC_LINKING=-static
 
 # Linker flags
-LDFLAGS=$(ABI) -w $(STATIC_LINKING)
-LDFLAGS_NO_STATIC=$(ABI) -w
+LDFLAGS_NO_STATIC := $(LDFLAGS) $(ABI) -w
+LDFLAGS += $(ABI) -w $(STATIC_LINKING)
 
 # Fortran linker
 F77_LINKER=f77
--- a/pdbml-parser/Makefile
+++ b/pdbml-parser/Makefile
@@ -222,10 +222,10 @@ $(L_MOD_LIB): $(OBJ_OTHER_FILES)
 
 # General rule for making object files
 $(OBJ_DIR)/%.o: $(SRC_DIR)/%.C
-	$(CCC) $(C++FLAGS) -c $< -o $@
+	$(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $@
 
 
 # Phony rule for making object files
 %.o: $(SRC_DIR)/%.C
-	libtool --mode=compile $(CCC) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
+	libtool --mode=compile $(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
 
--- a/tables/Makefile
+++ b/tables/Makefile
@@ -138,5 +138,5 @@ $(L_MOD_LIB): $(OBJ_FILES)
 
 # Rule for making object files
 %.o: $(SRC_DIR)/%.C
-	libtool --mode=compile $(CCC) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
+	libtool --mode=compile $(CCC) $(CPPFLAGS) $(C++FLAGS) -c $< -o $(OBJ_DIR)/$@
 
--- a/wrapper/Makefile
+++ b/wrapper/Makefile
@@ -148,10 +148,10 @@ clean_build:
 $(L_MOD_LIB): $(OBJ_FILES) $(ALL_DEP_LIBS)
 #       Create module library
 
-	@cd $(OBJ_DIR); $(CCC) $(LINK_METHOD) $(EXT_LIBS_DIRS) $(OBJ_FILES) $(ALL_DEP_LIBS) $(EXT_LIBS) $(SYS_LIBS) -o ../$@
+	@cd $(OBJ_DIR); $(CCC) $(CPPFLAGS) $(LINK_METHOD) $(EXT_LIBS_DIRS) $(OBJ_FILES) $(ALL_DEP_LIBS) $(EXT_LIBS) $(SYS_LIBS) -o ../$@
 
 
 # Rule for making object files
 %.o: $(SRC_DIR)/%.C
-	$(CCC) $(C++FLAGS) $(EXT_COMP_OPT) -c $< -o $(OBJ_DIR)/$@
+	$(CCC) $(CPPFLAGS) $(C++FLAGS) $(EXT_COMP_OPT) -c $< -o $(OBJ_DIR)/$@
 
--- a/regex/Makefile
+++ b/regex/Makefile
@@ -152,7 +152,7 @@ $(L_MOD_LIB): $(OBJ_FILES)
 
 # Rule for making object files
 %.o: $(SRC_DIR)/%.c
-	libtool --mode=compile $(CC) $(CFLAGS_NONANSI) -DPOSIX_MISTAKE -c $< -o $(OBJ_DIR)/$@
+	libtool --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS_NONANSI) -DPOSIX_MISTAKE -c $< -o $(OBJ_DIR)/$@
 
 
 # Extra, non-used in PDB build
@@ -180,18 +180,18 @@ TARGET   = $(L_BIN_DIR)/re
 
 
 $(OBJ_DIR)/main.o: $(H) $(HEADER_FILES) $(SRC_DIR)/main.c $(L_INCL_DIR)/main.ih
-	$(CC) $(CFLAGS_NONANSI) -DPOSIX_MISTAKE -c $(SRC_DIR)/main.c -o $@
+	$(CC) $(CPPFLAGS) $(CFLAGS_NONANSI) -DPOSIX_MISTAKE -c $(SRC_DIR)/main.c -o $@
 
 $(OBJ_DIR)/split.o: $(H) $(HEADER_FILES) $(SRC_DIR)/split.c 
-	libtool --mode=compile $(CC) $(CFLAGS_NONANSI) -DPOSIX_MISTAKE -c $(SRC_DIR)/split.c -o $@
+	libtool --mode=compile $(CC) $(CPPFLAGS) $(CFLAGS_NONANSI) -DPOSIX_MISTAKE -c $(SRC_DIR)/split.c -o $@
 
 debug.o: $(H) $(HEADER_FILES) $(SRC_DIR)/debug.c $(L_INCL_DIR)/debug.ih
-	$(CC) $(CFLAGS_NONANSI) -DPOSIX_MISTAKE -c $(SRC_DIR)/debug.c -o $(OBJ_DIR)/$@
+	$(CC) $(CPPFLAGS) $(CFLAGS_NONANSI) -DPOSIX_MISTAKE -c $(SRC_DIR)/debug.c -o $(OBJ_DIR)/$@
 
 
 # tester
 $(TARGET): $(ALLOBJS)
-	$(CC) $(CFLAGS) -DPOSIX_MISTAKE $(LDFLAGS) $(ALLOBJS) $(LIBS) -o $@
+	$(CC) $(CPPFLAGS) $(CFLAGS) -DPOSIX_MISTAKE $(LDFLAGS) $(ALLOBJS) $(LIBS) -o $@
 
 
 # regression test
