From 8958c3cb7b77ec50d8dae0490d8c80dee798e20d Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Diego=20Elio=20Petten=C3=B2?= <flameeyes@gmail.com>
Date: Fri, 18 Feb 2011 06:13:20 +0100
Subject: [PATCH 2/2] Don't generate files.h at build-time using an execution test.

The *_LOC variables are never used in the build itself, but only in the
built code; this means that they don't need to be known to ./configure at
all.

Since the previous method made acct not cross-compilable at all, this is
much preferred.

Note: before applying this patch it is necessary to execute

 % svn mv files.h.in files.h

otherwise it won't apply cleanly.
---
 Makefile.am     |    5 --
 Makefile.in     |   10 +----
 configure       |  119 +----------------------------------------------------
 configure.ac    |  103 +---------------------------------------------
 files.h         |  123 +++++++++++++++++++++++++++++++++++++++++++++++++++++++
 files.h.in      |   48 ---------------------
 lib/Makefile.in |    4 --
 7 files changed, 127 insertions(+), 285 deletions(-)
 create mode 100644 files.h
 delete mode 100644 files.h.in

diff --git a/Makefile.am b/Makefile.am
index 6766e4c..32b9a81 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -66,11 +66,6 @@ SYS_LASTCOMM = @SYS_LASTCOMM@
 SYS_AC = @SYS_AC@
 SYS_SA = @SYS_SA@
 
-WTMP_FILE_LOC = @WTMP_FILE_LOC@
-ACCT_FILE_LOC = @ACCT_FILE_LOC@
-SAVACCT_FILE_LOC = @SAVACCT_FILE_LOC@
-USRACCT_FILE_LOC = @USRACCT_FILE_LOC@
-
 compare-ac: ac
 	@echo
 	@echo "Running tests for ac"
diff --git a/Makefile.in b/Makefile.in
index 36d6c27..72f07a2 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -44,7 +44,7 @@ EXTRA_PROGRAMS = lastcomm$(EXEEXT) dump-acct$(EXEEXT) accton$(EXEEXT) \
 subdir = .
 DIST_COMMON = README $(am__configure_deps) $(noinst_HEADERS) \
 	$(srcdir)/Makefile.am $(srcdir)/Makefile.in \
-	$(srcdir)/config.h.in $(srcdir)/files.h.in $(srcdir)/stamp-vti \
+	$(srcdir)/config.h.in $(srcdir)/stamp-vti \
 	$(srcdir)/version.h.in $(srcdir)/version.texi \
 	$(top_srcdir)/configure AUTHORS COPYING ChangeLog INSTALL NEWS \
 	TODO config.guess config.sub depcomp install-sh ltmain.sh \
@@ -88,7 +88,7 @@ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \
  configure.lineno config.status.lineno
 mkinstalldirs = $(install_sh) -d
 CONFIG_HEADER = config.h
-CONFIG_CLEAN_FILES = files.h version.h
+CONFIG_CLEAN_FILES = version.h
 CONFIG_CLEAN_VPATH_FILES =
 am__installdirs = "$(DESTDIR)$(bindir)" "$(DESTDIR)$(sbindir)" \
 	"$(DESTDIR)$(infodir)" "$(DESTDIR)$(man1dir)" \
@@ -240,7 +240,6 @@ distuninstallcheck_listfiles = find . -type f -print
 distcleancheck_listfiles = find . -type f -print
 ACCTON_MAN = @ACCTON_MAN@
 ACCTON_PROG = @ACCTON_PROG@
-ACCT_FILE_LOC = @ACCT_FILE_LOC@
 ACLOCAL = @ACLOCAL@
 ALLOCA = @ALLOCA@
 ALLOCA_H = @ALLOCA_H@
@@ -836,7 +835,6 @@ REPLACE_WCSWIDTH = @REPLACE_WCSWIDTH@
 REPLACE_WCTOB = @REPLACE_WCTOB@
 REPLACE_WCWIDTH = @REPLACE_WCWIDTH@
 REPLACE_WRITE = @REPLACE_WRITE@
-SAVACCT_FILE_LOC = @SAVACCT_FILE_LOC@
 SA_MAN = @SA_MAN@
 SA_PROG = @SA_PROG@
 SED = @SED@
@@ -857,11 +855,9 @@ TIME_H_DEFINES_STRUCT_TIMESPEC = @TIME_H_DEFINES_STRUCT_TIMESPEC@
 UNDEFINE_STRTOK_R = @UNDEFINE_STRTOK_R@
 UNISTD_H_HAVE_WINSOCK2_H = @UNISTD_H_HAVE_WINSOCK2_H@
 UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS = @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
-USRACCT_FILE_LOC = @USRACCT_FILE_LOC@
 VERSION = @VERSION@
 WCHAR_T_SUFFIX = @WCHAR_T_SUFFIX@
 WINT_T_SUFFIX = @WINT_T_SUFFIX@
-WTMP_FILE_LOC = @WTMP_FILE_LOC@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
@@ -1017,8 +1013,6 @@ $(srcdir)/config.h.in:  $(am__configure_deps)
 
 distclean-hdr:
 	-rm -f config.h stamp-h1
-files.h: $(top_builddir)/config.status $(srcdir)/files.h.in
-	cd $(top_builddir) && $(SHELL) ./config.status $@
 version.h: $(top_builddir)/config.status $(srcdir)/version.h.in
 	cd $(top_builddir) && $(SHELL) ./config.status $@
 install-binPROGRAMS: $(bin_PROGRAMS)
diff --git a/configure b/configure
index b5354e6..4950d39 100755
--- a/configure
+++ b/configure
@@ -623,10 +623,6 @@ gl_LIBOBJS
 am__EXEEXT_FALSE
 am__EXEEXT_TRUE
 LTLIBOBJS
-USRACCT_FILE_LOC
-SAVACCT_FILE_LOC
-ACCT_FILE_LOC
-WTMP_FILE_LOC
 SA_MAN
 LASTCOMM_MAN
 ACCTON_MAN
@@ -28250,113 +28246,6 @@ fi
 
 
 fi
-if test "$cross_compiling" = yes; then :
-  echo "Sorry -- you cannot cross-compile this package (FIXME)."; exit 1
-else
-  cat confdefs.h - <<_ACEOF >conftest.$ac_ext
-/* end confdefs.h.  */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <stdint.h>	/* GNU/kFreeBSD */
-#include <sys/acct.h>
-#include <utmp.h>
-
-#ifndef WTMP_FILE
-#  if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__linux__) \
-        || defined(__FreeBSD_kernel__)
-#    define WTMP_FILE "/var/log/wtmp"
-#  else
-#    if defined(sun) || defined(AMIX)
-#      define WTMP_FILE "/var/adm/wtmp"
-#    else
-#      if defined(sgi) || defined(SVR4)
-#        define WTMP_FILE "/usr/adm/wtmp"
-#      else
-#        define WTMP_FILE "/usr/adm/wtmp"
-#      endif
-#    endif
-#  endif
-#endif
-
-#ifndef ACCT_FILE
-#  if defined(__FreeBSD__) || defined(__linux__) \
-        || defined(__FreeBSD_kernel__)
-#    define ACCT_FILE "/var/account/pacct"
-#  else
-#    if defined(__NetBSD__)
-#      define ACCT_FILE "/var/account/acct"
-#    else
-#      if defined(sun) || defined(AMIX)
-#        define ACCT_FILE "/var/adm/pacct"
-#      else
-#        if defined(sgi) || defined(SVR4) || defined(M_XENIX)
-#          define ACCT_FILE "/usr/adm/pacct"
-#        else
-#          define ACCT_FILE "/usr/adm/acct"
-#        endif
-#      endif
-#    endif
-#  endif
-#endif
-
-#ifndef SAVACCT_FILE
-#  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__) \
-        || defined(__FreeBSD_kernel__)
-#    define SAVACCT_FILE "/var/account/savacct"
-#  else
-#    if defined(sun) || defined(AMIX)
-#      define SAVACCT_FILE "/var/adm/savacct"
-#    else
-#      if defined(sgi) || defined(SVR4)
-#        define SAVACCT_FILE "/usr/adm/savacct"
-#      else
-#        define SAVACCT_FILE "/usr/adm/savacct"
-#      endif
-#    endif
-#  endif
-#endif
-
-#ifndef USRACCT_FILE
-#  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__) \
-        || defined(__FreeBSD_kernel__)
-#    define USRACCT_FILE "/var/account/usracct"
-#  else
-#    if defined(sun) || defined(AMIX)
-#      define USRACCT_FILE "/var/adm/usracct"
-#    else
-#      if defined(sgi) || defined(SVR4)
-#        define USRACCT_FILE "/usr/adm/usracct"
-#      else
-#        define USRACCT_FILE "/usr/adm/usracct"
-#      endif
-#    endif
-#  endif
-#endif
-
-main ()
-{
-  FILE *fp;
-  fp = fopen ("locs", "w");
-  fprintf (fp, "WTMP_FILE_LOC=%s\n", WTMP_FILE);
-  fprintf (fp, "ACCT_FILE_LOC=%s\n", ACCT_FILE);
-  fprintf (fp, "SAVACCT_FILE_LOC=%s\n", SAVACCT_FILE);
-  fprintf (fp, "USRACCT_FILE_LOC=%s\n", USRACCT_FILE);
-  fclose (fp);
-  exit(0);
-}
-
-_ACEOF
-if ac_fn_c_try_run "$LINENO"; then :
-  . ./locs; rm locs
-else
-  echo "Error -- could not locate your wtmp and acct files."; exit 1
-fi
-rm -f core *.core core.conftest.* gmon.out bb.out conftest$ac_exeext \
-  conftest.$ac_objext conftest.beam conftest.$ac_ext
-fi
-
 
 ac_fn_c_check_type "$LINENO" "pid_t" "ac_cv_type_pid_t" "$ac_includes_default"
 if test "x$ac_cv_type_pid_t" = xyes; then :
@@ -28766,12 +28655,7 @@ echo checking for kitchen sink... You find a ring in the sink!
 
 
 
-
-
-
-
-
-ac_config_files="$ac_config_files Makefile lib/Makefile files.h version.h"
+ac_config_files="$ac_config_files Makefile lib/Makefile version.h"
 
 cat >confcache <<\_ACEOF
 # This file is a shell script that caches the results of configure
@@ -29939,7 +29823,6 @@ do
     "libtool") CONFIG_COMMANDS="$CONFIG_COMMANDS libtool" ;;
     "Makefile") CONFIG_FILES="$CONFIG_FILES Makefile" ;;
     "lib/Makefile") CONFIG_FILES="$CONFIG_FILES lib/Makefile" ;;
-    "files.h") CONFIG_FILES="$CONFIG_FILES files.h" ;;
     "version.h") CONFIG_FILES="$CONFIG_FILES version.h" ;;
 
   *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;;
diff --git a/configure.ac b/configure.ac
index ad9c041..685ef94 100644
--- a/configure.ac
+++ b/configure.ac
@@ -228,101 +228,6 @@ AC_CHECK_HEADER(sys/acct.h,
 		AC_EGREP_HEADER([comp_t],[sys/acct.h],[AC_DEFINE(HAVE_COMP_T, 1, Define if <sys/acct.h> uses the COMP_T type.)])
   ) ]
 )
-dnl
-dnl find out where utmp/pacct are stored
-dnl
-AC_RUN_IFELSE([AC_LANG_SOURCE([[
-#include <stdio.h>
-#include <stdlib.h>
-#include <sys/types.h>
-#include <stdint.h>	/* GNU/kFreeBSD */
-#include <sys/acct.h>
-#include <utmp.h>
-
-#ifndef WTMP_FILE
-#  if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__linux__) \
-        || defined(__FreeBSD_kernel__)
-#    define WTMP_FILE "/var/log/wtmp"
-#  else
-#    if defined(sun) || defined(AMIX)
-#      define WTMP_FILE "/var/adm/wtmp"
-#    else
-#      if defined(sgi) || defined(SVR4)
-#        define WTMP_FILE "/usr/adm/wtmp"
-#      else
-#        define WTMP_FILE "/usr/adm/wtmp"
-#      endif
-#    endif
-#  endif
-#endif
-
-#ifndef ACCT_FILE
-#  if defined(__FreeBSD__) || defined(__linux__) \
-        || defined(__FreeBSD_kernel__)
-#    define ACCT_FILE "/var/account/pacct"
-#  else
-#    if defined(__NetBSD__)
-#      define ACCT_FILE "/var/account/acct"
-#    else
-#      if defined(sun) || defined(AMIX)
-#        define ACCT_FILE "/var/adm/pacct"
-#      else
-#        if defined(sgi) || defined(SVR4) || defined(M_XENIX)
-#          define ACCT_FILE "/usr/adm/pacct"
-#        else
-#          define ACCT_FILE "/usr/adm/acct"
-#        endif
-#      endif
-#    endif
-#  endif
-#endif
-
-#ifndef SAVACCT_FILE
-#  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__) \
-        || defined(__FreeBSD_kernel__)
-#    define SAVACCT_FILE "/var/account/savacct"
-#  else
-#    if defined(sun) || defined(AMIX)
-#      define SAVACCT_FILE "/var/adm/savacct"
-#    else
-#      if defined(sgi) || defined(SVR4)
-#        define SAVACCT_FILE "/usr/adm/savacct"
-#      else
-#        define SAVACCT_FILE "/usr/adm/savacct"
-#      endif
-#    endif
-#  endif
-#endif
-
-#ifndef USRACCT_FILE
-#  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__) \
-        || defined(__FreeBSD_kernel__)
-#    define USRACCT_FILE "/var/account/usracct"
-#  else
-#    if defined(sun) || defined(AMIX)
-#      define USRACCT_FILE "/var/adm/usracct"
-#    else
-#      if defined(sgi) || defined(SVR4)
-#        define USRACCT_FILE "/usr/adm/usracct"
-#      else
-#        define USRACCT_FILE "/usr/adm/usracct"
-#      endif
-#    endif
-#  endif
-#endif
-
-main ()
-{
-  FILE *fp;
-  fp = fopen ("locs", "w");
-  fprintf (fp, "WTMP_FILE_LOC=%s\n", WTMP_FILE);
-  fprintf (fp, "ACCT_FILE_LOC=%s\n", ACCT_FILE);
-  fprintf (fp, "SAVACCT_FILE_LOC=%s\n", SAVACCT_FILE);
-  fprintf (fp, "USRACCT_FILE_LOC=%s\n", USRACCT_FILE);
-  fclose (fp);
-  exit(0);
-}
-]])],[. ./locs; rm locs],[echo "Error -- could not locate your wtmp and acct files."; exit 1],[echo "Sorry -- you cannot cross-compile this package (FIXME)."; exit 1 ])
 
 dnl types
 AC_TYPE_PID_T dnl for sys/acct.h
@@ -366,12 +271,6 @@ AC_SUBST(ACCTON_MAN)
 AC_SUBST(LASTCOMM_MAN)
 AC_SUBST(SA_MAN)
 
-dnl Substitutions for file locations
-AC_SUBST(WTMP_FILE_LOC)
-AC_SUBST(ACCT_FILE_LOC)
-AC_SUBST(SAVACCT_FILE_LOC)
-AC_SUBST(USRACCT_FILE_LOC)
-
 dnl Dump the makefiles and etc.
-AC_CONFIG_FILES([Makefile lib/Makefile files.h version.h])
+AC_CONFIG_FILES([Makefile lib/Makefile version.h])
 AC_OUTPUT
diff --git a/files.h b/files.h
new file mode 100644
index 0000000..47bfd93
--- /dev/null
+++ b/files.h
@@ -0,0 +1,123 @@
+/* files.h.in
+ *
+ * file locations
+ *
+ */
+
+#ifndef FILES_H
+#define FILES_H
+
+#include "config.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <stdint.h>	/* GNU/kFreeBSD */
+
+#ifdef LINUX_MULTIFORMAT
+# include "linux-acct.h"
+#else
+# include <stdint.h> /* GNU/kFreeBSD */
+# include <sys/acct.h>
+# if defined __FreeBSD__ || defined __FreeBSD_kernel__
+#  include <osreldate.h>
+#  if __FreeBSD_kernel__
+#   define __FreeBSD_version __FreeBSD_kernel_version
+#  endif /* __FreeBSD_kernel__ */
+#  if __FreeBSD_version >= 700100 /* FreeBSD 7.0-STABLE */
+#   define acct acctv2
+#   define ac_flag ac_flagx
+#  endif
+# endif
+#endif
+
+#include <utmp.h>
+
+#ifndef WTMP_FILE
+#  if defined(__FreeBSD__) || defined (__NetBSD__) || defined(__linux__) \
+        || defined(__FreeBSD_kernel__)
+#    define WTMP_FILE "/var/log/wtmp"
+#  else
+#    if defined(sun) || defined(AMIX)
+#      define WTMP_FILE "/var/adm/wtmp"
+#    else
+#      if defined(sgi) || defined(SVR4)
+#        define WTMP_FILE "/usr/adm/wtmp"
+#      else
+#        define WTMP_FILE "/usr/adm/wtmp"
+#      endif
+#    endif
+#  endif
+#endif
+
+#ifndef ACCT_FILE
+#  if defined(__FreeBSD__) || defined(__linux__) \
+        || defined(__FreeBSD_kernel__)
+#    define ACCT_FILE "/var/account/pacct"
+#  else
+#    if defined(__NetBSD__)
+#      define ACCT_FILE "/var/account/acct"
+#    else
+#      if defined(sun) || defined(AMIX)
+#        define ACCT_FILE "/var/adm/pacct"
+#      else
+#        if defined(sgi) || defined(SVR4) || defined(M_XENIX)
+#          define ACCT_FILE "/usr/adm/pacct"
+#        else
+#          define ACCT_FILE "/usr/adm/acct"
+#        endif
+#      endif
+#    endif
+#  endif
+#endif
+
+#ifndef SAVACCT_FILE
+#  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__) \
+        || defined(__FreeBSD_kernel__)
+#    define SAVACCT_FILE "/var/account/savacct"
+#  else
+#    if defined(sun) || defined(AMIX)
+#      define SAVACCT_FILE "/var/adm/savacct"
+#    else
+#      if defined(sgi) || defined(SVR4)
+#        define SAVACCT_FILE "/usr/adm/savacct"
+#      else
+#        define SAVACCT_FILE "/usr/adm/savacct"
+#      endif
+#    endif
+#  endif
+#endif
+
+#ifndef USRACCT_FILE
+#  if defined(__FreeBSD__) || defined(__NetBSD__) || defined(__linux__) \
+        || defined(__FreeBSD_kernel__)
+#    define USRACCT_FILE "/var/account/usracct"
+#  else
+#    if defined(sun) || defined(AMIX)
+#      define USRACCT_FILE "/var/adm/usracct"
+#    else
+#      if defined(sgi) || defined(SVR4)
+#        define USRACCT_FILE "/usr/adm/usracct"
+#      else
+#        define USRACCT_FILE "/usr/adm/usracct"
+#      endif
+#    endif
+#  endif
+#endif
+
+#define WTMP_FILE_LOC WTMP_FILE
+#define ACCT_FILE_LOC ACCT_FILE
+#define SAVACCT_FILE_LOC SAVACCT_FILE
+#define USRACCT_FILE_LOC USRACCT_FILE
+
+/* Workaround for a kernel includes problem */
+#if defined(__linux__) && defined(__alpha__)
+#undef AHZ
+#define AHZ 1024
+#endif
+
+#ifndef AHZ
+#define AHZ 64
+#endif
+
+#endif /* ! FILES_H */
diff --git a/files.h.in b/files.h.in
deleted file mode 100644
index 6d9b017..0000000
--- a/files.h.in
+++ /dev/null
@@ -1,48 +0,0 @@
-/* files.h.in
- *
- * file locations
- *
- */
-
-#ifndef FILES_H
-#define FILES_H
-
-#include "config.h"
-
-#include <sys/types.h>
-
-#ifdef LINUX_MULTIFORMAT
-# include "linux-acct.h"
-#else
-# include <stdint.h> /* GNU/kFreeBSD */
-# include <sys/acct.h>
-# if defined __FreeBSD__ || defined __FreeBSD_kernel__
-#  include <osreldate.h>
-#  if __FreeBSD_kernel__
-#   define __FreeBSD_version __FreeBSD_kernel_version
-#  endif /* __FreeBSD_kernel__ */
-#  if __FreeBSD_version >= 700100 /* FreeBSD 7.0-STABLE */
-#   define acct acctv2
-#   define ac_flag ac_flagx
-#  endif
-# endif
-#endif
-
-#include <utmp.h>
-
-#define WTMP_FILE_LOC "@WTMP_FILE_LOC@"
-#define ACCT_FILE_LOC "@ACCT_FILE_LOC@"
-#define SAVACCT_FILE_LOC "@SAVACCT_FILE_LOC@"
-#define USRACCT_FILE_LOC "@USRACCT_FILE_LOC@"
-
-/* Workaround for a kernel includes problem */
-#if defined(__linux__) && defined(__alpha__)
-#undef AHZ
-#define AHZ 1024
-#endif
-
-#ifndef AHZ
-#define AHZ 64
-#endif
-
-#endif /* ! FILES_H */
diff --git a/lib/Makefile.in b/lib/Makefile.in
index 23157e4..fcedcbe 100644
--- a/lib/Makefile.in
+++ b/lib/Makefile.in
@@ -157,7 +157,6 @@ am__relativize = \
   reldir="$$dir2"
 ACCTON_MAN = @ACCTON_MAN@
 ACCTON_PROG = @ACCTON_PROG@
-ACCT_FILE_LOC = @ACCT_FILE_LOC@
 ACLOCAL = @ACLOCAL@
 ALLOCA = @ALLOCA@
 ALLOCA_H = @ALLOCA_H@
@@ -753,7 +752,6 @@ REPLACE_WCSWIDTH = @REPLACE_WCSWIDTH@
 REPLACE_WCTOB = @REPLACE_WCTOB@
 REPLACE_WCWIDTH = @REPLACE_WCWIDTH@
 REPLACE_WRITE = @REPLACE_WRITE@
-SAVACCT_FILE_LOC = @SAVACCT_FILE_LOC@
 SA_MAN = @SA_MAN@
 SA_PROG = @SA_PROG@
 SED = @SED@
@@ -774,11 +772,9 @@ TIME_H_DEFINES_STRUCT_TIMESPEC = @TIME_H_DEFINES_STRUCT_TIMESPEC@
 UNDEFINE_STRTOK_R = @UNDEFINE_STRTOK_R@
 UNISTD_H_HAVE_WINSOCK2_H = @UNISTD_H_HAVE_WINSOCK2_H@
 UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS = @UNISTD_H_HAVE_WINSOCK2_H_AND_USE_SOCKETS@
-USRACCT_FILE_LOC = @USRACCT_FILE_LOC@
 VERSION = @VERSION@
 WCHAR_T_SUFFIX = @WCHAR_T_SUFFIX@
 WINT_T_SUFFIX = @WINT_T_SUFFIX@
-WTMP_FILE_LOC = @WTMP_FILE_LOC@
 abs_builddir = @abs_builddir@
 abs_srcdir = @abs_srcdir@
 abs_top_builddir = @abs_top_builddir@
-- 
1.7.4.1

