Skip to content

Commit

Permalink
buildsys: always link gap against libgap
Browse files Browse the repository at this point in the history
... 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).
  • Loading branch information
fingolfin committed Aug 28, 2024
1 parent 1be1120 commit 7ccddc9
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -308,10 +308,13 @@ ifneq (,$(findstring cygwin,$(host_os)))
else
ifneq (,$(findstring darwin,$(host_os)))
GAC_CFLAGS = -fno-common
GAC_LDFLAGS = -bundle -flat_namespace -bundle_loader $(SYSINFO_GAP)
GAC_LDFLAGS = -bundle -L$(abs_builddir) -lgap
GAC_LDFLAGS_FOR_INSTALL = -bundle -L$(libdir) -lgap

else
GAC_CFLAGS = -fPIC
GAC_LDFLAGS = -shared -fPIC
GAC_LDFLAGS_FOR_INSTALL = -shared -fPIC
endif
endif

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

bin/$(GAPARCH)/gap.dll: libgap.dll
bin/$(GAPARCH)/gap.dll: libgap$(SHLIB_EXT)
@$(MKDIR_P) bin/$(GAPARCH)
cp $< $@

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

else
Expand All @@ -509,17 +512,17 @@ libgap$(SHLIB_EXT): $(LIBGAP_FULL)
ln -sf $< $@

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

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

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

endif
Expand Down Expand Up @@ -673,6 +676,7 @@ install-sysinfo: SYSINFO_CPPFLAGS = -I${includedir}/gap -I${includedir} $(GAP_DE
install-sysinfo: SYSINFO_LDFLAGS = $(ABI_CFLAGS)
install-sysinfo: SYSINFO_GAP = $(bindir)/gap
install-sysinfo: SYSINFO_GAC = $(bindir)/gac
install-sysinfo: GAC_LDFLAGS = $(GAC_LDFLAGS_FOR_INSTALL)
install-sysinfo: GMP_PREFIX =
install-sysinfo:
$(INSTALL) -d -m 0755 $(DESTDIR)$(libdir)/gap
Expand Down

0 comments on commit 7ccddc9

Please sign in to comment.