Fix static build

This commit is contained in:
Grégory Soutadé 2023-01-14 12:56:06 +01:00
parent 1213b34250
commit 50bc16079f
2 changed files with 17 additions and 13 deletions

View File

@ -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

View File

@ -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)