commit cbac8abcdce70f21ad3b2ad091aa5199621bb278
parent 4e73ff38e2eb0e0ca1352406e5b8d1746e7dbab1
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Wed, 18 Oct 2023 14:18:36 +0200
Partially link static library object files
Make hidden symbols local to the relocatable object to avoid conflicts
with internal symbols in another static library. In release mode, delete
all symbols not required for relocation processing, but keep them in
debug mode.
Diffstat:
2 files changed, 26 insertions(+), 17 deletions(-)
diff --git a/Makefile b/Makefile
@@ -42,10 +42,14 @@ $(DEP) $(OBJ): config.mk
$(LIBNAME_SHARED): $(OBJ)
$(CC) $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(DPDC_LIBS)
-$(LIBNAME_STATIC): $(OBJ)
+$(LIBNAME_STATIC): libpolygon.o
$(AR) -rc $@ $?
$(RANLIB) $@
+libpolygon.o: $(OBJ)
+ $(LD) -r $(OBJ) -o $@
+ $(OBJCOPY) $(OCPFLAGS) $@
+
.config: Makefile config.mk
@if ! $(PKG_CONFIG) --atleast-version $(RSYS_VERSION) rsys; then \
echo "rsys $(RSYS_VERSION) not found"; exit 1; fi
@@ -62,26 +66,24 @@ $(LIBNAME_STATIC): $(OBJ)
# Installation
################################################################################
pkg:
- @echo "Setup polygon.pc"
- @sed -e 's#@PREFIX@#$(PREFIX)#g' \
- -e 's#@VERSION@#$(VERSION)#g' \
- -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
- polygon.pc.in > polygon.pc
+ sed -e 's#@PREFIX@#$(PREFIX)#g' \
+ -e 's#@VERSION@#$(VERSION)#g' \
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g' \
+ polygon.pc.in > polygon.pc
polygon-local.pc: polygon.pc.in
- @sed -e '1d'\
- -e 's#^includedir=.*#includedir=./src/#'\
- -e 's#^libdir=.*#libdir=./#'\
- -e 's#@VERSION@#$(VERSION)#g'\
- -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
- polygon.pc.in > $@
+ sed -e '1d'\
+ -e 's#^includedir=.*#includedir=./src/#'\
+ -e 's#^libdir=.*#libdir=./#'\
+ -e 's#@VERSION@#$(VERSION)#g'\
+ -e 's#@RSYS_VERSION@#$(RSYS_VERSION)#g'\
+ polygon.pc.in > $@
install: build_library pkg
@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib" $(LIBNAME)
@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/lib/pkgconfig" polygon.pc
@$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/include" src/polygon.h
- @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/polygon"\
- COPYING README.md
+ @$(SHELL) make.sh install "$(DESTDIR)$(PREFIX)/share/doc/polygon" COPYING README.md
uninstall:
rm -f "$(DESTDIR)$(PREFIX)/lib/$(LIBNAME)"
@@ -96,10 +98,11 @@ uninstall:
all: build_library build_tests
clean: clean_test
- @rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) .test polygon.pc polygon-local.pc .config
+ rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
+ rm -f .config .test libpolygon.o polygon.pc polygon-local.pc
distclean: clean
- @rm -f $(DEP) $(TEST_DEP)
+ rm -f $(DEP) $(TEST_DEP)
lint:
shellcheck -o all make.sh
diff --git a/config.mk b/config.mk
@@ -12,7 +12,9 @@ BUILD_TYPE = RELEASE
################################################################################
AR = ar
CC = cc
+LD = ld
PKG_CONFIG = pkg-config
+OBJCOPY = objcopy
RANLIB = ranlib
################################################################################
@@ -21,7 +23,7 @@ RANLIB = ranlib
PCFLAGS_STATIC = --static
PCFLAGS = $(PCFLAGS_$(LIB_TYPE))
-RSYS_VERSION = 0.6
+RSYS_VERSION = 0.14
RSYS_CFLAGS = $$($(PKG_CONFIG) $(PCFLAGS) --cflags rsys)
RSYS_LIBS = $$($(PKG_CONFIG) $(PCFLAGS) --libs rsys)
@@ -60,3 +62,7 @@ SOFLAGS = -shared -Wl,--no-undefined
LDFLAGS_DEBUG =
LDFLAGS_RELEASE = -s
LDFLAGS = $(LDFLAGS_$(BUILD_TYPE))
+
+OCPFLAGS_DEBUG = --localize-hidden
+OCPFLAGS_RELEASE = --localize-hidden --strip-unneeded
+OCPFLAGS = $(OCPFLAGS_$(BUILD_TYPE))