Skip to content

Commit 7ccddc9

Browse files
committed
buildsys: always link gap against libgap
... even the copy we don't install system wide. On macOS this allows us an annoying issue with the linker flags used by e.g. gac for building kernel extensions: by always linking them against libgap we don't need to use a flat namespace, nor rely on a bundle loader (which breaks if you try to load the kernel extension in another binary using libgap).
1 parent 1be1120 commit 7ccddc9

File tree

1 file changed

+12
-8
lines changed

1 file changed

+12
-8
lines changed

Makefile.rules

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -308,10 +308,13 @@ ifneq (,$(findstring cygwin,$(host_os)))
308308
else
309309
ifneq (,$(findstring darwin,$(host_os)))
310310
GAC_CFLAGS = -fno-common
311-
GAC_LDFLAGS = -bundle -flat_namespace -bundle_loader $(SYSINFO_GAP)
311+
GAC_LDFLAGS = -bundle -L$(abs_builddir) -lgap
312+
GAC_LDFLAGS_FOR_INSTALL = -bundle -L$(libdir) -lgap
313+
312314
else
313315
GAC_CFLAGS = -fPIC
314316
GAC_LDFLAGS = -shared -fPIC
317+
GAC_LDFLAGS_FOR_INSTALL = -shared -fPIC
315318
endif
316319
endif
317320

@@ -492,13 +495,13 @@ GAP_LDFLAGS += -Wl,--allow-multiple-definition
492495
# loads that DLL and calls the renamed main function.
493496
all: bin/$(GAPARCH)/gap.dll
494497

495-
bin/$(GAPARCH)/gap.dll: libgap.dll
498+
bin/$(GAPARCH)/gap.dll: libgap$(SHLIB_EXT)
496499
@$(MKDIR_P) bin/$(GAPARCH)
497500
cp $< $@
498501

499502
# build rule for the main gap executable
500-
gap$(EXEEXT): libgap.dll cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS build/obj/src/main.c.o
501-
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) -Wl,--export-all-symbols build/obj/src/main.c.o $(GAP_LIBS) -L${abs_builddir} -lgap -o $@
503+
gap$(EXEEXT): build/obj/src/main.c.o libgap$(SHLIB_EXT) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS
504+
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) -Wl,--export-all-symbols $< $(GAP_LIBS) -L${abs_builddir} -lgap -o $@
502505
@( if which peflags > /dev/null ; then peflags --cygwin-heap=2048 gap$(EXEEXT) ; fi )
503506

504507
else
@@ -509,17 +512,17 @@ libgap$(SHLIB_EXT): $(LIBGAP_FULL)
509512
ln -sf $< $@
510513

511514
# build rule for the main gap executable
512-
gap$(EXEEXT): $(OBJS) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS build/obj/src/main.c.o
513-
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) build/obj/src/main.c.o $(OBJS) $(GAP_LIBS) -o $@
515+
gap$(EXEEXT): build/obj/src/main.c.o libgap$(SHLIB_EXT) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS
516+
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) $< $(GAP_LIBS) -L${abs_builddir} -lgap -o $@
514517

515518
# generate a modified copy of main.c for use by the `gap-install` binary
516519
build/main.c: src/main.c
517520
@echo "#define SYS_DEFAULT_PATHS \"$(libdir)/gap;$(datarootdir)/gap\"" > $@
518521
@cat $< >> $@
519522

520523
# build rule for the gap executable used by the `install-bin` target
521-
build/gap-install: libgap$(SHLIB_EXT) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS build/obj/build/main.c.o
522-
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) build/obj/build/main.c.o $(GAP_LIBS) -L${abs_builddir} -lgap -o $@
524+
build/gap-install: build/obj/build/main.c.o libgap$(SHLIB_EXT) cnf/GAP-LDFLAGS cnf/GAP-LIBS cnf/GAP-OBJS
525+
$(QUIET_LINK)$(LINK) $(GAP_LDFLAGS) $< $(GAP_LIBS) -L${abs_builddir} -lgap -o $@
523526
$(INSTALL_NAME_TOOL) -change $(LIBGAP_FULL) $(libdir)/$(LIBGAP_FULL) $@
524527

525528
endif
@@ -673,6 +676,7 @@ install-sysinfo: SYSINFO_CPPFLAGS = -I${includedir}/gap -I${includedir} $(GAP_DE
673676
install-sysinfo: SYSINFO_LDFLAGS = $(ABI_CFLAGS)
674677
install-sysinfo: SYSINFO_GAP = $(bindir)/gap
675678
install-sysinfo: SYSINFO_GAC = $(bindir)/gac
679+
install-sysinfo: GAC_LDFLAGS = $(GAC_LDFLAGS_FOR_INSTALL)
676680
install-sysinfo: GMP_PREFIX =
677681
install-sysinfo:
678682
$(INSTALL) -d -m 0755 $(DESTDIR)$(libdir)/gap

0 commit comments

Comments
 (0)