Skip to content

Commit

Permalink
Fix installation directory variable substitution
Browse files Browse the repository at this point in the history
Most autoconf installation directory variables rely on ${prefix}
or ${exec_prefix}.  This behavior is mandated by the GNU coding
standards.  During "make", it allows these variables to be redefined
from the value specified at "configure".  And during "make install",
it allows a different installation location to be specified without
changing the compiled-in location.

The old configure.ac would set these variables during "configure" and
substitute them via AC_CONFIG_FILES.  Some files would use these values
(e.g., conman.init and the manpages), while others would hard-code
conventional paths (e.g., the sysvinit and systemd config files).

This commit fixes this behavior so installation directory variable
substitution now follows the GNU coding standards.  Autoconf-style
template files are created where needed.  In Makefile.am, these files
are specified in SUBSTITUTE_FILES.  To ensure they are generated
during "make", $(SUBSTITUTE_FILES) is added to noinst_DATA.
(Note that listing the manpages here is redundant since those are
also specified in man_MANS, but doing so doesn't cause problems and
simplifies the Makefile.)  "substitute" is defined for performing the
autoconf-style variable substition via sed.  A Makefile rule is defined
for creating the $(SUBSTITUTE_FILES), and AM_V_GEN is used to match
the make output when AM_SILENT_RULES is enabled.  In configure.ac,
AC_CONFIG_FILES is now reduced to just the Makefile.

In Makefile.am, distclean-local is modified to rmdir both the etc/
and man/ directories.  These will only be removed if they are empty.
This should only happen during VPATH builds.

In conman.conf.5.in, the reference to the "@datadir@/@Package@/exec"
directory is updated to use the automake variable "@pkgdatadir@"
since it is now supported via $(substitute).

Reference:
- https://www.gnu.org/software/autoconf/manual/autoconf-2.63/html_node/Installation-Directory-Variables.html
- https://www.gnu.org/software/automake/manual/html_node/Automake-Silent-Rules.html
- https://autotools.io/automake/silent.html
- https://www.gnu.org/software/automake/manual/html_node/Uniform.html

Signed-off-by: Chris Dunlap <cdunlap@llnl.gov>
  • Loading branch information
dun committed Oct 24, 2018
1 parent 1410fab commit 7642609
Show file tree
Hide file tree
Showing 7 changed files with 77 additions and 27 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,8 @@
/conman
/conmand
/etc/conman.init
/etc/conman.logrotate
/etc/conman.service
/etc/conman.sysconfig
/man/*.[1-9]
/stamp-h1
68 changes: 61 additions & 7 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,24 @@ EXTRA_DIST = \
conman.spec \
etc/conman.conf \
etc/conman.init.in \
etc/conman.logrotate.in \
etc/conman.service.in \
etc/conman.sysconfig.in \
man/conman.1.in \
man/conman.conf.5.in \
man/conmand.8.in

SUBSTITUTE_FILES = \
etc/conman.init \
etc/conman.logrotate \
etc/conman.service \
etc/conman.sysconfig
etc/conman.sysconfig \
man/conman.1 \
man/conman.conf.5 \
man/conmand.8

noinst_DATA = \
$(SUBSTITUTE_FILES)

bin_PROGRAMS = \
conman
Expand Down Expand Up @@ -152,27 +167,62 @@ dist_pkgdatalib_SCRIPTS = \
scripts/lib/alpha.exp \
scripts/lib/conman.exp

$(SUBSTITUTE_FILES): Makefile
@$(MKDIR_P) `dirname "$(builddir)/$@"`
$(AM_V_GEN)$(substitute) < "$(srcdir)/$@.in" > "$(builddir)/$@"

substitute = $(SED) \
-e 's,[@]bindir[@],$(bindir),g' \
-e 's,[@]datadir[@],$(datadir),g' \
-e 's,[@]datarootdir[@],$(datarootdir),g' \
-e 's,[@]docdir[@],$(docdir),g' \
-e 's,[@]dvidir[@],$(dvidir),g' \
-e 's,[@]exec_prefix[@],$(exec_prefix),g' \
-e 's,[@]htmldir[@],$(htmldir),g' \
-e 's,[@]includedir[@],$(includedir),g' \
-e 's,[@]infodir[@],$(infodir),g' \
-e 's,[@]libdir[@],$(libdir),g' \
-e 's,[@]libexecdir[@],$(libexecdir),g' \
-e 's,[@]localedir[@],$(localedir),g' \
-e 's,[@]localstatedir[@],$(localstatedir),g' \
-e 's,[@]mandir[@],$(mandir),g' \
-e 's,[@]oldincludedir[@],$(oldincludedir),g' \
-e 's,[@]pdfdir[@],$(pdfdir),g' \
-e 's,[@]pkgdatadir[@],$(pkgdatadir),g' \
-e 's,[@]pkgincludedir[@],$(pkgincludedir),g' \
-e 's,[@]pkglibdir[@],$(pkglibdir),g' \
-e 's,[@]pkglibexecdir[@],$(pkglibexecdir),g' \
-e 's,[@]prefix[@],$(prefix),g' \
-e 's,[@]psdir[@],$(psdir),g' \
-e 's,[@]runstatedir[@],$(runstatedir),g' \
-e 's,[@]sbindir[@],$(sbindir),g' \
-e 's,[@]sharedstatedir[@],$(sharedstatedir),g' \
-e 's,[@]sysconfdir[@],$(sysconfdir),g' \
-e 's,[@]DATE[@],$(DATE),g' \
-e 's,[@]PACKAGE[@],$(PACKAGE),g' \
-e 's,[@]VERSION[@],$(VERSION),g'

install-data-local: install-logrotate install-systemd install-sysvinit

install-logrotate:
install-logrotate: etc/conman.logrotate
$(MKDIR_P) $(DESTDIR)$(sysconfdir)/logrotate.d
$(INSTALL_DATA) $(top_srcdir)/etc/conman.logrotate \
$(INSTALL_DATA) $(top_builddir)/etc/conman.logrotate \
$(DESTDIR)$(sysconfdir)/logrotate.d/$(PACKAGE)

install-systemd:
install-systemd: etc/conman.service
$(MKDIR_P) $(DESTDIR)$(prefix)/lib/systemd/system
$(INSTALL_DATA) $(top_srcdir)/etc/conman.service \
$(INSTALL_DATA) $(top_builddir)/etc/conman.service \
$(DESTDIR)$(prefix)/lib/systemd/system/$(PACKAGE).service

install-sysvinit: install-sysvinit-conf
$(MKDIR_P) $(DESTDIR)$(sysconfdir)/init.d
$(INSTALL_SCRIPT) $(top_builddir)/etc/conman.init \
$(DESTDIR)$(sysconfdir)/init.d/$(PACKAGE)

install-sysvinit-conf:
install-sysvinit-conf: etc/conman.init etc/conman.sysconfig
test -d /etc/sysconfig && d=sysconfig || d=default; \
$(MKDIR_P) $(DESTDIR)$(sysconfdir)/$${d}; \
$(INSTALL_DATA) $(top_srcdir)/etc/conman.sysconfig \
$(INSTALL_DATA) $(top_builddir)/etc/conman.sysconfig \
$(DESTDIR)$(sysconfdir)/$${d}/$(PACKAGE)

uninstall-local:
Expand All @@ -182,12 +232,16 @@ uninstall-local:
-test -d /etc/sysconfig && d=sysconfig || d=default; \
cd "$(DESTDIR)$(sysconfdir)/$${d}" && rm -f $(PACKAGE)

CLEANFILES = \
$(SUBSTITUTE_FILES)

DISTCLEANFILES = \
config.h.in~ \
$(PACKAGE)-*.tar*

distclean-local:
-rm -rf autom4te.cache/
-rmdir etc/ man/ 2>/dev/null || :

MAINTAINERCLEANFILES = \
Makefile.in \
Expand Down
9 changes: 2 additions & 7 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ AC_CONFIG_SRCDIR([server.c])

# checks for programs
AC_PROG_CC
AC_PROG_SED
X_AC_ENABLE_DEBUG

# checks for libraries
Expand Down Expand Up @@ -55,11 +56,5 @@ AC_REPLACE_FUNCS([ \

# checks for system services

AC_CONFIG_FILES([ \
Makefile \
etc/conman.init \
man/conman.1 \
man/conman.conf.5 \
man/conmand.8 \
])
AC_CONFIG_FILES([Makefile])
AC_OUTPUT
7 changes: 3 additions & 4 deletions etc/conman.logrotate → etc/conman.logrotate.in
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,17 @@
##

##
# Example logrotate entry for ConMan.
# Be sure to create the /var/log/conman/ and /var/log/conman.old/ dirs.
# Example logrotate entry.
##
# /var/log/conman/* {
# @localstatedir@/log/conman/* {
# compress
# missingok
# nocopytruncate
# nocreate
# nodelaycompress
# nomail
# notifempty
# olddir /var/log/conman.old/
# olddir @localstatedir@/log/conman.old/
# rotate 4
# sharedscripts
# size=5M
Expand Down
4 changes: 2 additions & 2 deletions etc/conman.service → etc/conman.service.in
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ After=time-sync.target

[Service]
Type=forking
ExecStart=/usr/sbin/conmand -P /var/run/conmand.pid
PIDFile=/var/run/conmand.pid
ExecStart=@sbindir@/conmand -P @localstatedir@/run/conmand.pid
PIDFile=@localstatedir@/run/conmand.pid
LimitNOFILE=infinity
Restart=on-abort

Expand Down
4 changes: 2 additions & 2 deletions etc/conman.sysconfig → etc/conman.sysconfig.in
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
##
# Specify an alternative configuration file.
##
# CONFIG="/etc/conman.conf"
# CONFIG="@sysconfdir@/conman.conf"

##
# Pass additional command-line options to the daemon.
Expand All @@ -11,7 +11,7 @@
##
# Specify where the daemon's PID is written.
##
# PIDFILE="/var/run/conmand.pid"
# PIDFILE="@localstatedir@/run/conmand.pid"

##
# Adjust the scheduling priority of the daemon.
Expand Down
9 changes: 4 additions & 5 deletions man/conman.conf.5.in
Original file line number Diff line number Diff line change
Expand Up @@ -229,11 +229,10 @@ the "\fIhost\fR:\fIport\fR" format (where \fIhost\fR is the remote hostname
or IPv4 address, and \fIport\fR is the remote port number).
.br
.sp
An external process-based connection is defined by the "\fIpath\fR
\fIargs\fR" format (where \fIpath\fR is the pathname to an executable
file/script, and any additional \fIargs\fR are space-delimited); the
\fI@datadir@/@PACKAGE@/exec\fR directory contains scripts for various
console types.
An external process-based connection is defined by the "\fIpath\fR \fIargs\fR"
format (where \fIpath\fR is the pathname to an executable file/script, and
any additional \fIargs\fR are space-delimited); the \fI@pkgdatadir@/exec\fR
directory contains scripts for various console types.
.br
.sp
A local Unix domain socket connection is defined by the "unix:\fIpath\fR"
Expand Down

0 comments on commit 7642609

Please sign in to comment.