From 9f34b969c61ea0105811f91e005e79a9fce18639 Mon Sep 17 00:00:00 2001 From: Andrea Zoli <zoli@iasfbo.inaf.it> Date: Fri, 5 Sep 2014 11:15:13 +0200 Subject: [PATCH] Use conditional assignment for CXX, CFLAGS and LINK in Makefiles. --- Makefile | 10 ++++------ Makefile.dist | 22 ++++++++++------------ examples/Makefile | 21 +++++++++------------ 3 files changed, 23 insertions(+), 30 deletions(-) diff --git a/Makefile b/Makefile index aa5c0da..24316b0 100644 --- a/Makefile +++ b/Makefile @@ -56,11 +56,9 @@ LIB_DESTDIR = lib ####### 4) Compiler, tools and options -CXX = g++ +CXX ?= g++ #Insert the optional parameter to the compiler. The CFLAGS could be changed externally by the user -#- g3 -CFLAGS = -O2 -fPIC -g -#-O2 -O0 -g3 +CFLAGS ?= -O2 -fPIC #Set INCPATH to add the inclusion paths INCPATH = -I ./include #Insert the implicit parameter to the compiler: @@ -69,7 +67,7 @@ ifeq ($(SYSTEM), QNX) ALL_CFLAGS += -Vgcc_ntox86_gpp -lang-c++ endif #Use CPPFLAGS for the preprocessor -CPPFLAGS = +CPPFLAGS ?= #Set LIBS for addition library LIBS = -lstdc++ ifeq ($(SYSTEM), QNX) @@ -81,7 +79,7 @@ ifneq (, $(findstring apple, $(SYSTEM))) LIBS += -L$(LOCAL)/lib endif -LINK = g++ +LINK ?= $(CXX) #for link LFLAGS = -shared -Wl,-soname,$(TARGET1) -Wl,-rpath,$(DESTDIR) AR = ar cqs diff --git a/Makefile.dist b/Makefile.dist index 707c75a..757e392 100644 --- a/Makefile.dist +++ b/Makefile.dist @@ -41,12 +41,10 @@ VER_FILE_NAME = PlVersion.h ####### 4) Compiler, tools and options -CC = gcc -CXX = g++ +CC ?= gcc +CXX ?= g++ #Insert the optional parameter to the compiler. The CFLAGS could be changed externally by the user -#- g3 -CFLAGS = -O2 -O0 -#-O2 -O0 -g3 +CFLAGS ?= -O2 #Set INCPATH to add the inclusion paths INCPATH = -I $(includedir) #Insert the implicit parameter to the compiler: @@ -55,13 +53,13 @@ ifeq ($(SYSTEM), QNX) ALL_CFLAGS += -Vgcc_ntox86_gpp -lang-c++ endif #Use CPPFLAGS for the preprocessor -CPPFLAGS = +CPPFLAGS = #Set LIBS for addition library LIBS = -lstdc++ -lpacket ifeq ($(SYSTEM), QNX) LIBS += -lsocket endif -LINK = g++ +LINK ?= $(CXX) #for link LFLAGS = -shared -Wl,-soname,$(TARGET1) -Wl,-rpath,$(DESTDIR) AR = ar cqs @@ -104,15 +102,15 @@ $(shell cut $(INCLUDE_DIR)/$(VER_FILE_NAME) -f 3 > version) ####### 9) Pattern rules %.o : %.cpp - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -c $< -o $(OBJECTS_DIR)/$@ + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -c $< -o $(OBJECTS_DIR)/$@ ####### 10) Build rules all: makeobjdir $(OBJECTS) - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/in $(OBJECTS_DIR)/in.o $(LIBS) - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/out $(OBJECTS_DIR)/out.o $(LIBS) - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqclient $(OBJECTS_DIR)/msgqclient.o $(LIBS) - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqserver $(OBJECTS_DIR)/msgqserver.o $(LIBS) + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/in $(OBJECTS_DIR)/in.o $(LIBS) + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/out $(OBJECTS_DIR)/out.o $(LIBS) + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqclient $(OBJECTS_DIR)/msgqclient.o $(LIBS) + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqserver $(OBJECTS_DIR)/msgqserver.o $(LIBS) makeobjdir: test -d $(OBJECTS_DIR) || mkdir -p $(OBJECTS_DIR) diff --git a/examples/Makefile b/examples/Makefile index 707c75a..e04c122 100644 --- a/examples/Makefile +++ b/examples/Makefile @@ -41,12 +41,9 @@ VER_FILE_NAME = PlVersion.h ####### 4) Compiler, tools and options -CC = gcc -CXX = g++ +CXX ?= g++ #Insert the optional parameter to the compiler. The CFLAGS could be changed externally by the user -#- g3 -CFLAGS = -O2 -O0 -#-O2 -O0 -g3 +CFLAGS ?= -O2 #Set INCPATH to add the inclusion paths INCPATH = -I $(includedir) #Insert the implicit parameter to the compiler: @@ -55,13 +52,13 @@ ifeq ($(SYSTEM), QNX) ALL_CFLAGS += -Vgcc_ntox86_gpp -lang-c++ endif #Use CPPFLAGS for the preprocessor -CPPFLAGS = +CPPFLAGS ?= #Set LIBS for addition library LIBS = -lstdc++ -lpacket ifeq ($(SYSTEM), QNX) LIBS += -lsocket endif -LINK = g++ +LINK ?= $(CXX) #for link LFLAGS = -shared -Wl,-soname,$(TARGET1) -Wl,-rpath,$(DESTDIR) AR = ar cqs @@ -104,15 +101,15 @@ $(shell cut $(INCLUDE_DIR)/$(VER_FILE_NAME) -f 3 > version) ####### 9) Pattern rules %.o : %.cpp - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -c $< -o $(OBJECTS_DIR)/$@ + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -c $< -o $(OBJECTS_DIR)/$@ ####### 10) Build rules all: makeobjdir $(OBJECTS) - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/in $(OBJECTS_DIR)/in.o $(LIBS) - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/out $(OBJECTS_DIR)/out.o $(LIBS) - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqclient $(OBJECTS_DIR)/msgqclient.o $(LIBS) - $(CC) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqserver $(OBJECTS_DIR)/msgqserver.o $(LIBS) + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/in $(OBJECTS_DIR)/in.o $(LIBS) + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/out $(OBJECTS_DIR)/out.o $(LIBS) + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqclient $(OBJECTS_DIR)/msgqclient.o $(LIBS) + $(CXX) $(CPPFLAGS) $(ALL_CFLAGS) -o $(SOURCE_DIR)/msgqserver $(OBJECTS_DIR)/msgqserver.o $(LIBS) makeobjdir: test -d $(OBJECTS_DIR) || mkdir -p $(OBJECTS_DIR) -- GitLab