From bcf77ea1c8d27af00d0ffd92497db2ab04f4cf99 Mon Sep 17 00:00:00 2001 From: RafalGoslawski Date: Tue, 19 May 2015 13:51:36 +0200 Subject: [PATCH] Add soname and release build traget, default make target is debug --- Makefile | 19 ++++++++++++++----- src/Makefile | 19 +++++++++++++------ 2 files changed, 27 insertions(+), 11 deletions(-) diff --git a/Makefile b/Makefile index 40b86bb0..63b601ad 100644 --- a/Makefile +++ b/Makefile @@ -1,10 +1,16 @@ PREFIX = /usr INCLUDE_DIR = ${PREFIX}/include LIBRARY_DIR = ${PREFIX}/lib +export LIBRARY_NAME = amqpcpp +export SONAME = 2.2 +export VERSION = 2.2.0 all: $(MAKE) -C src all +release: + $(MAKE) -C src release + static: $(MAKE) -C src static @@ -15,9 +21,12 @@ clean: $(MAKE) -C src clean install: - mkdir -p ${INCLUDE_DIR}/amqpcpp + mkdir -p ${INCLUDE_DIR}/$(LIBRARY_NAME) mkdir -p ${LIBRARY_DIR} - cp -f amqpcpp.h ${INCLUDE_DIR} - cp -f include/*.h ${INCLUDE_DIR}/amqpcpp - cp -f src/libamqpcpp.so ${LIBRARY_DIR} - cp -f src/libamqpcpp.a ${LIBRARY_DIR} + cp -f $(LIBRARY_NAME).h ${INCLUDE_DIR} + cp -f include/*.h ${INCLUDE_DIR}/$(LIBRARY_NAME) + cp -f src/lib$(LIBRARY_NAME).so.$(VERSION) ${LIBRARY_DIR} + cp -f src/lib$(LIBRARY_NAME).a.$(VERSION) ${LIBRARY_DIR} + ln -s -f $(LIBRARY_DIR)/lib$(LIBRARY_NAME).so.$(VERSION) $(LIBRARY_DIR)/lib$(LIBRARY_NAME).so.$(SONAME) + ln -s -f $(LIBRARY_DIR)/lib$(LIBRARY_NAME).so.$(VERSION) $(LIBRARY_DIR)/lib$(LIBRARY_NAME).so + ln -s -f $(LIBRARY_DIR)/lib$(LIBRARY_NAME).a.$(VERSION) $(LIBRARY_DIR)/lib$(LIBRARY_NAME).a diff --git a/src/Makefile b/src/Makefile index c9330b93..6fa021c0 100644 --- a/src/Makefile +++ b/src/Makefile @@ -1,22 +1,29 @@ CPP = g++ RM = rm -f -CPPFLAGS = -Wall -c -I. -g -std=c++11 -g +CPPFLAGS = -Wall -c -I. -flto -std=c++11 LD = g++ -LD_FLAGS = -Wall -shared -O2 -SHARED_LIB = libamqpcpp.so -STATIC_LIB = $(SHARED_LIB:%.so=%.a) +LD_FLAGS = -Wall -shared +SHARED_LIB = lib$(LIBRARY_NAME).so.$(VERSION) +STATIC_LIB = lib$(LIBRARY_NAME).a.$(VERSION) SOURCES = $(wildcard *.cpp) SHARED_OBJECTS = $(SOURCES:%.cpp=%.o) STATIC_OBJECTS = $(SOURCES:%.cpp=%.s.o) + +all: CPPFLAGS += -g +all: LD_FLAGS += -g all: shared static +release: CPPFLAGS += -O2 +release: LD_FLAGS += -O2 +release: shared static + shared: ${SHARED_OBJECTS} ${SHARED_LIB} static: ${STATIC_OBJECTS} ${STATIC_LIB} ${SHARED_LIB}: ${SHARED_OBJECTS} - ${LD} ${LD_FLAGS} -o $@ ${SHARED_OBJECTS} + ${LD} ${LD_FLAGS} -Wl,-soname,lib$(LIBRARY_NAME).so.$(SONAME) -o $@ ${SHARED_OBJECTS} ${STATIC_LIB}: ${STATIC_OBJECTS} ar rcs ${STATIC_LIB} ${STATIC_OBJECTS} @@ -25,7 +32,7 @@ clean: ${RM} *.obj *~* ${SHARED_OBJECTS} ${STATIC_OBJECTS} ${SHARED_LIB} ${STATIC_LIB} ${SHARED_OBJECTS}: - ${CPP} ${CPPFLAGS} -flto -fpic -o $@ ${@:%.o=%.cpp} + ${CPP} ${CPPFLAGS} -fpic -o $@ ${@:%.o=%.cpp} ${STATIC_OBJECTS}: ${CPP} ${CPPFLAGS} -o $@ ${@:%.s.o=%.cpp}