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 Mar 26, 2022
1 parent 1b28a27 commit ae59a6c
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 76 deletions.
76 changes: 59 additions & 17 deletions Makefile.rules
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,9 @@ endif
# Finally add user provided CFLAGS
GAP_CFLAGS += $(CFLAGS)

# Expose all flags to package build systems
SYSINFO_CFLAGS = $(GAP_CFLAGS)


########################################################################
# C++ compiler flags
Expand All @@ -220,11 +223,15 @@ endif
# Finally add user provided CXXFLAGS
GAP_CXXFLAGS += $(CXXFLAGS)

# Expose all flags to package build systems
SYSINFO_CXXFLAGS = $(GAP_CXXFLAGS)


########################################################################
# Linker flags
########################################################################
GAP_LDFLAGS = $(ABI_CFLAGS)
SYSINFO_LDFLAGS = $(ABI_CFLAGS)

# Add flags for dependencies
GAP_LDFLAGS += $(GMP_LDFLAGS)
Expand All @@ -240,10 +247,12 @@ endif

# Finally add user provided flags
GAP_LDFLAGS += $(LDFLAGS)
SYSINFO_LDFLAGS += $(LDFLAGS)


# libs
GAP_LIBS =
SYSINFO_LIBS =

# Add flags for dependencies
GAP_LIBS += $(GMP_LIBS)
Expand All @@ -255,6 +264,46 @@ GAP_LIBS += $(LIBATOMIC_OPS_LIBS)

# Finally add user provided flags
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
########################################################################

# paths to gap and gac executable
SYSINFO_GAP = $(abs_builddir)/gap
SYSINFO_GAC = $(abs_builddir)/gac


########################################################################
Expand Down Expand Up @@ -529,10 +578,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 @@ -769,16 +816,6 @@ endif
#
# regenerate sysinfo.gap if necessary
#

SYSINFO_GAP = $(abs_builddir)/gap
SYSINFO_GAC = $(abs_builddir)/gac

SYSINFO_CFLAGS = $(GAP_CFLAGS)
SYSINFO_CXXFLAGS = $(GAP_CXXFLAGS)
#SYSINFO_CPPFLAGS is already initialized at this point
SYSINFO_LDFLAGS = $(GAP_LDFLAGS)
SYSINFO_LIBS = $(GAP_LIBS)

define sysinfo_gap
# This file has been generated by the GAP build system,
# DO NOT EDIT MANUALLY!
Expand Down Expand Up @@ -828,7 +865,7 @@ GAP="$(SYSINFO_GAP)"
# GAC: path to the `gac` executable (may be a shell script)
GAC="$(SYSINFO_GAC)"

# Build flags for use by `gac` resp. build systems: these correspond to
# 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_`.
GAP_CC="$(CC)"
GAP_CXX="$(CXX)"
Expand All @@ -837,6 +874,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 @@ -1436,8 +1477,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
63 changes: 19 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}"


#############################################################################
Expand Down Expand Up @@ -118,18 +103,8 @@ cxx_compile () {
##
c_link_dyn () {
mkdir -p $(dirname $1)
echo ${c_dyn_linker} ${GAP_LDFLAGS} -o $1 $2 ${c_addlibs}
output_la=${1%.so}.la
output_dir=$(dirname $1)
${c_dyn_linker} ${GAP_LDFLAGS} -o "$output_la" $2 ${c_addlibs} || exit 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 ${c_dyn_linker} -o $1 $2 ${GAP_LDFLAGS} ${c_addlibs}
${c_dyn_linker} -o $1 $2 ${GAP_LDFLAGS} ${c_addlibs} || exit 1
}


Expand Down Expand Up @@ -164,12 +139,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 @@ -189,12 +164,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 @@ -360,7 +335,7 @@ for input in ${inputs}; do
name=$(basename ${input} .o)
process_o_file $name $input;;

*.lo) # look over '.lo' source files
*.lo) # look over '.lo' source files (for backwards compatibility)
name=$(basename ${input} .lo)
process_o_file $name $input;;
esac
Expand All @@ -374,7 +349,7 @@ if [ $comp_howfar = "link" ]; then
exit 1
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 @@ -993,5 +993,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
22 changes: 8 additions & 14 deletions etc/Makefile.gappkg
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@
# read GAP's build settings
include $(GAPPATH)/sysinfo.gap

# hack to support GAP <= 4.9
ifndef GAP_KERNEL_MAJOR_VERSION
KEXT_CFLAGS += -I$(GAP_LIB_DIR)/src
KEXT_CXXFLAGS += -I$(GAP_LIB_DIR)/src
endif

# honor used supplied flags
KEXT_CFLAGS += $(CPPFLAGS)
KEXT_CFLAGS += $(CFLAGS)
Expand Down Expand Up @@ -74,12 +68,12 @@ all: $(KEXT_SO)

########################################################################
# Object files
# For each file FOO.c in SOURCES, add gen/FOO.lo to KEXT_OBJS; similar
# For each file FOO.c in SOURCES, add gen/FOO.o to KEXT_OBJS; similar
# for .cc files
########################################################################
KEXT_OBJS = $(patsubst %.s,gen/%.lo, \
$(patsubst %.cc,gen/%.lo, \
$(patsubst %.c,gen/%.lo, \
KEXT_OBJS = $(patsubst %.s,gen/%.o, \
$(patsubst %.cc,gen/%.o, \
$(patsubst %.c,gen/%.o, \
$(KEXT_SOURCES))))

########################################################################
Expand All @@ -100,7 +94,7 @@ endif
########################################################################

# List of all (potential) dependency files, derived from KEXT_OBJS
KEXT_DEPFILES = $(patsubst %.lo,%.d,$(KEXT_OBJS))
KEXT_DEPFILES = $(patsubst %.o,%.d,$(KEXT_OBJS))

# Include the dependency tracking files
-include $(KEXT_DEPFILES)
Expand All @@ -117,19 +111,19 @@ KEXT_DEPFLAGS = -MQ "$@" -MMD -MP -MF $(@D)/$(*F).d

# build rule for C code
# The dependency on Makefile ensures that re-running configure recompiles everything
gen/%.lo: %.c Makefile
gen/%.o: %.c Makefile
@mkdir -p $(@D)
$(QUIET_GAC)$(GAC) -d -p "$(KEXT_DEPFLAGS)" -p "$(KEXT_CFLAGS)" -c $< -o $@

# build rule for C++ code
# The dependency on Makefile ensures that re-running configure recompiles everything
gen/%.lo: %.cc Makefile
gen/%.o: %.cc Makefile
@mkdir -p $(@D)
$(QUIET_GAC)$(GAC) -d -p "$(KEXT_DEPFLAGS)" -p "$(KEXT_CXXFLAGS)" -c $< -o $@

# build rule for assembler code
# The dependency on Makefile ensures that re-running configure recompiles everything
gen/%.lo: %.s Makefile
gen/%.o: %.s Makefile
@mkdir -p $(@D)
$(QUIET_GAC)$(GAC) -d -p "$(KEXT_DEPFLAGS)" -p "$(KEXT_CFLAGS)" -c $< -o $@

Expand Down

0 comments on commit ae59a6c

Please sign in to comment.