From 50bc16079f48cbffdacf5c07c99e12a1ff5aebdb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Gr=C3=A9gory=20Soutad=C3=A9?= Date: Sat, 14 Jan 2023 12:56:06 +0100 Subject: [PATCH] Fix static build --- Makefile | 20 ++++++++++++-------- utils/Makefile | 10 +++++----- 2 files changed, 17 insertions(+), 13 deletions(-) diff --git a/Makefile b/Makefile index 61a54a9..ceaf392 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ endif UPDFPARSERLIB = ./lib/updfparser/libupdfparser.a CXXFLAGS += -Wall -fPIC -I./include -I./usr/include/pugixml -I./lib/updfparser/include -LDFLAGS = $(UPDFPARSERLIB) -lpugixml +LDFLAGS = -lpugixml VERSION := $(shell cat include/libgourou.h |grep LIBGOUROU_VERSION|cut -d '"' -f2) @@ -21,9 +21,13 @@ BUILD_UTILS ?= 1 TARGETS = TARGET_LIBRARIES = +ifneq ($(STATIC_UTILS),) + BUILD_STATIC=1 +endif ifneq ($(BUILD_STATIC), 0) TARGETS += libgourou.a TARGET_LIBRARIES += libgourou.a + STATIC_UTILS=1 endif ifneq ($(BUILD_SHARED), 0) TARGETS += libgourou.so @@ -70,25 +74,25 @@ obj: $(BUILDDIR)/%.$(OBJEXT): $(SRCDIR)/%.$(SRCEXT) $(CXX) $(CXXFLAGS) -c $^ -o $@ -libgourou: libgourou.a libgourou.so +libgourou: $(TARGET_LIBRARIES) libgourou.a: $(OBJECTS) $(UPDFPARSERLIB) - $(AR) crs $@ obj/*.o $(UPDFPARSERLIB) + $(AR) rcs --thin $@ $^ libgourou.so.$(VERSION): $(OBJECTS) $(UPDFPARSERLIB) - $(CXX) obj/*.o -Wl,-soname,$@ $(LDFLAGS) -o $@ -shared + $(CXX) $^ -Wl,-soname,$@ $(LDFLAGS) -o $@ -shared libgourou.so: libgourou.so.$(VERSION) ln -f -s $^ $@ build_utils: $(TARGET_LIBRARIES) - make -C utils ROOT=$(PWD) CXX=$(CXX) AR=$(AR) DEBUG=$(DEBUG) STATIC_UTILS=$(STATIC_UTILS) DEST_DIR=$(DEST_DIR) PREFIX=$(PREFIX) + $(MAKE) -C utils ROOT=$(PWD) CXX=$(CXX) AR=$(AR) DEBUG=$(DEBUG) STATIC_UTILS=$(STATIC_UTILS) DEST_DIR=$(DEST_DIR) PREFIX=$(PREFIX) install: $(TARGET_LIBRARIES) install -d $(DESTDIR)$(PREFIX)$(LIBDIR) # Use cp to preserver symlinks cp --no-dereference $(TARGET_LIBRARIES) $(DESTDIR)$(PREFIX)$(LIBDIR) - make -C utils ROOT=$(PWD) CXX=$(CXX) AR=$(AR) DEBUG=$(DEBUG) STATIC_UTILS=$(STATIC_UTILS) DEST_DIR=$(DEST_DIR) PREFIX=$(PREFIX) install + $(MAKE) -C utils ROOT=$(PWD) CXX=$(CXX) AR=$(AR) DEBUG=$(DEBUG) STATIC_UTILS=$(STATIC_UTILS) DEST_DIR=$(DEST_DIR) PREFIX=$(PREFIX) install uninstall: cd $(DESTDIR)$(PREFIX)/$(LIBDIR) @@ -104,8 +108,8 @@ uninstall_headers: clean: rm -rf libgourou.a libgourou.so libgourou.so.$(VERSION)* obj - make -C utils clean + $(MAKE) -C utils clean ultraclean: clean rm -rf lib - make -C utils ultraclean + $(MAKE) -C utils ultraclean diff --git a/utils/Makefile b/utils/Makefile index e7d0ae5..687ce1d 100644 --- a/utils/Makefile +++ b/utils/Makefile @@ -30,12 +30,12 @@ COMMON_LIB = utils.a all: $(TARGETS) -${COMMON_LIB}: ${COMMON_DEPS} ${STATIC_DEP} - $(CXX) $(CXXFLAGS) ${COMMON_DEPS} $(LDFLAGS) -c - $(AR) crs $@ ${COMMON_OBJECTS} $(STATIC_DEP) +${COMMON_LIB}: $(COMMON_DEPS) + $(CXX) $(CXXFLAGS) $(COMMON_DEPS) $(LDFLAGS) -c + $(AR) crs $@ $(COMMON_OBJECTS) -%: %.cpp ${COMMON_LIB} - $(CXX) $(CXXFLAGS) $^ $(LDFLAGS) -o $@ +%: %.cpp $(COMMON_LIB) $(STATIC_DEP) + $(CXX) $(CXXFLAGS) $^ $(STATIC_DEP) $(LDFLAGS) -o $@ install: $(TARGET_BINARIES) install -d $(DESTDIR)$(PREFIX)/$(BINDIR)