diff options
author | Pavel Raiskup <praiskup@redhat.com> | 2015-09-25 13:09:26 +0200 |
---|---|---|
committer | Pavel Raiskup <praiskup@redhat.com> | 2015-09-25 13:09:26 +0200 |
commit | 34e1ada302b502570f9bed9ecba0ea4c6d538dd8 (patch) | |
tree | 041f3fc44e3b4b6841305f774ef98133b6f67036 | |
parent | b3502bb172f127d91ef59d5cd423ec1c9b12b3cb (diff) | |
download | postgresql-setup-34e1ada302b502570f9bed9ecba0ea4c6d538dd8.tar.gz postgresql-setup-34e1ada302b502570f9bed9ecba0ea4c6d538dd8.tar.xz postgresql-setup-34e1ada302b502570f9bed9ecba0ea4c6d538dd8.zip |
configury: switch to _ax_text_tpl.m4
The script generation Makefile snippets are now used from
_ax_text_tpl.m4, DRY principle (the m4 file is maintained
separately for multiple projects).
* configure.ac: Remove all the manual work with substitutions,
start using _AX_TEXT_* macros.
* Makefile.am: Use $(text_tpl_gen*) variables from _ax_text_tpl.
* tests/Makefile.am: Likewise.
* share/postgresql-setup/Makefile.inc: Likewise.
* m4/_ax_text_tpl.m4: New file, TODO: publish somewhere.
* m4/packaging.m4: Reuse _ax_text_tpl.
-rw-r--r-- | Makefile.am | 32 | ||||
-rw-r--r-- | configure.ac | 83 | ||||
-rw-r--r-- | m4/_ax_text_tpl.m4 | 162 | ||||
-rw-r--r-- | m4/packaging.m4 | 3 | ||||
-rw-r--r-- | share/postgresql-setup/Makefile.inc | 2 | ||||
-rw-r--r-- | tests/Makefile.am | 2 |
6 files changed, 199 insertions, 85 deletions
diff --git a/Makefile.am b/Makefile.am index 6d486a7..6b7fa10 100644 --- a/Makefile.am +++ b/Makefile.am @@ -51,47 +51,47 @@ pgdoc_DATA = $(readme_dist) noinst_DATA += $(TEST_GEN_FILES_LIST) $(ctl): $(ctl_in) $(c_s) - $(INSTANTIATE_SCRIPT) + $(text_tpl_gen_script) $(setup): $(setup_in) $(c_s) - $(INSTANTIATE_SCRIPT) + $(text_tpl_gen_script) $(checkdb): $(check) $(checkdb_in) $(c_s) - $(INSTANTIATE_SCRIPT) + $(text_tpl_gen_script) $(initscript): $(initscript_in) $(c_s) - $(INSTANTIATE_SCRIPT) + $(text_tpl_gen_script) initdb upgrade: legacy-sysv-script.in $(c_s) - $(INSTANTIATE_SCRIPT) + $(text_tpl_gen_script) # In ideal world, postgresql@.service would be hardlink to postgresql.service. # That would require, however, the rhbz#1141824 resolved so we could install # system-default drop-in file. Make a "almost" duplicate files now. $(serviceat): $(serviceat_in) $(c_s) - $(AM_V_GEN)$(SED_CALL) \ - -e '/@PGDATA_ENVIRONMENT[@]/d' \ - $< > $@ + $(AM_V_GEN)\ + ax_text_add_sed_substs="-e /@PGDATA_ENVIRONMENT[@]/d" ; \ + $(text_tpl_gen_verbose) $(service): $(service_in) $(c_s) - $(AM_V_GEN)$(SED_CALL) \ - -e 's|@PGDATA_ENVIRONMENT[@]|Environment=PGDATA=$(PGDATADIR)|' \ - $< > $@ + $(AM_V_GEN)\ + ax_text_add_sed_substs="-e s|@PGDATA_ENVIRONMENT[@]|Environment=PGDATA=$(PGDATADIR)|" ; \ + $(text_tpl_gen_verbose) $(readme_dist_sed): $(readme_template) $(c_s) - $(INSTANTIATE) + $(text_tpl_gen) $(readme_dist_m4): $(readme_dist_sed) - $(INSTANTIATE_CONV) && \ + $(text_tpl_gen_conv) && \ m4 -P < $< > $@ $(readme_dist_db): $(readme_dist_m4) - $(INSTANTIATE_CONV) && \ - $(SED_CALL) < $(readme_dist_m4) | m4 -P > $(readme_dist_db) + $(text_tpl_gen_conv) && \ + $(text_tpl_sed_call) < $(readme_dist_m4) | m4 -P > $(readme_dist_db) $(readme_dist): $(readme_dist_db) $(srcdir)/style.dsl - $(INSTANTIATE_CONV) && docbook2txt -d $(srcdir)/style.dsl $(readme_dist_db) >/dev/null && \ + $(text_tpl_gen_conv) && docbook2txt -d $(srcdir)/style.dsl $(readme_dist_db) >/dev/null && \ mv -f $(readme_dist).txt $(readme_dist) EXTRA_DIST += \ diff --git a/configure.ac b/configure.ac index 5d8a4a4..b0074f0 100644 --- a/configure.ac +++ b/configure.ac @@ -13,7 +13,10 @@ AM_SILENT_RULES([yes]) AC_CONFIG_TESTDIR(tests) AC_CONFIG_FILES([tests/Makefile]) AM_MISSING_PROG([AUTOM4TE], [autom4te]) -AC_SUBST([TEST_GEN_FILES_LIST], [.generated_files]) + +_AX_TEXT_TPL_INIT + +_AX_TEXT_TPL_SUBST([TEST_GEN_FILES_LIST], [.generated_files]) # TODO: detect systemd/sysvinit. Also, we should probably be able to install # both configuration at once when needed. @@ -36,45 +39,11 @@ INIT_SYSTEM=systemd test x"$WANT_SYSVINIT" = x1 && INIT_SYSTEM=sysvinit AM_CONDITIONAL([WANT_SYSVINIT], [test "$WANT_SYSVINIT" -eq 1]) -AC_SUBST([WANT_SYSVINIT]) - -# Instatiating generated files by sed instead of config.status. -# This is encouraged by autoconf documentation itself because if we used -# config.status directly, e.g. libexecdir may result into -# '${exec_prefix}/libexec' -- but we need fully expanded strings. -m4_define([sed_subst_var_pattern], [ -e 's|@$1[[@]]|\$($1)|g' \\]) -SED_RULES="\\ -sed_subst_var_pattern(bindir) -sed_subst_var_pattern(datadir) -sed_subst_var_pattern(docdir) -sed_subst_var_pattern(includedir) -sed_subst_var_pattern(libdir) -sed_subst_var_pattern(libexecdir) -sed_subst_var_pattern(MOUNTPOINT) -sed_subst_var_pattern(top_srcdir) -sed_subst_var_pattern(PGDATADIR) -sed_subst_var_pattern(PGMAJORVERSION) -sed_subst_var_pattern(PG_UPGRADE_BIN_USER_OPT) -sed_subst_var_pattern(PGVERSION) -sed_subst_var_pattern(PKGCONFIG_DIR) -sed_subst_var_pattern(POSTGRES_HOMEDIR) -sed_subst_var_pattern(README_DIST) -sed_subst_var_pattern(sharedstatedir) -sed_subst_var_pattern(SU_POSTGRES) -sed_subst_var_pattern(sysconfdir) -sed_subst_var_pattern(TEST_GEN_FILES_LIST) -sed_subst_var_pattern(VERSION) -sed_subst_var_pattern(WANT_SYSVINIT)" - -m4_define([add_sed_subst_var], [ -SED_RULES="$SED_RULES -sed_subst_var_pattern($1)" -AC_SUBST($1) -]) +_AX_TEXT_TPL_SUBST([WANT_SYSVINIT]) m4_define([conf_dir], [dnl test -z "$$1" && $1=$2 -add_sed_subst_var($1) +_AX_TEXT_TPL_SUBST([$1]) ]) SED_CALL="\$(SED) \$(SED_RULES)" @@ -95,13 +64,6 @@ INSTANTIATE="\$(INSTANTIATE_CONV) && \$(SED_CALL) \$< > \$@ && chmod -w \$@" INSTANTIATE_SCRIPT="\$(INSTANTIATE) && chmod +x \$@" c_s='$(top_builddir)/config.status' -AC_SUBST([SED_CALL]) -AC_SUBST([INSTANTIATE]) -AC_SUBST([INSTANTIATE_CONV]) -AC_SUBST([INSTANTIATE_SCRIPT]) -AC_SUBST([c_s]) - - AC_PATH_PROG([SED], [sed]) test -z "$ac_cv_path_SED" && AC_MSG_ERROR([Sed is needed but not found.]) @@ -110,9 +72,10 @@ AC_PATH_PROGS([SU], [runuser su]) test -z "$ac_cv_path_SU" && AC_MSG_ERROR([Neither 'runuser' nor 'su' program found]) SU_POSTGRES="$SU -s /bin/sh -l postgres" -AC_SUBST([SU_POSTGRES]) +_AX_TEXT_TPL_SUBST([SU_POSTGRES]) AC_PATH_PROG([MOUNTPOINT], [mountpoint], [false]) +_AX_TEXT_TPL_SUBST([MOUNTPOINT]) PGSETUP_PACKAGING_INIT @@ -140,7 +103,7 @@ fi AX_COMPARE_VERSION([9.4], [le], [$PGVERSION], [PG_UPGRADE_BIN_USER_OPT="--username"], [PG_UPGRADE_BIN_USER_OPT="--user"]) -AC_SUBST([PG_UPGRADE_BIN_USER_OPT]) +_AX_TEXT_TPL_SUBST([PG_UPGRADE_BIN_USER_OPT]) AC_PATH_PROG([PG_UPGRADE_BIN], [pg_upgrade]) @@ -160,8 +123,8 @@ fi README_DIST_BASENAME=README.rpm-dist README_DIST="\${pgdocdir}/$README_DIST_BASENAME" -AC_SUBST([README_DIST]) -AC_SUBST([README_DIST_BASENAME]) +_AX_TEXT_TPL_SUBST([README_DIST]) +_AX_TEXT_TPL_SUBST([README_DIST_BASENAME]) PGSETUP_SUBST_REQ([PGVERSION], [full PG version]) PGSETUP_SUBST_REQ([PGMAJORVERSION], [major PG version]) @@ -198,29 +161,17 @@ then SCL_SHELL_WRAPPER="$SCL_BINDIR/$SCL_BINARY enable $SCLS -- " SCL_SOURCE="source scl_source enable $SCLS ;" fi -add_sed_subst_var(SCL_SHELL_WRAPPER) -add_sed_subst_var(SCL_SOURCE) + +_AX_TEXT_TPL_SUBST([SCL_SHELL_WRAPPER]) +_AX_TEXT_TPL_SUBST([SCL_SOURCE]) NAME_BINARYBASE="$NAME_BIN_PFX""postgresql$NAME_BIN_SFX" NAME_PACKAGE="$NAME_PKG_PFX""postgresql$NAME_PKG_SFX" NAME_SERVICE="$NAME_SRV_PFX""postgresql$NAME_SRV_SFX" -AC_SUBST([NAME_BINARYBASE]) -AC_SUBST([NAME_PACKAGE]) -AC_SUBST([NAME_SERVICE]) - -AC_SUBST([NAME_BINARYBASE]) -AC_SUBST([NAME_PACKAGE]) -AC_SUBST([NAME_SERVICE]) - -add_sed_subst_var(NAME_SERVICE) -add_sed_subst_var(NAME_PACKAGE) -add_sed_subst_var(NAME_BINARYBASE) - -# As late as possible. -SED_RULES="$SED_RULES - -e 's|@__FILE__[[@]]|\$@|g'" -AC_SUBST([SED_RULES]) +_AX_TEXT_TPL_SUBST([NAME_BINARYBASE]) +_AX_TEXT_TPL_SUBST([NAME_PACKAGE]) +_AX_TEXT_TPL_SUBST([NAME_SERVICE]) AC_OUTPUT diff --git a/m4/_ax_text_tpl.m4 b/m4/_ax_text_tpl.m4 new file mode 100644 index 0000000..971096a --- /dev/null +++ b/m4/_ax_text_tpl.m4 @@ -0,0 +1,162 @@ +# Text templating system with autoconf +# ==================================== +# +# Correctly generate files based on ./configure check results. The @variable@ +# substitution is usually done by config.status from *.in files, however +# substuing paths like @libexecdir@ can result into '${exec_prefix}/libexec' +# which is not desired for installed scripts, for example, where we need to have +# fully expanded paths. The aim of this script is to generalize steps users +# usually do to perform full expansion of configure variables. Currently we use +# sed substitution only. +# +# The easiest usage of this templating system is like this: +# $ cat configure.ac | "grep interresting lines" +# _AX_TEXT_TPL_INIT +# some_other_var="some other var content" +# _AX_TEXT_TPL_SUBST([some_other_var]) +# +# $ cat Makefile (or Makefile.am): +# generated_file: TEMPLATE.in $(text_tpl_deps) +# <<tab>>$(text_tpl_gen) +# +# Limitations: +# - this code is probably not terribly portable +# - substitutions should not contain '|' character (because we use sed rules +# spelled like 's|||'), you can do things like '\|', however you need to +# take into account that substitution done by 'sed' and by 'config.status' are +# not the same. Also be careful about escaping '\' caracter. +# - only single-line substitutions are expected; you may use '\n' however +# there is the same problem as with '|' and '\'. +# +# TODO: +# - we should do something similar to what config.status does (awk generated +# source code for substitutions), however even thought usually variable +# (macro) values are defined by ./configure, some may be defined like 'make +# VARIABLE=VALUE'. + +# sed_subst_var_pattern VARNAME (private macro) +# --------------------------------------------- +# Generate sed substitution rule to substitute @VARNAME@ with fully expaned +# value of $VARNAME. The trick is that we use 'make' to expand the value. +# The VARNAME must be AC_SUBST'ed (and all its sub-components like ${prefix}, +# etc.) to allow 'make' doing correct expansion. +m4_define([sed_subst_var_pattern], [\\ + -e 's|@$1[[@]]|\$($1)|g']) + +# _AX_TEXT_TPL_INIT +# ----------------- +# Initialize the templating system. +AC_DEFUN([_AX_TEXT_TPL_INIT], [ + +__ax_text_tpl_default_variables="\ + abs_builddir + abs_srcdir + abs_top_builddir + abs_top_srcdir + bindir + build_alias + builddir + datarootdir + datadir + docdir + dvidir + exec_prefix + host_alias + htmldir + includedir + infodir + libdir + libexecdir + localedir + localstatedir + mandir + oldincludedir + pdfdir + pkgdatadir + prefix + psdir + sbindir + sharedstatedir + srcdir + sysconfdir + target_alias + top_srcdir + PACKAGE + PACKAGE_BUGREPORT + PACKAGE_NAME + PACKAGE_STRING + PACKAGE_TARNAME + PACKAGE_URL + PACKAGE_VERSION + PATH_SEPARATOR + SHELL + VERSION +" + +__ax_text_tpl_sed_rules="" +for i in $__ax_text_tpl_default_variables +do +__ax_text_tpl_sed_rules="$__ax_text_tpl_sed_rules \ +sed_subst_var_pattern($i)" +done + +__ax_text_tpl_sed_rules="$__ax_text_tpl_sed_rules \\ + \$(__ax_text_tpl_user_sed_rules) \\ + \$(_AX_TEXT_ADDITIONAL_SED_SUBSTITUTIONS) \\ + \$\$ax_text_add_sed_substs \\ + -e 's|@__FILE__[[@]]|\@S|@@|g'" + +__ax_text_tpl_sed_call="\$(SED) \$(__ax_text_tpl_sed_rules)" +text_tpl_sed_call=$__ax_text_tpl_sed_call +m4_pattern_allow(AM_V_GEN) + +# Convenient snippet to clean & prepare for following build +text_tpl_gen_conv_verbose="rm -rf \@S|@@; \$(MKDIR_P) \$(@D)" +text_tpl_gen_conv="\$(AM_V_GEN)\$(text_tpl_gen_conv_verbose)" + +# Instantiate arbitrary data text file +text_tpl_gen_verbose="\$(text_tpl_gen_conv_verbose) && \$(__ax_text_tpl_sed_call) \$< > \@S|@@ && chmod -w \@S|@@" +text_tpl_gen="\$(AM_V_GEN)\$(text_tpl_gen_verbose)" + +# Instantiate script file +text_tpl_gen_script_verbose="\$(text_tpl_gen_verbose) && chmod +x \@S|@@" +text_tpl_gen_script="\$(AM_V_GEN)\$(text_tpl_gen_script_verbose) && chmod +x \@S|@@" + +# Make dependencies for targets of $(text_tpl_gen) and $(text_tpl_gen_script) +text_tpl_deps='$(top_builddir)/config.status' + +AC_PATH_PROG([SED], [sed]) +test -z "$ac_cv_path_SED" && + AC_MSG_ERROR([Sed is needed but not found.]) + +AC_SUBST([__ax_text_tpl_sed_call]) +AC_SUBST([__ax_text_tpl_sed_rules]) +AC_SUBST([__ax_text_tpl_user_sed_rules]) +AC_SUBST([text_tpl_deps]) +AC_SUBST([text_tpl_sed_call]) +AC_SUBST([text_tpl_gen]) +AC_SUBST([text_tpl_gen_verbose]) +AC_SUBST([text_tpl_gen_conv]) +AC_SUBST([text_tpl_gen_conv_verbose]) +AC_SUBST([text_tpl_gen_script]) +AC_SUBST([text_tpl_gen_script_verbose]) +]) + +# _AX_TEXT_TPL_SUBST SHELL_VARNAME +# -------------------------------- +# Do substitution of SHELL_VARNAME both by config.status, and by sed call +# in instantiation rules. +AC_DEFUN([_AX_TEXT_TPL_SUBST], [ +__ax_text_tpl_user_sed_rules="$__ax_text_tpl_user_sed_rules\ +sed_subst_var_pattern($1)" +AC_SUBST($1) +]) + + +# _AX_TEXT_TPL_ARG_VAR VARNAME DEFAULT DESCRIPTION +# ------------------------------------------------ +AC_DEFUN([_AX_TEXT_TPL_ARG_VAR], [ +AC_ARG_VAR([$1], [$3]) +test -z "$$1" && $1=$2 +_AX_TEXT_TPL_SUBST($1) +]) diff --git a/m4/packaging.m4 b/m4/packaging.m4 index a50c4ba..3d166d3 100644 --- a/m4/packaging.m4 +++ b/m4/packaging.m4 @@ -29,6 +29,7 @@ AC_DEFUN([PGSETUP_PACKAGING_INIT], [ # comment. m4_define([PGSETUP_SUBST_REQ], [ AC_ARG_VAR([$1], [$2]) + _AX_TEXT_TPL_SUBST([$1]) test -z "$[]$1" && AC_MSG_ERROR([the \$$1 variable is not set]) ]) @@ -39,5 +40,5 @@ m4_define([PGSETUP_SUBST_OPT], [ AC_ARG_VAR([$1], [$3]) test -z "$[]$1" && $1=$2 - add_sed_subst_var($1) + _AX_TEXT_TPL_SUBST($1) ]) diff --git a/share/postgresql-setup/Makefile.inc b/share/postgresql-setup/Makefile.inc index 0f23e91..23c07d8 100644 --- a/share/postgresql-setup/Makefile.inc +++ b/share/postgresql-setup/Makefile.inc @@ -16,6 +16,6 @@ GENERATED_FILES += $(rawdata_generated_files) EXTRA_DIST += $(rawdata_static_files) $(rawdata_template_files) $(lib): $(lib_in) $(c_s) - $(INSTANTIATE_SCRIPT) + $(text_tpl_gen) # vim: ft=automake noet diff --git a/tests/Makefile.am b/tests/Makefile.am index 93bef19..8f6f5a5 100644 --- a/tests/Makefile.am +++ b/tests/Makefile.am @@ -24,7 +24,7 @@ TESTSUITE = $(srcdir)/testsuite CHECK_DEPS = atconfig atlocal $(TESTSUITE) $(top_builddir)/$(TEST_GEN_FILES_LIST) atlocal: atlocal.in $(c_s) - $(INSTANTIATE) + $(text_tpl_gen) check-local: $(CHECK_DEPS) $(SHELL) '$(TESTSUITE)' $(TESTSUITEFLAGS) |