Skip to content

Commit

Permalink
refactor(build): Use more standardized macros from my other projects
Browse files Browse the repository at this point in the history
  • Loading branch information
alerque committed Apr 15, 2024
1 parent f39bb27 commit b1756d4
Show file tree
Hide file tree
Showing 25 changed files with 357 additions and 269 deletions.
2 changes: 1 addition & 1 deletion .cirrus.yml
Expand Up @@ -42,7 +42,7 @@ task:
- ./bootstrap.sh
configure_script: |
./configure MAKE=gmake \
--enable-developer LDOC=false LUAROCKS=false LUACHECK=false BUSTED=false DELTA=cat PDFINFO=false NIX=false NPM=false DOCKER=false \
--enable-developer-mode LDOC=false LUAROCKS=false LUACHECK=false BUSTED=false DELTA=cat PDFINFO=false NIX=false NPM=false DOCKER=false \
--disable-font-variations \
--with-system-lua-sources \
--with-system-luarocks \
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/coverage.yml
Expand Up @@ -60,7 +60,7 @@ jobs:
run: |
./bootstrap.sh
./configure \
--enable-developer LDOC=false LUACHECK=false NIX=false DELTA=cat \
--enable-developer-mode LDOC=false LUACHECK=false NIX=false DELTA=cat \
--disable-font-variations \
--without-manual
- name: Make
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/deploy.yml
Expand Up @@ -25,7 +25,7 @@ jobs:
run: |
echo "REF=${GITHUB_REF##refs/*/}" >> $GITHUB_ENV
./bootstrap.sh
./configure --disable-dependency-checks --enable-developer DOCKER=docker
./configure --enable-developer-mode DOCKER=docker
- name: Publish Docker Image to GH Container Registry
run: |
make docker-build-push
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Expand Up @@ -71,7 +71,7 @@ jobs:
./bootstrap.sh
./configure \
${{ matrix.luaVersion[1] }} \
--enable-developer LDOC=false LUACHECK=false NIX=false DELTA=cat \
--enable-developer-mode LDOC=false LUACHECK=false NIX=false DELTA=cat \
--disable-font-variations \
--with${{ !startsWith(matrix.luaVersion[0], 'luajit') && 'out' || '' }}-luajit \
--without-system-luarocks \
Expand Down
40 changes: 15 additions & 25 deletions Makefile.am
@@ -1,4 +1,5 @@
ACLOCAL_AMFLAGS = -I build-aux
AM_DISTCHECK_CONFIGURE_FLAGS = --enable-developer-mode

.ONESHELL:
.SECONDARY:
Expand Down Expand Up @@ -82,7 +83,16 @@ BUILT_SOURCES = $(BUILT_LUA_SOURCES) Makefile-distfiles

CLEANFILES = $(MANUAL)

include $(top_srcdir)/build-aux/rust_boilerplate.mk
DISTCLEANFILES = @AMINCLUDE@

# A classical use of the autoconf-archive include macro would expand
# INC_AMINCLUDE here, but the perl script that inlines include statements
# runs before the automake that organizes logic and performs substitution.
# Consequentially with a substitution here it becomes impossible to use
# automake conditionals and substitutions in the included Makefile fragments.
# By entering the expanded value directly we are ready in time for the inlining
# functionality and hence can use conditionals in included makefile fragments.
include $(top_srcdir)/aminclude.am

Makefile-distfiles: $(wildcard .version .tarball-version) | $(LUAMODLOCK)
$(SHELL) build-aux/list-dist-files.sh > $@
Expand Down Expand Up @@ -257,13 +267,13 @@ patterndeps = $(_FORCED) $(_TEST_DEPS) $(_DOCS_DEPS) | $(bin_PROGRAMS) $(DEPDIRS
.PHONY: force
force: ;

PHONY_DEVELOPER_TARGETS = busted compare coverage docker docker-build-push \
PHONY_DEVELOPER_TARGETS = busted compare coverage \
docker-dep-check docker-ghcr-to-hub gource.webm lint luacheck luarocks-lint \
prerelease regression_previews regressions release release-preview tagrelease \
test update_expecteds update_libtexpdf
.PHONY: $(PHONY_DEVELOPER_TARGETS)

if DEVELOPER
if DEVELOPER_MODE

RELTYPE ?=

Expand Down Expand Up @@ -382,9 +392,6 @@ export DOCKER_REGISTRY ?= docker.io
export DOCKER_REPO ?= siletypesetter/$(TRANSFORMED_PACKAGE_NAME)
export DOCKER_TAG ?= HEAD

docker: Dockerfile hooks/build .version
./hooks/build $(VERSION)

docker-dep-check: .docker_deps .aur_deps
$(DIFF) -u $^

Expand All @@ -403,28 +410,11 @@ CLEANFILES += .docker_deps

CLEANFILES += .aur_deps

define docker_push =
test -z "$(DOCKER_PAT)" || \
$(DOCKER) login https://$(DOCKER_REGISTRY) -u $(DOCKER_USERNAME) -p $(DOCKER_PAT)
$(DOCKER) push $(DOCKER_REGISTRY)/$(DOCKER_REPO):$(DOCKER_TAG)
if [[ "$(DOCKER_TAG)" == v*.*.* ]]; then \
tag=$(DOCKER_TAG) ; \
$(DOCKER) tag $(DOCKER_REPO):$(DOCKER_TAG) $(DOCKER_REGISTRY)/$(DOCKER_REPO):latest ; \
$(DOCKER) tag $(DOCKER_REPO):$(DOCKER_TAG) $(DOCKER_REGISTRY)/$(DOCKER_REPO):$${tag//.*} ; \
$(DOCKER) push $(DOCKER_REGISTRY)/$(DOCKER_REPO):latest ; \
$(DOCKER) push $(DOCKER_REGISTRY)/$(DOCKER_REPO):$${tag//.*} ; \
fi
endef

docker-ghcr-to-hub:
$(DOCKER) pull $(GHCR_REGISTRY)/$(GHCR_REPO):$(DOCKER_TAG)
$(DOCKER) tag $(GHCR_REGISTRY)/$(GHCR_REPO):$(DOCKER_TAG) $(DOCKER_REGISTRY)/$(DOCKER_REPO):$(DOCKER_TAG)
$(docker_push)

docker-build-push: docker
$(DOCKER) tag $(DOCKER_REPO):$(DOCKER_TAG) $(DOCKER_REGISTRY)/$(DOCKER_REPO):$(DOCKER_TAG)
$(docker_push)

gource.webm:
$(MKDIR_P) /tmp/gravatars
magick documentation/sile-logo.pdf[0] -density 300 -colorspace RGB -negate -resize 50% /tmp/sile-logo.jpg
Expand All @@ -437,9 +427,9 @@ gource.webm:
gource -a 0.2 -s 0.2 -i 0 --logo /tmp/sile-logo.jpg -b 000000 --max-file-lag 5 --hide filenames --date-format '%Y-%m-%d' --user-image-dir /tmp/gravatars --user-filter simoncozens --key -1920x1080 -o - | \
ffmpeg -y -r 60 -f image2pipe -vcodec ppm -i - -vcodec libvpx -b 10000K $@

else !DEVELOPER
else !DEVELOPER_MODE

$(PHONY_DEVELOPER_TARGETS):
@: $(error "Please reconfigure using --enable-developer to use developer tooling")

endif !DEVELOPER
endif !DEVELOPER_MODE
4 changes: 2 additions & 2 deletions README.md
Expand Up @@ -234,7 +234,7 @@ $ ./bootstrap.sh

If you just plan on installing and using SILE, the default configure options (plus any Lua related options discussed above) should be fine.
If you plan on developing SILE itself (whether to just tinker with it for your own use or contribute upstream) there is one particularly useful configuration option.
You can add `--enable-developer` will set the 'installed data' directory to the source location which will enable the compiled binary to run directly from the source directory without being installed at all.
You can add `--enable-developer-mode` will set the 'installed data' directory to the source location which will enable the compiled binary to run directly from the source directory without being installed at all.
Additionally it will enable checks for tooling we expect SILE contributors to have such as tools used for testing.
Using this options also enables a number of targets that wouldn’t normally be needed by end users such as `make regressions`.

Expand All @@ -245,7 +245,7 @@ $ ./configure
$ make
```

If you just want to mess with SILE locally you can stop here (especially if you used `--enable-developer`).
If you just want to mess with SILE locally you can stop here (especially if you used `--enable-developer-mode`).
However to actually install, you will need to run the installation command with system permissions.

```console
Expand Down
13 changes: 8 additions & 5 deletions bootstrap.sh
Expand Up @@ -36,11 +36,14 @@ else
fi

# Autoreconf uses a perl script to inline includes from Makefile.am into
# Makefile.in before ./configure is even run ... which is where we're going to
# use AC_SUBST to setup project specific build options. We need to pre-seed
# a file to avoid a file not found error on first run. The configure process
# will rebuild this and also re-include it into the final Makefile.
touch build-aux/rust_boilerplate.mk
# Makefile.in before ./configure is ever run even once ... which typically means
# AX_AUTOMAKE_MACROS forfeit access to substitutions or conditional logic
# because they enter the picture after those steps. We're intentially using the
# expanded value of @INC_AMINCLUDE@ directly so the include will be inlined. To
# bootstrap we must pre-seed an empty file to avoid a 'file not found' error on
# first run. Subsequently running ./configure will generate the correct content
# based on the configuration flags and also get re-inlined into Makefile.in.
touch aminclude.am

autoreconf --install

Expand Down
9 changes: 0 additions & 9 deletions build-aux/ax_git_version.m4

This file was deleted.

49 changes: 0 additions & 49 deletions build-aux/ax_rust_boilerplate.m4

This file was deleted.

18 changes: 0 additions & 18 deletions build-aux/ax_transform_package_name.m4

This file was deleted.

8 changes: 3 additions & 5 deletions build-aux/pkg.nix
Expand Up @@ -132,12 +132,10 @@ in stdenv.mkDerivation (finalAttrs: {

enableParallelBuilding = true;

# Autoconf wants to check that Makefile imports are valid files even before
# it potentially generates said files from substitution templates. The
# upstream project uses a bootstrap.sh to create this. Since we skip that, we
# have to fix this race condition ourselves.
# See commentary in bootstrap.sh; we're getting AMINCCLUDE stuff inlined
# instead of included but need to avoid a file not found error on first run.
postUnpack = ''
touch source/build-aux/rust_boilerplate.mk
touch source/aminclude.am
'';

passthru = {
Expand Down
19 changes: 19 additions & 0 deletions build-aux/que_developer_mode.m4
@@ -0,0 +1,19 @@
# Like AM_MAINTAINER_MODE, but doesn't touch automake internals and so
# can be used freely to control access to project specific developer
# tooling without breaking autotools if disabled.
AC_DEFUN([QUE_DEVELOPER_MODE], [
m4_case(m4_default([$1], [disable]),
[enable], [m4_define([_que_developer_def], [disable])],
[disable], [m4_define([_que_developer_def], [enable])],
[m4_define([_que_developer_def], [enable])
m4_warn([syntax], [unexpected argument to AM@&t@_DEVELOPER_MODE: $1])])
AC_MSG_CHECKING([whether to enable developer-specific portions of Makefiles])
AC_ARG_ENABLE([developer-mode],
[AS_HELP_STRING([--]_que_developer_def[-developer-mode],
_que_developer_def[ dependencies and make targets only useful for developers])],
[USE_DEVELOPER_MODE=$enableval],
[USE_DEVELOPER_MODE=]m4_if(_que_developer_def, [enable], [no], [yes]))
AC_MSG_RESULT([$USE_DEVELOPER_MODE])
AM_CONDITIONAL([DEVELOPER_MODE], [test $USE_DEVELOPER_MODE = yes])
])
21 changes: 21 additions & 0 deletions build-aux/que_dist_checksums.am
@@ -0,0 +1,21 @@
# Output both a file that can be attatched to releases and also write STDOUT
# for the sake of CI build logs so they can be audited as matching what is
# eventually posted. The list of files checksummed is a glob (even though we
# know an exact pattern) to avoid errors for formats not generated.
checksum_dist = \
shopt -s nullglob ; \
$(SHA256SUM) $(distdir)*.{tar.{gz,bz2,lz,xz,zst},zip} |\
$(TEE) $(distdir).sha256.txt

# Since the checksums file isn't an artifact produced by the default source dist
# creation process, we have to clean it up ourselves so distcheck can see that
# everything round-tripped cleanly.
distclean-local: distclean-local-checksums

distclean-local-checksums:
rm -f $(distdir).sha256.txt

# Append checksum operation to function that runs after compressing dist archives
am__post_remove_distdir = $(am__remove_distdir); $(checksum_dist)

# vim: ft=automake
20 changes: 20 additions & 0 deletions build-aux/que_dist_checksums.m4
@@ -0,0 +1,20 @@
AC_DEFUN_ONCE([QUE_DIST_CHECKSUMS], [
QUE_TRANSFORM_PACKAGE_NAME
AC_REQUIRE([AX_AM_MACROS])
AX_ADD_AM_MACRO([dnl
EXTRA_DIST += build-aux/que_dist_checksums.am
])dnl
AM_COND_IF([DEVELOPER_MODE], [
QUE_PROGVAR([sha256sum])
QUE_PROGVAR([tee])
AX_ADD_AM_MACRO([dnl
$(cat build-aux/que_dist_checksums.am)
])dnl
])
])
28 changes: 28 additions & 0 deletions build-aux/que_docker_boilerplate.am
@@ -0,0 +1,28 @@
export VERSION_FROM_AUTOTOOLS = v$(VERSION)

DOCKER_DEVELOPER_TARGETS = docker
.PHONY: $(DOCKER_DEVELOPER_TARGETS)

export DOCKER_REGISTRY ?= ghcr.io
export DOCKER_REPO ?= alerque/$(TRANSFORMED_PACKAGE_NAME)
export DOCKER_TAG ?= HEAD

docker: Dockerfile hooks/build .version
./hooks/build $(VERSION)

docker-build-push: docker
docker tag $(DOCKER_REPO):$(DOCKER_TAG) $(DOCKER_REGISTRY)/$(DOCKER_REPO):$(DOCKER_TAG)
$(docker_push)

define docker_push =
test -z "$(DOCKER_PAT)" || \
docker login https://$(DOCKER_REGISTRY) -u $(DOCKER_USERNAME) -p $(DOCKER_PAT)
docker push $(DOCKER_REGISTRY)/$(DOCKER_REPO):$(DOCKER_TAG)
if [[ "$(DOCKER_TAG)" == v*.*.* ]]; then \
tag=$(DOCKER_TAG) ; \
docker tag $(DOCKER_REPO):$(DOCKER_TAG) $(DOCKER_REGISTRY)/$(DOCKER_REPO):latest ; \
docker tag $(DOCKER_REPO):$(DOCKER_TAG) $(DOCKER_REGISTRY)/$(DOCKER_REPO):$${tag//.*} ; \
docker push $(DOCKER_REGISTRY)/$(DOCKER_REPO):latest ; \
docker push $(DOCKER_REGISTRY)/$(DOCKER_REPO):$${tag//.*} ; \
fi
endef
18 changes: 18 additions & 0 deletions build-aux/que_docker_boilerplate.m4
@@ -0,0 +1,18 @@
AC_DEFUN_ONCE([QUE_DOCKER_BOILERPLATE], [
QUE_TRANSFORM_PACKAGE_NAME
AC_MSG_NOTICE([checking for tools used by automake to build Docker projects])
AC_PROG_INSTALL
AM_COND_IF([DEVELOPER_MODE], [
QUE_PROGVAR([docker])
])
AC_REQUIRE([AX_AM_MACROS])
AX_ADD_AM_MACRO([dnl
EXTRA_DIST += build-aux/que_docker_boilerplate.am
$($SED -E "s/@PACKAGE_VAR@/$PACKAGE_VAR/g" build-aux/que_docker_boilerplate.am)
])dnl
])
4 changes: 3 additions & 1 deletion build-aux/git_version.mk → build-aux/que_git_version.am
@@ -1,6 +1,5 @@
.SECONDEXPANSION:

# EXTRA_@PACKAGE_VAR@_SOURCES += .version
EXTRA_DIST += build-aux/git-version-gen
BUILT_SOURCES += .version
CLEANFILES += .version .version-prev
Expand All @@ -25,6 +24,9 @@ check-git-version: $(PACKAGE_NAME)$(EXEEXT) | .version
$(GREP) -Fx '$(VERSION)' $|
./$< --version | $(GREP) -Ff $|

installcheck-local-version:
./$(TRANSFORMED_PACKAGE_NAME)$(EXEEXT) --version

dist-hook: dist-tarball-version

.PHONY: dist-tarball-version
Expand Down

0 comments on commit b1756d4

Please sign in to comment.