Skip to content

Commit

Permalink
Further buildsystem tweaks
Browse files Browse the repository at this point in the history
  • Loading branch information
fingolfin committed Oct 4, 2019
1 parent 4e33282 commit 0402f26
Show file tree
Hide file tree
Showing 3 changed files with 88 additions and 65 deletions.
119 changes: 78 additions & 41 deletions Makefile.gappkg
Original file line number Diff line number Diff line change
@@ -1,36 +1,63 @@
########################################################################
#
# The build rules in this file based on the GAP build system. They require GNU
# make. To use them in your GAP package, please `include` them from your
# primary Makefile.
# The build rules in this file are intended for use by GAP packages that
# want to build a simple GAP kernel extensions. They are based on the
# GAP build system, and require GNU make. To use this in your GAP
# package, `include` this from your primary Makefile. You must also set
# several variables beforehand:
#
# - GAPPATH must be set to the location of the GAP installation against
# which to build your package.
# - KEXT_NAME should be the name of your kernel extension (without
# file extensions like .so or .dll)
# - KEXT_SOURCES must contain a list of .c or .cc files to be linked
# into your kernel extension
# - optionally, you can set KEXT_CFLAGS, KEXT_CXXFLAGS, KEXT_LDFLAGS
#
# Ideally, try not to edit this file, instead set the appropriate
# variables, such as MODULE_NAME, SOURCES, CFLAGS, CXXFLAGS, LDFLAGS,
# in your primary Makefile.
#
# If you still find that you must edit this file, please consider submitting
# your changes back to the GAP team.
# Only GAP >= 4.11 ships with this file. In order to keep your package
# compatible with older GAP versions, we recommend to bundle a copy of
# it with your package, but only as a fallback. So, your configure
# scripts should check if GAP ships with this file, and use it then, and
# only fall back to your own copy as a last resort. This way, you will
# benefit from any fixes and improvements made by the GAP team.
#
# The contents of this file are released into the public domain; hence
# you may edit this file as you wish, bundle and distribute it with your
# package, etc.
#
# If you bundle this file with your package, please try not to edit it,
# so that we can keep it identical across all GAP packages. If you still
# find that you must edit it, please consider submitting your changes
# back to the GAP team, so that a future version of this file can be
# adjusted to cover your usecase without modifications.
#
########################################################################

BINARCHDIR = bin/$(GAPARCH)
GAPINSTALLIB = $(BINARCHDIR)/$(MODULE_NAME).so
# read GAP's build settings
include $(GAPPATH)/sysinfo.gap

MKDIR_P = /bin/mkdir -p
# various derived settings
KEXT_BINARCHDIR = bin/$(GAParch)
KEXT_SO = $(KEXT_BINARCHDIR)/$(KEXT_NAME).so

GAP = $(GAPPATH)/gap
GAC = $(GAPPATH)/gac

all: $(GAPINSTALLIB)
# override KEXT_RECONF if your package needs a different invocation
# for reconfiguring (e.g. `./config.status --recheck` for autoconf)
KEXT_RECONF ?= ./configure "$(GAPPATH)"

# default target
all: $(KEXT_SO)
.PHONY: all

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

########################################################################
# Quiet rules.
Expand All @@ -41,7 +68,6 @@ OBJS = $(patsubst %.cc,gen/%.lo,$(patsubst %.c,gen/%.lo,$(SOURCES)))
ifneq ($(findstring $(MAKEFLAGS),s),s)
ifndef V
QUIET_GAC = @echo " GAC $< => $@";
LIBTOOL += --silent
endif
endif

Expand All @@ -50,56 +76,67 @@ endif
# This is based on the GAP build system.
########################################################################

# List of all (potential) dependency directories, derived from OBJS
# and SOURCES (the latter for generated sources, which may also involve
# dependency tracking)
DEPDIRS = $(sort $(dir $(SOURCES) $(OBJS)))
ALL_DEP_FILES = $(wildcard $(addsuffix /*.d,$(DEPDIRS)))
# List of all (potential) dependency directories, derived from KEXT_OBJS
# and KEXT_SOURCES (the latter for generated sources, which may also
# involve dependency tracking)
KEXT_DEPDIRS = $(sort $(dir $(KEXT_SOURCES) $(KEXT_OBJS)))
KEXT_DEPFILES = $(wildcard $(addsuffix /*.d,$(KEXT_DEPDIRS)))

# Include the dependency tracking files.
-include $(ALL_DEP_FILES)
-include $(KEXT_DEPFILES)

# Mark *.d files as PHONY. This stops make from trying to
# recreate them (which it can't), and in particular from looking for potential
# source files. This can save quite a bit of disk access time.
.PHONY: $(ALL_DEP_FILES)
# Mark *.d files as PHONY. This stops make from trying to recreate them
# (which it can't), and in particular from looking for potential source
# files. This can save quite a bit of disk access time.
.PHONY: $(KEXT_DEPFILES)

# The following flags instruct the compiler to enable advanced
# dependency tracking. Supported by GCC 3 and newer; clang; Intel C
# compiler; and more.
DEPFLAGS = -MQ "$@" -MMD -MP -MF $(@D)/$(*F).d
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
$(QUIET_GAC)$(GAC) -d -p "$(DEPFLAGS)" -p "$(CFLAGS)" -c $< -o $@
$(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
$(QUIET_GAC)$(GAC) -d -p "$(DEPFLAGS)" -p "$(CXXFLAGS)" -c $< -o $@
$(QUIET_GAC)$(GAC) -d -p "$(KEXT_DEPFLAGS)" -p "$(KEXT_CXXFLAGS)" -c $< -o $@

# build rule for linking all object files together into a kernel extension
$(GAPINSTALLIB): $(OBJS)
@$(MKDIR_P) $(BINARCHDIR)
$(QUIET_GAC)$(GAC) -d -p "$(DEPFLAGS)" -P "$(LDFLAGS)" $(OBJS) -o $@

clean:
rm -rf $(BINARCHDIR)
rm -rf gen

distclean:
$(KEXT_SO): $(KEXT_OBJS)
@mkdir -p $(KEXT_BINARCHDIR)
$(QUIET_GAC)$(GAC) -d -p "$(KEXT_DEPFLAGS)" -P "$(KEXT_LDFLAGS)" $(KEXT_OBJS) -o $@

# hook into `make clean`
clean: clean-kext
clean-kext:
rm -rf $(KEXT_BINARCHDIR) gen

# hook into `make distclean`
distclean: clean-kext
distclean-kext:
rm -rf bin gen Makefile
(cd doc && ./clean)

doc: default
# hook into `make doc`
doc: doc-kext
doc-kext:
$(GAP) makedoc.g

check: default
# hook into `make check`
check: check-kext
check-kext:
$(GAP) tst/testall.g

# re-run configure if configure, Makefile.in or GAP itself changed
Makefile: configure Makefile.in $(GAPPATH)/sysinfo.gap
./configure "$(GAPPATH)"
$(KEXT_RECONF)

.PHONY: default clean distclean doc check
.PHONY: check clean distclean doc
.PHONY: check-kext clean-kext distclean-kext doc-kext

########################################################################
# Makefile debugging trick:
Expand Down
20 changes: 3 additions & 17 deletions Makefile.in
Original file line number Diff line number Diff line change
@@ -1,23 +1,9 @@
#
# Makefile rules for the cvec package
#
# This requires GNU make (just as the main GAP does).
#
# For simple packages one should only need to modify the MODULE_NAME
# and the SOURCES variable.
#
MODULE_NAME = cvec

SOURCES = src/cvec.c
KEXT_NAME = cvec
KEXT_SOURCES = src/cvec.c

########################################################################
# Do not edit below unless you know what you're doing
########################################################################

########################################################################
# Some variables that come from GAP via our configure script
########################################################################
# include shared GAP package build system
GAPPATH = @GAPPATH@
GAPARCH = @GAPARCH@

include Makefile.gappkg
14 changes: 7 additions & 7 deletions configure
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ else
GAPPATH=$1;
fi

if test ! -r $GAPPATH/sysinfo.gap ; then
if test ! -r "$GAPPATH/sysinfo.gap" ; then
echo
echo "No file $GAPPATH/sysinfo.gap found."
echo
Expand All @@ -26,10 +26,10 @@ if test ! -r $GAPPATH/sysinfo.gap ; then
exit 1
fi

echo "Using config in $GAPPATH/sysinfo.gap"
echo "Using settings from $GAPPATH/sysinfo.gap"

. "$GAPPATH/sysinfo.gap"
sed \
-e "s;@GAPARCH@;$GAParch;g" \
-e "s;@GAPPATH@;$GAPPATH;g" \
Makefile.in > Makefile
# update Makefile.gappkg from GAP installation, if possible
test -r "$GAPPATH/etc/Makefile.gappkg" && cp "$GAPPATH/etc/Makefile.gappkg" .

#
sed -e "s;@GAPPATH@;$GAPPATH;g" Makefile.in > Makefile

0 comments on commit 0402f26

Please sign in to comment.