Skip to content

Commit

Permalink
buildsys: change gac to not use libtool
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Jul 8, 2022
1 parent a03ede4 commit d95730b
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 52 deletions.
47 changes: 40 additions & 7 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,36 @@ GAP_LIBS += $(LIBS)
SYSINFO_LIBS += $(LIBS)


########################################################################
# gac flags
########################################################################

#
# Determine flags for building kernel extensions for use in GAC
#
# For now we basically support GCC and clang, on Linux/macOS/Windows,
# and as a side effect also some other systems such as FreeBSD.
# Support for other compilers or operating systems will require some
# extra tweaks.
#
ifneq (,$(findstring cygwin,$(host_os)))
GAC_CFLAGS =
GAC_LDFLAGS = -shared -Wl,$(abs_builddir)/bin/$(GAPARCH)/gap.dll
# Note: the above won't be correct after "make install"; but then I am not
# sure we care about "make install" on Cygwin, so I am not going to work on
# this until someone specifically asks for it (and even then I'll require
# that person to help test it)
else
ifneq (,$(findstring darwin,$(host_os)))
GAC_CFLAGS = -fno-common
GAC_LDFLAGS = -bundle -bundle_loader $(SYSINFO_GAP)
else
GAC_CFLAGS = -fPIC
GAC_LDFLAGS = -shared
endif
endif


########################################################################
# additional settings for use in sysinfo.gap
########################################################################
Expand Down Expand Up @@ -559,10 +589,8 @@ install-bin: gap
echo "$$gap_wrapper" > $(DESTDIR)$(bindir)/gap
chmod 0755 $(DESTDIR)$(bindir)/gap

# TODO: make gac installable; this requires adjusting path in it, and
# installing the libtool script generated by configure somewhere; and then
# putting that path to it into gac)
#$(INSTALL) gac $(DESTDIR)$(bindir)
sed -e "s;@SYSINFO_GAPROOT@;$(libdir)/gap;" < $(srcdir)/cnf/gac.in > $(DESTDIR)$(bindir)/gac
chmod 0755 $(DESTDIR)$(bindir)/gac

install-doc:
# TODO: should this depend on the 'doc' target? but that target is phony
Expand Down Expand Up @@ -857,7 +885,7 @@ GAP="$(SYSINFO_GAP)"
GAC="$(SYSINFO_GAC)"

# File extension used by object files created by GAC
GAP_OBJEXT=lo
GAP_OBJEXT=o

# Build flags for use by `gac` resp. package build systems: these correspond to
# the usual variables as used by e.g. autotools, with the added prefix `GAP_`.
Expand All @@ -868,6 +896,10 @@ GAP_CXXFLAGS="$(SYSINFO_CXXFLAGS)"
GAP_CPPFLAGS="$(SYSINFO_CPPFLAGS)"
GAP_LDFLAGS="$(SYSINFO_LDFLAGS)"
GAP_LIBS="$(SYSINFO_LIBS)"

# Extra flags for use by `gac`
GAC_CFLAGS="$(GAC_CFLAGS)"
GAC_LDFLAGS="$(GAC_LDFLAGS)"
endef
export sysinfo_gap

Expand Down Expand Up @@ -1467,8 +1499,9 @@ doc/make_doc: $(srcdir)/doc/make_doc.in config.status
CITATION: $(srcdir)/CITATION.in config.status
@$(SHELL) ./config.status $@

gac: $(srcdir)/cnf/gac.in config.status
@$(SHELL) ./config.status $@
gac: $(srcdir)/cnf/gac.in
sed -e "s;@SYSINFO_GAPROOT@;$(abs_top_builddir);" < $< > $@
chmod a+x $@

GNUmakefile: $(srcdir)/GNUmakefile.in config.status
$(SHELL) ./config.status $@
Expand Down
69 changes: 25 additions & 44 deletions cnf/gac.in
Original file line number Diff line number Diff line change
Expand Up @@ -49,34 +49,19 @@
## -k|--gap-compiler
##

# absolute path of the directory in which GAP was compiled
abs_top_builddir="@abs_top_builddir@"

#
libdir="@libdir@"

# path to the GAP executable
gap_compiler="${abs_top_builddir}/gap"

libtool="@SHELL@ ${abs_top_builddir}/libtool"

# read sysinfo.gap, which should set GAP_CFLAGS, GAP_CPPFLAGS, etc.
. "${abs_top_builddir}/sysinfo.gap"

# These three should be filled in by the standard autoconf procedures
c_compiler="$libtool --mode=compile $GAP_CC"
cxx_compiler="$libtool --mode=compile $GAP_CXX"

# These will need special care
c_dyn_linker="$libtool --mode=link $GAP_CC -module -avoid-version -rpath $libdir"
# read sysinfo.gap, which sets GAP_CFLAGS, GAP_CPPFLAGS, etc.
. "@SYSINFO_GAPROOT@/sysinfo.gap"

# Extract sysinfo settings...
gap_compiler="${GAP}"
c_compiler="${GAP_CC}"
cxx_compiler="${GAP_CXX}"
c_dyn_linker="${GAP_CC}"
c_addlibs=""

SYS_IS_CYGWIN32=@SYS_IS_CYGWIN32@
if [ X"$SYS_IS_CYGWIN32" = X"yes" ] ; then
c_dyn_linker="$c_dyn_linker -no-undefined -version-info 0:0:0"
# FIXME: use correct DLL path (also after "make install")
c_dyn_linker="$c_dyn_linker -Wl,${abs_top_builddir}/bin/${GAParch}/gap.dll"
fi
GAP_CFLAGS="${GAP_CFLAGS} ${GAC_CFLAGS}"
GAP_CXXFLAGS="${GAP_CXXFLAGS} ${GAC_CFLAGS}"
GAP_LDFLAGS="${GAP_LDFLAGS} ${GAC_LDFLAGS}"


# is output going to a terminal?
Expand Down Expand Up @@ -161,17 +146,7 @@ cxx_compile () {
##
c_link_dyn () {
mkdir -p $(dirname $1)
echo_and_run ${c_dyn_linker} ${GAP_LDFLAGS} -o "${1%.so}.la" $2 ${c_addlibs} || exit 1

output_dir=$(dirname $1)
if [ X"$SYS_IS_CYGWIN32" = X"yes" ] ; then
# GAP assumes shared libraries end in .so
for dllfile in $(cd $output_dir/.libs; ls *.dll); do
cp $output_dir/.libs/$dllfile $output_dir/${dllfile%.dll}.so
done
else
cp $output_dir/.libs/*.so $output_dir
fi;
echo_and_run ${c_dyn_linker} -o $1 $2 ${GAP_LDFLAGS} ${c_addlibs} || exit 1
}


Expand Down Expand Up @@ -206,12 +181,12 @@ process_c_file () {
c_file=$2

if [ $comp_howfar != "object" ]; then
o_file=${gactmp}/$$_${name}.lo
o_file=${gactmp}/$$_${name}.o
temps_o="${temps_o} ${o_file}"
elif [ "X$output" != "X" ]; then
o_file=$output
else
o_file=${name}.lo
o_file=${name}.o
fi
c_compile $o_file $c_file
if [ $comp_howfar = "link" ]; then
Expand All @@ -231,12 +206,12 @@ process_cxx_file () {
cxx_file=$2

if [ $comp_howfar != "object" ]; then
o_file=${gactmp}/$$_${name}.lo
o_file=${gactmp}/$$_${name}.o
temps_o="${temps_o} ${o_file}"
elif [ "X$output" != "X" ]; then
o_file=$output
else
o_file=${name}.lo
o_file=${name}.o
fi
cxx_compile $o_file $cxx_file
if [ $comp_howfar = "link" ]; then
Expand Down Expand Up @@ -393,11 +368,17 @@ for input in ${inputs}; do
name=$(basename ${input} .s)
process_c_file $name $input;; # HACK: just use the C compiler

*.o) # look over '.o' source files
*.o) # add '.o' object files to the linker list
name=$(basename ${input} .o)
process_o_file $name $input;;

*.lo) # look over '.lo' source files
*.lo)
# for backwards compatibility, treat .lo files like .o files this
# is useful for package that use an old Makefile.gappkg which
# hardcodes the file extension .lo for object files created by
# gac. So this only works if the .lo files are honest object files
# with the wrong extension; it does *not* support linking .lo
# files created by GNU libtool.
name=$(basename ${input} .lo)
process_o_file $name $input;;
esac
Expand All @@ -410,7 +391,7 @@ if [ $comp_howfar = "link" ]; then
error "$0: static linking is not supported anymore, use -d / --dynamic"
fi

if [ "X${output}" = "X" ]; then output="${name}.la"; fi
if [ "X${output}" = "X" ]; then output="${name}.so"; fi
c_link_dyn ${output} "${objects}"

if [ "$savetemps" = "true" ]; then
Expand Down
1 change: 0 additions & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -1025,5 +1025,4 @@ AC_CONFIG_FILES([GNUmakefile])
AC_CONFIG_FILES([CITATION])
AC_CONFIG_FILES([doc/make_doc], [chmod +x doc/make_doc])
AC_CONFIG_FILES([doc/versiondata])
AC_CONFIG_FILES([gac:cnf/gac.in], [chmod +x gac])
AC_OUTPUT

0 comments on commit d95730b

Please sign in to comment.