From e02c68d49c4d45495b87eca0059d45ecda591d3c Mon Sep 17 00:00:00 2001 From: Caleb Maclennan Date: Mon, 10 Jun 2024 16:50:32 +0300 Subject: [PATCH] feat(build): Overhaul autoconf with modular components from other projects --- Makefile.am | 18 ++- bootstrap.sh | 13 +- build-aux/ax_add_am_macro.m4 | 29 ++++ build-aux/ax_am_macros.m4 | 44 +++++++ build-aux/ax_append_to_file.m4 | 27 ++++ build-aux/ax_file_escapes.m4 | 30 +++++ build-aux/ax_git_version.m4 | 9 -- build-aux/ax_print_to_file.m4 | 27 ++++ build-aux/ax_rust_boilerplate.m4 | 47 ------- build-aux/que_developer_mode.m4 | 19 +++ build-aux/que_dist_checksums.am | 21 +++ build-aux/que_dist_checksums.m4 | 20 +++ build-aux/que_docker_boilerplate.am | 28 ++++ build-aux/que_docker_boilerplate.m4 | 18 +++ .../{git_version.mk => que_git_version.am} | 4 +- build-aux/que_git_version.m4 | 26 ++++ build-aux/{ax_progvar.m4 => que_progvar.m4} | 2 +- ...lerplate.mk.in => que_rust_boilerplate.am} | 25 ++-- build-aux/que_rust_boilerplate.m4 | 42 ++++++ ...n_dirs.mk => que_shell_completion_dirs.am} | 0 ...n_dirs.m4 => que_shell_completion_dirs.m4} | 11 +- ..._name.m4 => que_transform_package_name.m4} | 4 +- configure.ac | 124 ++++++++++-------- 23 files changed, 445 insertions(+), 143 deletions(-) create mode 100644 build-aux/ax_add_am_macro.m4 create mode 100644 build-aux/ax_am_macros.m4 create mode 100644 build-aux/ax_append_to_file.m4 create mode 100644 build-aux/ax_file_escapes.m4 delete mode 100644 build-aux/ax_git_version.m4 create mode 100644 build-aux/ax_print_to_file.m4 delete mode 100644 build-aux/ax_rust_boilerplate.m4 create mode 100644 build-aux/que_developer_mode.m4 create mode 100644 build-aux/que_dist_checksums.am create mode 100644 build-aux/que_dist_checksums.m4 create mode 100644 build-aux/que_docker_boilerplate.am create mode 100644 build-aux/que_docker_boilerplate.m4 rename build-aux/{git_version.mk => que_git_version.am} (91%) create mode 100644 build-aux/que_git_version.m4 rename build-aux/{ax_progvar.m4 => que_progvar.m4} (87%) rename build-aux/{rust_boilerplate.mk.in => que_rust_boilerplate.am} (83%) create mode 100644 build-aux/que_rust_boilerplate.m4 rename build-aux/{shell_completion_dirs.mk => que_shell_completion_dirs.am} (100%) rename build-aux/{ax_shell_completion_dirs.m4 => que_shell_completion_dirs.m4} (90%) rename build-aux/{ax_transform_package_name.m4 => que_transform_package_name.m4} (82%) diff --git a/Makefile.am b/Makefile.am index 116c19bf..9ca0a7db 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,6 +1,7 @@ $(and $(word 2,$(MAKEFILE_LIST)),$(error This is not the makefile you should include in your project to run CaSILE, please use 'rules/casile.mk' instead.)) ACLOCAL_AMFLAGS = -I build-aux +AM_DISTCHECK_CONFIGURE_FLAGS = --enable-developer-mode .ONESHELL: .SECONDARY: @@ -47,7 +48,16 @@ BUILT_SOURCES = Makefile-distfiles CLEANFILES = -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) $(SHELL) build-aux/list-dist-files.sh > $@ @@ -154,7 +164,7 @@ casile-%.md: CHANGELOG.md PHONY_DEVELOPER_TARGETS = lint luacheck stylua checkmake ruff tagrelease release-preview release docker docker-dep-check docker-ghcr-to-hub docker-build-push .PHONY: $(PHONY_DEVELOPER_TARGETS) -if DEVELOPER +if DEVELOPER_MODE lint: luacheck checkmake ruff ruff-format stylua @@ -234,9 +244,9 @@ docker-build-push: docker $(DOCKER) tag $(DOCKER_REPO):$(DOCKER_TAG) $(DOCKER_REGISTRY)/$(DOCKER_REPO):$(DOCKER_TAG) $(docker_push) -else +else !DEVELOPER_MODE $(PHONY_DEVELOPER_TARGETS): @: $(error "Please reconfigure using --enable-developer to use developer tooling") -endif +endif !DEVELOPER_MODE diff --git a/bootstrap.sh b/bootstrap.sh index 92b0893f..e7861c65 100755 --- a/bootstrap.sh +++ b/bootstrap.sh @@ -22,10 +22,13 @@ 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 diff --git a/build-aux/ax_add_am_macro.m4 b/build-aux/ax_add_am_macro.m4 new file mode 100644 index 00000000..3962002b --- /dev/null +++ b/build-aux/ax_add_am_macro.m4 @@ -0,0 +1,29 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_add_am_macro.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_ADD_AM_MACRO([RULE]) +# +# DESCRIPTION +# +# Adds the specified rule to $AMINCLUDE. This macro will only work +# properly with implementations of Make which allow include statements. +# See also AX_ADD_AM_MACRO_STATIC. +# +# LICENSE +# +# Copyright (c) 2009 Tom Howard +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 10 + +AC_DEFUN([AX_ADD_AM_MACRO],[ + AC_REQUIRE([AX_AM_MACROS]) + AX_APPEND_TO_FILE([$AMINCLUDE],[$1]) +]) diff --git a/build-aux/ax_am_macros.m4 b/build-aux/ax_am_macros.m4 new file mode 100644 index 00000000..36c3ab6a --- /dev/null +++ b/build-aux/ax_am_macros.m4 @@ -0,0 +1,44 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_am_macros.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_AM_MACROS +# +# DESCRIPTION +# +# Adds support for macros that create Make rules. You must manually add +# the following line +# +# @INC_AMINCLUDE@ +# +# to your Makefile.in (or Makefile.am if you use Automake) files. +# +# LICENSE +# +# Copyright (c) 2009 Tom Howard +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 11 + +AC_DEFUN([AX_AM_MACROS], +[ +AC_MSG_NOTICE([adding automake macro support]) +AMINCLUDE="aminclude.am" +AC_SUBST(AMINCLUDE) +AC_MSG_NOTICE([creating $AMINCLUDE]) +AMINCLUDE_TIME=`LC_ALL=C date` +AX_PRINT_TO_FILE([$AMINCLUDE],[[ +# generated automatically by configure from AX_AUTOMAKE_MACROS +# on $AMINCLUDE_TIME + +]]) + +INC_AMINCLUDE="include \$(top_builddir)/$AMINCLUDE" +AC_SUBST(INC_AMINCLUDE) +]) diff --git a/build-aux/ax_append_to_file.m4 b/build-aux/ax_append_to_file.m4 new file mode 100644 index 00000000..fca57083 --- /dev/null +++ b/build-aux/ax_append_to_file.m4 @@ -0,0 +1,27 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_append_to_file.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_APPEND_TO_FILE([FILE],[DATA]) +# +# DESCRIPTION +# +# Appends the specified data to the specified file. +# +# LICENSE +# +# Copyright (c) 2008 Tom Howard +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 9 + +AC_DEFUN([AX_APPEND_TO_FILE],[ +AC_REQUIRE([AX_FILE_ESCAPES]) +printf "%s" "$2" >> "$1" +]) diff --git a/build-aux/ax_file_escapes.m4 b/build-aux/ax_file_escapes.m4 new file mode 100644 index 00000000..a86fdc32 --- /dev/null +++ b/build-aux/ax_file_escapes.m4 @@ -0,0 +1,30 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_file_escapes.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_FILE_ESCAPES +# +# DESCRIPTION +# +# Writes the specified data to the specified file. +# +# LICENSE +# +# Copyright (c) 2008 Tom Howard +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 8 + +AC_DEFUN([AX_FILE_ESCAPES],[ +AX_DOLLAR="\$" +AX_SRB="\\135" +AX_SLB="\\133" +AX_BS="\\\\" +AX_DQ="\"" +]) diff --git a/build-aux/ax_git_version.m4 b/build-aux/ax_git_version.m4 deleted file mode 100644 index b5980783..00000000 --- a/build-aux/ax_git_version.m4 +++ /dev/null @@ -1,9 +0,0 @@ -AC_DEFUN([AX_GIT_VERSION], [ - - AC_PROG_AWK - AC_PROG_GREP - AX_PROGVAR([cmp]) - - AX_TRANSFORM_PACKAGE_NAME - -]) diff --git a/build-aux/ax_print_to_file.m4 b/build-aux/ax_print_to_file.m4 new file mode 100644 index 00000000..8aa71120 --- /dev/null +++ b/build-aux/ax_print_to_file.m4 @@ -0,0 +1,27 @@ +# =========================================================================== +# https://www.gnu.org/software/autoconf-archive/ax_print_to_file.html +# =========================================================================== +# +# SYNOPSIS +# +# AX_PRINT_TO_FILE([FILE],[DATA]) +# +# DESCRIPTION +# +# Writes the specified data to the specified file. +# +# LICENSE +# +# Copyright (c) 2008 Tom Howard +# +# Copying and distribution of this file, with or without modification, are +# permitted in any medium without royalty provided the copyright notice +# and this notice are preserved. This file is offered as-is, without any +# warranty. + +#serial 8 + +AC_DEFUN([AX_PRINT_TO_FILE],[ +AC_REQUIRE([AX_FILE_ESCAPES]) +printf "$2" > "$1" +]) diff --git a/build-aux/ax_rust_boilerplate.m4 b/build-aux/ax_rust_boilerplate.m4 deleted file mode 100644 index 3dae605b..00000000 --- a/build-aux/ax_rust_boilerplate.m4 +++ /dev/null @@ -1,47 +0,0 @@ -AC_DEFUN_ONCE([AX_RUST_BOILERPLATE], [ - - AX_TRANSFORM_PACKAGE_NAME - AX_SHELL_COMPLETION_DIRS - - AC_ARG_ENABLE(debug, - AS_HELP_STRING([--enable-debug], - [Build Rust code with debugging information])) - AM_CONDITIONAL([DEBUG_RELEASE], [test "x$enable_debug" = "xyes"]) - - AC_ARG_ENABLE([dependency-checks], - AS_HELP_STRING([--disable-dependency-checks], - [Disable build tooling dependency checks])) - AM_CONDITIONAL([DEPENDENCY_CHECKS], [test "x$enable_dependency_checks" != "xno"]) - - AC_ARG_ENABLE([developer], - AS_HELP_STRING([--enable-developer], - [Check for and enable tooling required only for developers])) - AM_CONDITIONAL([DEVELOPER], [test "x$enable_developer" = "xyes"]) - - AC_MSG_NOTICE([checking for tools used by automake to build Rust projects]) - AC_PROG_INSTALL - AX_PROGVAR([cargo]) - AX_PROGVAR([jq]) - AX_PROGVAR([rustc]) - AX_PROGVAR([cmp]) - AX_PROGVAR([xargs]) - AM_COND_IF([DEPENDENCY_CHECKS], [ - AM_COND_IF([DEVELOPER], [ - AX_PROGVAR([git]) - AX_PROGVAR([rustfmt]) - ]) - ]) - - AC_MSG_CHECKING([whether to build Rust code with debugging information]) - AM_COND_IF([DEBUG_RELEASE], [ - AC_MSG_RESULT(yes) - RUST_TARGET_SUBDIR=debug - ], [ - AC_MSG_RESULT(no) - RUST_TARGET_SUBDIR=release - ]) - AC_SUBST([RUST_TARGET_SUBDIR]) - - AC_CONFIG_FILES([build-aux/rust_boilerplate.mk]) - -]) diff --git a/build-aux/que_developer_mode.m4 b/build-aux/que_developer_mode.m4 new file mode 100644 index 00000000..18bd29fe --- /dev/null +++ b/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]) + +]) diff --git a/build-aux/que_dist_checksums.am b/build-aux/que_dist_checksums.am new file mode 100644 index 00000000..7474ad7c --- /dev/null +++ b/build-aux/que_dist_checksums.am @@ -0,0 +1,21 @@ +# Output both a file that can be attached 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 diff --git a/build-aux/que_dist_checksums.m4 b/build-aux/que_dist_checksums.m4 new file mode 100644 index 00000000..7ace93af --- /dev/null +++ b/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 + + ]) +]) diff --git a/build-aux/que_docker_boilerplate.am b/build-aux/que_docker_boilerplate.am new file mode 100644 index 00000000..b584d447 --- /dev/null +++ b/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 ?= sile-typesetter/$(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 diff --git a/build-aux/que_docker_boilerplate.m4 b/build-aux/que_docker_boilerplate.m4 new file mode 100644 index 00000000..066bf3e1 --- /dev/null +++ b/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 + +]) diff --git a/build-aux/git_version.mk b/build-aux/que_git_version.am similarity index 91% rename from build-aux/git_version.mk rename to build-aux/que_git_version.am index 97a35ad8..6b9e8098 100644 --- a/build-aux/git_version.mk +++ b/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 @@ -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 diff --git a/build-aux/que_git_version.m4 b/build-aux/que_git_version.m4 new file mode 100644 index 00000000..f91ca11b --- /dev/null +++ b/build-aux/que_git_version.m4 @@ -0,0 +1,26 @@ +AC_DEFUN_ONCE([QUE_GIT_VERSION], [ + + AM_CONDITIONAL([SOURCE_IS_GIT], + [test -d .git]) + + AM_CONDITIONAL([SOURCE_IS_DIST], + [test -f .tarball-version]) + + AM_CONDITIONAL([SOURCE_IS_ARCHIVE], + [test ! -d .git -a ! -f .tarball-version]) + + AC_PROG_AWK + AC_PROG_GREP + + QUE_TRANSFORM_PACKAGE_NAME + + AM_COND_IF([SOURCE_IS_DIST], [], [QUE_PROGVAR([cmp])]) + + AC_REQUIRE([AX_AM_MACROS]) + AX_ADD_AM_MACRO([dnl +EXTRA_DIST += build-aux/que_git_version.am + +$(cat build-aux/que_git_version.am) +])dnl + +]) diff --git a/build-aux/ax_progvar.m4 b/build-aux/que_progvar.m4 similarity index 87% rename from build-aux/ax_progvar.m4 rename to build-aux/que_progvar.m4 index e584ed4a..20d1288b 100644 --- a/build-aux/ax_progvar.m4 +++ b/build-aux/que_progvar.m4 @@ -1,4 +1,4 @@ -AC_DEFUN([AX_PROGVAR], [ +AC_DEFUN([QUE_PROGVAR], [ test -n "$m4_toupper($1)" || { AC_PATH_PROG(m4_toupper($1), m4_default($2,$1)) } test -n "$m4_toupper($1)" || AC_MSG_ERROR([m4_default($2,$1) is required]) ]) diff --git a/build-aux/rust_boilerplate.mk.in b/build-aux/que_rust_boilerplate.am similarity index 83% rename from build-aux/rust_boilerplate.mk.in rename to build-aux/que_rust_boilerplate.am index c598c329..2f7b2dd4 100644 --- a/build-aux/rust_boilerplate.mk.in +++ b/build-aux/que_rust_boilerplate.am @@ -11,12 +11,14 @@ if !DEBUG_RELEASE CARGO_RELEASE_ARGS += --release --locked endif -CARGO_ENV = CARGO_TARGET_DIR=@abs_top_builddir@/target -CARGO_BIN = @abs_top_builddir@/target/@RUST_TARGET_SUBDIR@/$(PACKAGE_NAME) -_RUST_OUT = @abs_top_builddir@/target/@RUST_TARGET_SUBDIR@/.cargo_out_dir +CARGO_ENV = CARGO_TARGET_DIR=@builddir@/target +CARGO_BIN = @builddir@/target/@RUST_TARGET_SUBDIR@/$(PACKAGE_NAME) +_RUST_OUT = @builddir@/target/@RUST_TARGET_SUBDIR@/.cargo_out_dir -include $(top_srcdir)/build-aux/git_version.mk -include $(top_srcdir)/build-aux/shell_completion_dirs.mk +distclean-local: distclean-local-rust + +distclean-local-rust: + -rm -rf @builddir@/target @PACKAGE_NAME@$(EXEEXT): $(CARGO_BIN) $(INSTALL) $< $@ @@ -51,10 +53,8 @@ $(COMPLETIONS_OUT_DIR)/_$(TRANSFORMED_PACKAGE_NAME).ps1: $(CARGO_BIN) | $(COMPLE $(COMPLETIONS_OUT_DIR)/_$(TRANSFORMED_PACKAGE_NAME): $(CARGO_BIN) | $(COMPLETIONS_OUT_DIR) $(INSTALL) -m755 $$(cat $(_RUST_OUT))/$(COMPLETIONS_OUT_DIR)/_$(PACKAGE_NAME) $@ - sed -i -e "/::target/s/:'/:_files'/g" $@ $(_RUST_OUT) $(CARGO_BIN): $(@PACKAGE_VAR@_SOURCES) $(EXTRA_@PACKAGE_VAR@_SOURCES) - cd $(top_srcdir) set -e export AUTOTOOLS_DEPENDENCIES="$^" $(CARGO_ENV) $(CARGO) build $(CARGO_VERBOSE) $(CARGO_FEATURE_ARGS) $(CARGO_RELEASE_ARGS) @@ -64,7 +64,7 @@ $(_RUST_OUT) $(CARGO_BIN): $(@PACKAGE_VAR@_SOURCES) $(EXTRA_@PACKAGE_VAR@_SOURCE RUST_DEVELOPER_TARGETS = cargo-test clippy rustfmt .PHONY: $(RUST_DEVELOPER_TARGETS) -if DEVELOPER +if DEVELOPER_MODE test: cargo-test lint: rustfmt clippy @@ -75,22 +75,19 @@ rustfmt: $(GIT) ls-files '*.rs' '*.rs.in' | $(XARGS) $(RUSTFMT) --check --config skip_children=true clippy: - cd $(srcdir) $(CARGO_ENV) $(CARGO) $(CARGO_VERBOSE) clippy $(CARGO_FEATURE_ARGS) -- -D warnings clean-cargo: - cd $(top_srcdir) $(CARGO_ENV) $(CARGO) $(CARGO_VERBOSE) clean cargo-test: $(PACKAGE_NAME)$(EXEEXT) - cd $(srcdir) $(CARGO_ENV) $(CARGO) $(CARGO_VERBOSE) test $(CARGO_FEATURE_ARGS) --locked -else !DEVELOPER +else !DEVELOPER_MODE $(RUST_DEVELOPER_TARGETS): - @: $(error "Please reconfigure using --enable-developer to use developer tooling") + @: $(error "Please reconfigure using --enable-developer-mode to use developer tooling") -endif !DEVELOPER +endif !DEVELOPER_MODE # vim: ft=automake diff --git a/build-aux/que_rust_boilerplate.m4 b/build-aux/que_rust_boilerplate.m4 new file mode 100644 index 00000000..36fa0923 --- /dev/null +++ b/build-aux/que_rust_boilerplate.m4 @@ -0,0 +1,42 @@ +AC_DEFUN_ONCE([QUE_RUST_BOILERPLATE], [ + + QUE_TRANSFORM_PACKAGE_NAME + QUE_DEVELOPER_MODE + QUE_SHELL_COMPLETION_DIRS + + AC_ARG_ENABLE(debug, + AS_HELP_STRING([--enable-debug], + [Build Rust code with debugging information])) + AM_CONDITIONAL([DEBUG_RELEASE], [test "x$debug_release" = "xyes"]) + + AC_MSG_NOTICE([checking for tools used by automake to build Rust projects]) + AC_PROG_INSTALL + AC_PROG_SED + QUE_PROGVAR([cargo]) + QUE_PROGVAR([jq]) + QUE_PROGVAR([rustc]) + QUE_PROGVAR([cmp]) + QUE_PROGVAR([xargs]) + AM_COND_IF([DEVELOPER_MODE], [ + QUE_PROGVAR([git]) + QUE_PROGVAR([rustfmt]) + ]) + + AC_MSG_CHECKING([whether to build Rust code with debugging information]) + AM_COND_IF([DEBUG_RELEASE], [ + AC_MSG_RESULT(yes) + RUST_TARGET_SUBDIR=debug + ], [ + AC_MSG_RESULT(no) + RUST_TARGET_SUBDIR=release + ]) + AC_SUBST([RUST_TARGET_SUBDIR]) + + AC_REQUIRE([AX_AM_MACROS]) + AX_ADD_AM_MACRO([dnl +EXTRA_DIST += build-aux/que_rust_boilerplate.am + +$($SED -E "s/@PACKAGE_VAR@/$PACKAGE_VAR/g;s/@PACKAGE_NAME@/$PACKAGE_NAME/g" build-aux/que_rust_boilerplate.am) +])dnl + +]) diff --git a/build-aux/shell_completion_dirs.mk b/build-aux/que_shell_completion_dirs.am similarity index 100% rename from build-aux/shell_completion_dirs.mk rename to build-aux/que_shell_completion_dirs.am diff --git a/build-aux/ax_shell_completion_dirs.m4 b/build-aux/que_shell_completion_dirs.m4 similarity index 90% rename from build-aux/ax_shell_completion_dirs.m4 rename to build-aux/que_shell_completion_dirs.m4 index 1545cfd9..380ff53d 100644 --- a/build-aux/ax_shell_completion_dirs.m4 +++ b/build-aux/que_shell_completion_dirs.m4 @@ -1,6 +1,6 @@ -AC_DEFUN_ONCE([AX_SHELL_COMPLETION_DIRS], [ +AC_DEFUN_ONCE([QUE_SHELL_COMPLETION_DIRS], [ - AX_TRANSFORM_PACKAGE_NAME + QUE_TRANSFORM_PACKAGE_NAME AC_ARG_WITH([bash-completion-dir], AS_HELP_STRING([--with-bash-completion-dir[=PATH]], @@ -44,4 +44,11 @@ AC_DEFUN_ONCE([AX_SHELL_COMPLETION_DIRS], [ [ZSH_COMPLETION_DIR="$with_zsh_completion_dir"]) AC_SUBST([ZSH_COMPLETION_DIR]) + AC_REQUIRE([AX_AM_MACROS]) + AX_ADD_AM_MACRO([dnl +EXTRA_DIST += build-aux/que_shell_completion_dirs.am + +$(cat build-aux/que_shell_completion_dirs.am) +])dnl + ]) diff --git a/build-aux/ax_transform_package_name.m4 b/build-aux/que_transform_package_name.m4 similarity index 82% rename from build-aux/ax_transform_package_name.m4 rename to build-aux/que_transform_package_name.m4 index 0ff3298c..ee1e8972 100644 --- a/build-aux/ax_transform_package_name.m4 +++ b/build-aux/que_transform_package_name.m4 @@ -1,9 +1,9 @@ -# The autotools supplied AC_ARG_PROGAM enables renaming operations, but it +# The autotools supplied AC_ARG_PROGRAM enables renaming operations, but it # supplies them as a sed operation that can be applied to multiple binaries. # This isn't convenient to use if we're just renaming the top level package, so # we go ahead and *do* the transformation and save for use as a substitution. -AC_DEFUN_ONCE([AX_TRANSFORM_PACKAGE_NAME], [ +AC_DEFUN_ONCE([QUE_TRANSFORM_PACKAGE_NAME], [ AC_PROG_SED diff --git a/configure.ac b/configure.ac index 86a3c0c0..d3f8843a 100644 --- a/configure.ac +++ b/configure.ac @@ -5,16 +5,24 @@ AC_CONFIG_MACRO_DIR([build-aux]) AM_INIT_AUTOMAKE([foreign tar-pax dist-zstd dist-zip no-dist-gzip color-tests subdir-objects]) AM_SILENT_RULES([yes]) -AX_GIT_VERSION -AX_TRANSFORM_PACKAGE_NAME +QUE_GIT_VERSION +QUE_TRANSFORM_PACKAGE_NAME +QUE_DEVELOPER_MODE +QUE_DIST_CHECKSUMS # Build time deps AC_PROG_AWK AC_PROG_SED -AX_PROGVAR([yarn]) -AX_PROGVAR([xargs]) +QUE_PROGVAR([yarn]) +QUE_PROGVAR([xargs]) -AX_RUST_BOILERPLATE +QUE_RUST_BOILERPLATE +QUE_DOCKER_BOILERPLATE + +AC_ARG_ENABLE([dependency-checks], │ │ + AS_HELP_STRING([--disable-dependency-checks], │ │ + [Disable build tooling dependency checks])) │ │ +AM_CONDITIONAL([DEPENDENCY_CHECKS], [test "x$enable_dependency_checks" != "xno"]) AC_ARG_WITH([luajit], AS_HELP_STRING([--without-luajit], @@ -28,51 +36,51 @@ AM_COND_IF([DEPENDENCY_CHECKS], [ AC_PROG_GREP AC_PROG_INSTALL AC_PROG_MKDIR_P - AX_PROGVAR([bc]) - AX_PROGVAR([curl]) - AX_PROGVAR([cut]) - AX_PROGVAR([decasify]) - AX_PROGVAR([deepl]) - AX_PROGVAR([diff]) - AX_PROGVAR([entr]) - AX_PROGVAR([epubcheck]) - AX_PROGVAR([fcconflist], [fc-conflist]) - AX_PROGVAR([find]) - AX_PROGVAR([flock]) - AX_PROGVAR([git]) - AX_PROGVAR([gitwarptime], [git-warp-time]) - AX_PROGVAR([gs]) - AX_PROGVAR([hostnamebin], [hostname]) - AX_PROGVAR([inkscape]) - AX_PROGVAR([jq]) - AX_PROGVAR([kindlegen]) - AX_PROGVAR([m4]) - AX_PROGVAR([magick]) - AX_PROGVAR([mdbook]) - AX_PROGVAR([node]) - AX_PROGVAR([pandoc]) - AX_PROGVAR([pcregrep]) - AX_PROGVAR([pdfbook2]) - AX_PROGVAR([pdfinfo]) - AX_PROGVAR([pdfjam]) - AX_PROGVAR([pdftk]) - AX_PROGVAR([pgrep]) - AX_PROGVAR([podofobox]) - AX_PROGVAR([povray]) - AX_PROGVAR([sassc]) - AX_PROGVAR([sile]) - AX_PROGVAR([sort]) - AX_PROGVAR([sponge]) - AX_PROGVAR([sqlite3]) - AX_PROGVAR([stat]) - AX_PROGVAR([truncate]) - AX_PROGVAR([wc]) - AX_PROGVAR([xcf2png]) - AX_PROGVAR([xvfbrun], [xvfb-run]) - AX_PROGVAR([yq]) - AX_PROGVAR([zint]) - AX_PROGVAR([zola]) - AX_PROGVAR([zsh]) + QUE_PROGVAR([bc]) + QUE_PROGVAR([curl]) + QUE_PROGVAR([cut]) + QUE_PROGVAR([decasify]) + QUE_PROGVAR([deepl]) + QUE_PROGVAR([diff]) + QUE_PROGVAR([entr]) + QUE_PROGVAR([epubcheck]) + QUE_PROGVAR([fcconflist], [fc-conflist]) + QUE_PROGVAR([find]) + QUE_PROGVAR([flock]) + QUE_PROGVAR([git]) + QUE_PROGVAR([gitwarptime], [git-warp-time]) + QUE_PROGVAR([gs]) + QUE_PROGVAR([hostnamebin], [hostname]) + QUE_PROGVAR([inkscape]) + QUE_PROGVAR([jq]) + QUE_PROGVAR([kindlegen]) + QUE_PROGVAR([m4]) + QUE_PROGVAR([magick]) + QUE_PROGVAR([mdbook]) + QUE_PROGVAR([node]) + QUE_PROGVAR([pandoc]) + QUE_PROGVAR([pcregrep]) + QUE_PROGVAR([pdfbook2]) + QUE_PROGVAR([pdfinfo]) + QUE_PROGVAR([pdfjam]) + QUE_PROGVAR([pdftk]) + QUE_PROGVAR([pgrep]) + QUE_PROGVAR([podofobox]) + QUE_PROGVAR([povray]) + QUE_PROGVAR([sassc]) + QUE_PROGVAR([sile]) + QUE_PROGVAR([sort]) + QUE_PROGVAR([sponge]) + QUE_PROGVAR([sqlite3]) + QUE_PROGVAR([stat]) + QUE_PROGVAR([truncate]) + QUE_PROGVAR([wc]) + QUE_PROGVAR([xcf2png]) + QUE_PROGVAR([xvfbrun], [xvfb-run]) + QUE_PROGVAR([yq]) + QUE_PROGVAR([zint]) + QUE_PROGVAR([zola]) + QUE_PROGVAR([zsh]) AC_MSG_CHECKING(whether pandoc has SILE Writer) AS_IF([$PANDOC --list-output-formats | $GREP -qx sile],[ @@ -107,19 +115,19 @@ AM_COND_IF([DEPENDENCY_CHECKS], [ AX_FONT(Libertinus Sans) # Developer tooling deps - AM_COND_IF([DEVELOPER], [ - AX_PROGVAR([checkmake]) - AX_PROGVAR([docker]) - AX_PROGVAR([luacheck]) - AX_PROGVAR([ruff]) - AX_PROGVAR([stylua]) - AX_PROGVAR([tr]) + AM_COND_IF([DEVELOPER_MODE], [ + QUE_PROGVAR([checkmake]) + QUE_PROGVAR([docker]) + QUE_PROGVAR([luacheck]) + QUE_PROGVAR([ruff]) + QUE_PROGVAR([stylua]) + QUE_PROGVAR([tr]) ]) ]) # Avoid the need for configuring with the `--datarootdir=$(cd ..; pwd)` hack to # run from the source directory when developer mode is enabled. -AM_COND_IF([DEVELOPER], [ +AM_COND_IF([DEVELOPER_MODE], [ datarootdir="$(cd ..; pwd)" ])