commit 5d715331ae4a05f87ade9e3a6101b7dbba6ed20a
parent ea7befd1da2e9bc717dac1fdb113fedb424a8af8
Author: Vincent Forest <vincent.forest@meso-star.com>
Date: Thu, 19 Oct 2023 10:17:03 +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, 13 insertions(+), 2 deletions(-)
diff --git a/Makefile b/Makefile
@@ -42,10 +42,14 @@ $(OBJ) $(DEP): config.mk
$(LIBNAME_SHARED): $(OBJ)
$(CC) $(CFLAGS) $(DPDC_CFLAGS) -o $@ $(OBJ) $(LDFLAGS) $(SOFLAGS) $(DPDC_LIBS)
-$(LIBNAME_STATIC): $(OBJ)
+$(LIBNAME_STATIC): libs3daw.o
$(AR) -rc $@ $?
$(RANLIB) $@
+libs3daw.o: $(OBJ)
+ $(LD) -r $(OBJ) -o $@
+ $(OBJCOPY) $(OCPFLAGS) $@
+
.config: config.mk
@if ! $(PKG_CONFIG) --atleast-version $(AW_VERSION) aw; then\
echo "aw $(AW_VERSION) not found" >&2; exit 1; fi
@@ -108,7 +112,8 @@ uninstall:
all: build_library build_tests
clean: clean_test
- rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME) .config .test s3daw.pc s3daw-local.pc
+ rm -f $(OBJ) $(TEST_OBJ) $(LIBNAME)
+ rm -f .config .test libs3daw.o s3daw.pc s3daw-local.pc
distclean: clean
rm -f $(DEP) $(TEST_DEP)
diff --git a/config.mk b/config.mk
@@ -12,6 +12,8 @@ BUILD_TYPE = RELEASE
################################################################################
AR = ar
CC = cc
+LD = ld
+OBJCOPY = objcopy
PKG_CONFIG = pkg-config
RANLIB = ranlib
@@ -73,3 +75,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))