From 0c1fc1c715aa18605eb11c6c25867277824e8f8d Mon Sep 17 00:00:00 2001 From: Jim Meyering Date: Wed, 13 Aug 2008 22:30:14 +0200 Subject: [PATCH] use new global, "Version", rather than macro, VERSION With this change, a version-string update no longer forces recompilation of 100+ src/*.o files. * src/version.c (Version): New global. New file. * src/version.h: Declare it. * src/Makefile.am: Put it in a library that everyone links to. (noinst_LIBRARIES, libver_a_SOURCES): Define. (LDADD): Add libver.a. (sc_tight_scope): Use perl (was sed), and a more relaxed regexp to build the global-variable-name-recognizing regexp list. * src/system.h: Include "version.h". (case_GETOPT_VERSION_CHAR): Use Version rather than VERSION. * src/basename.c (main): Use Version rather than VERSION. * src/chroot.c (main): Likewise. * src/cksum.c (main): Likewise. * src/dd.c (main): Likewise. * src/dirname.c (main): Likewise. * src/echo.c (main): Likewise. * src/hostid.c (main): Likewise. * src/hostname.c (main): Likewise. * src/link.c (main): Likewise. * src/logname.c (main): Likewise. * src/nice.c (main): Likewise. * src/nohup.c (main): Likewise. * src/printenv.c (main): Likewise. * src/printf.c (main): Likewise. * src/pwd.c (main): Likewise. * src/setuidgid.c (main): Likewise. * src/sleep.c (main): Likewise. * src/sync.c (main): Likewise. * src/test.c (main): Likewise. * src/timeout.c (main): Likewise. * src/true.c (main): Likewise. * src/tsort.c (main): Likewise. * src/unlink.c (main): Likewise. * src/uptime.c (main): Likewise. * src/users.c (main): Likewise. * src/whoami.c (main): Likewise. * src/yes.c (main): Likewise. --- src/Makefile.am | 9 ++++++--- src/basename.c | 2 +- src/chroot.c | 2 +- src/cksum.c | 2 +- src/dd.c | 2 +- src/dirname.c | 2 +- src/echo.c | 2 +- src/hostid.c | 2 +- src/hostname.c | 2 +- src/link.c | 2 +- src/logname.c | 2 +- src/nice.c | 2 +- src/nohup.c | 2 +- src/printenv.c | 2 +- src/printf.c | 2 +- src/pwd.c | 2 +- src/setuidgid.c | 2 +- src/sleep.c | 2 +- src/sync.c | 2 +- src/system.h | 3 ++- src/test.c | 2 +- src/timeout.c | 2 +- src/true.c | 2 +- src/tsort.c | 2 +- src/unlink.c | 2 +- src/uptime.c | 2 +- src/users.c | 2 +- src/version.c | 2 ++ src/version.h | 1 + src/whoami.c | 2 +- src/yes.c | 2 +- 31 files changed, 38 insertions(+), 31 deletions(-) create mode 100644 src/version.c create mode 100644 src/version.h diff --git a/src/Makefile.am b/src/Makefile.am index 359d18ec6..1d5900387 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -69,12 +69,15 @@ CLEANFILES = $(SCRIPTS) su AM_CPPFLAGS = -I$(top_srcdir)/lib +noinst_LIBRARIES = libver.a +libver_a_SOURCES = version.c version.h + # Sometimes, the expansion of $(LIBINTL) includes -lc which may # include modules defining variables like `optind', so libcoreutils.a # must precede $(LIBINTL) in order to ensure we use GNU getopt. # But libcoreutils.a must also follow $(LIBINTL), since libintl uses # replacement functions defined in libcoreutils.a. -LDADD = ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a +LDADD = libver.a ../lib/libcoreutils.a $(LIBINTL) ../lib/libcoreutils.a cat_LDADD = $(LDADD) df_LDADD = $(LDADD) @@ -435,8 +438,8 @@ sc_tight_scope: $(all_programs) { echo 'the above functions should have static scope' 1>&2; \ exit 1; } || : ; \ ( printf '^program_name$$\n'; \ - sed -n 's/^extern int \([^ ][^ ]*\);$$/^\1$$/p' \ - $(noinst_HEADERS) ) > $$t; \ + perl -ne '/^extern .*?\**(\w+);/ and print "^$$1\$$\n"' \ + *.h ) > $$t; \ nm -e *.$(OBJEXT) \ | sed -n 's/.* [BD] //p' \ | grep -Ev -f $$t && \ diff --git a/src/basename.c b/src/basename.c index 69b708fe7..ac2e01ec2 100644 --- a/src/basename.c +++ b/src/basename.c @@ -103,7 +103,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "+", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/chroot.c b/src/chroot.c index d55db6ef0..299acbcbf 100644 --- a/src/chroot.c +++ b/src/chroot.c @@ -71,7 +71,7 @@ main (int argc, char **argv) initialize_exit_failure (EXIT_FAILURE); atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "+", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/cksum.c b/src/cksum.c index a2d49c5b3..8bbed37f9 100644 --- a/src/cksum.c +++ b/src/cksum.c @@ -287,7 +287,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/dd.c b/src/dd.c index d32cd946e..f598e44cd 100644 --- a/src/dd.c +++ b/src/dd.c @@ -1739,7 +1739,7 @@ main (int argc, char **argv) page_size = getpagesize (); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, Version, usage, AUTHORS, (char const *) NULL); close_stdout_required = false; diff --git a/src/dirname.c b/src/dirname.c index 3a319128f..10926435f 100644 --- a/src/dirname.c +++ b/src/dirname.c @@ -82,7 +82,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "+", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/echo.c b/src/echo.c index 8a6466ea8..d549cda2b 100644 --- a/src/echo.c +++ b/src/echo.c @@ -122,7 +122,7 @@ main (int argc, char **argv) atexit (close_stdout); if (allow_options) - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); --argc; diff --git a/src/hostid.c b/src/hostid.c index dbcb98df8..f3cabc47b 100644 --- a/src/hostid.c +++ b/src/hostid.c @@ -68,7 +68,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/hostname.c b/src/hostname.c index cf8e9535b..b325c2753 100644 --- a/src/hostname.c +++ b/src/hostname.c @@ -85,7 +85,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/link.c b/src/link.c index 1b09fe327..d155291f0 100644 --- a/src/link.c +++ b/src/link.c @@ -67,7 +67,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/logname.c b/src/logname.c index a71ac33a1..9cf0d9fae 100644 --- a/src/logname.c +++ b/src/logname.c @@ -62,7 +62,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/nice.c b/src/nice.c index 13033ec5e..ee8cc866e 100644 --- a/src/nice.c +++ b/src/nice.c @@ -104,7 +104,7 @@ main (int argc, char **argv) initialize_exit_failure (EXIT_FAILURE); atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); for (i = 1; i < argc; /* empty */) diff --git a/src/nohup.c b/src/nohup.c index 61f181dbd..3ff22eac8 100644 --- a/src/nohup.c +++ b/src/nohup.c @@ -95,7 +95,7 @@ main (int argc, char **argv) initialize_exit_failure (NOHUP_FAILURE); atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "+", NULL, NULL) != -1) usage (NOHUP_FAILURE); diff --git a/src/printenv.c b/src/printenv.c index ecb6593dd..3033fd4b9 100644 --- a/src/printenv.c +++ b/src/printenv.c @@ -88,7 +88,7 @@ main (int argc, char **argv) initialize_exit_failure (PRINTENV_FAILURE); atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "+", NULL, NULL) != -1) usage (PRINTENV_FAILURE); diff --git a/src/printf.c b/src/printf.c index a9d5aa144..c50995183 100644 --- a/src/printf.c +++ b/src/printf.c @@ -645,7 +645,7 @@ main (int argc, char **argv) posixly_correct = (getenv ("POSIXLY_CORRECT") != NULL); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); /* The above handles --help and --version. diff --git a/src/pwd.c b/src/pwd.c index 5038065d3..3c7b4fcc4 100644 --- a/src/pwd.c +++ b/src/pwd.c @@ -293,7 +293,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/setuidgid.c b/src/setuidgid.c index e9103572d..057002cbf 100644 --- a/src/setuidgid.c +++ b/src/setuidgid.c @@ -90,7 +90,7 @@ main (int argc, char **argv) initialize_exit_failure (SETUIDGID_FAILURE); atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); { int c; diff --git a/src/sleep.c b/src/sleep.c index 4176977f0..0c11b8e73 100644 --- a/src/sleep.c +++ b/src/sleep.c @@ -111,7 +111,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/sync.c b/src/sync.c index 96dcf0953..fccc6fb92 100644 --- a/src/sync.c +++ b/src/sync.c @@ -61,7 +61,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/system.h b/src/system.h index 4b8e58e1f..e88b1bb3b 100644 --- a/src/system.h +++ b/src/system.h @@ -115,6 +115,7 @@ you must include before including this file #include #include +#include "version.h" /* Exit statuses for programs like 'env' that exec other programs. */ enum @@ -466,7 +467,7 @@ enum #define case_GETOPT_VERSION_CHAR(Program_name, Authors) \ case GETOPT_VERSION_CHAR: \ - version_etc (stdout, Program_name, PACKAGE_NAME, VERSION, Authors, \ + version_etc (stdout, Program_name, PACKAGE_NAME, Version, Authors, \ (char *) NULL); \ exit (EXIT_SUCCESS); \ break; diff --git a/src/test.c b/src/test.c index 833b254b6..1fe7da00c 100644 --- a/src/test.c +++ b/src/test.c @@ -826,7 +826,7 @@ main (int margc, char **margv) to exit silently with status 0. */ if (margc < 2 || !STREQ (margv[margc - 1], "]")) { - parse_long_options (margc, margv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (margc, margv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); test_syntax_error (_("missing `]'"), NULL); } diff --git a/src/timeout.c b/src/timeout.c index 8449607af..37bed3c09 100644 --- a/src/timeout.c +++ b/src/timeout.c @@ -232,7 +232,7 @@ main (int argc, char **argv) initialize_exit_failure (EXIT_CANCELED); atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); while ((c = getopt_long (argc, argv, "+s:", long_options, NULL)) != -1) diff --git a/src/true.c b/src/true.c index 12100bdbf..80940f07b 100644 --- a/src/true.c +++ b/src/true.c @@ -70,7 +70,7 @@ main (int argc, char **argv) usage (EXIT_STATUS); if (STREQ (argv[1], "--version")) - version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, VERSION, AUTHORS, + version_etc (stdout, PROGRAM_NAME, PACKAGE_NAME, Version, AUTHORS, (char *) NULL); } diff --git a/src/tsort.c b/src/tsort.c index 703b8557d..76865b95f 100644 --- a/src/tsort.c +++ b/src/tsort.c @@ -538,7 +538,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/unlink.c b/src/unlink.c index 36595c8dc..1b999d1d6 100644 --- a/src/unlink.c +++ b/src/unlink.c @@ -66,7 +66,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/uptime.c b/src/uptime.c index b35e97a48..a5c4fe55c 100644 --- a/src/uptime.c +++ b/src/uptime.c @@ -230,7 +230,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/users.c b/src/users.c index 19ffce8ca..c10dac67d 100644 --- a/src/users.c +++ b/src/users.c @@ -128,7 +128,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/version.c b/src/version.c new file mode 100644 index 000000000..1187ff0c2 --- /dev/null +++ b/src/version.c @@ -0,0 +1,2 @@ +#include +char const *Version = VERSION; diff --git a/src/version.h b/src/version.h new file mode 100644 index 000000000..f6a1ed330 --- /dev/null +++ b/src/version.h @@ -0,0 +1 @@ +extern char const *Version; diff --git a/src/whoami.c b/src/whoami.c index c3b709bc4..75bb9a6cd 100644 --- a/src/whoami.c +++ b/src/whoami.c @@ -70,7 +70,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "", NULL, NULL) != -1) usage (EXIT_FAILURE); diff --git a/src/yes.c b/src/yes.c index d72c5da87..e2a58445f 100644 --- a/src/yes.c +++ b/src/yes.c @@ -67,7 +67,7 @@ main (int argc, char **argv) atexit (close_stdout); - parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, VERSION, + parse_long_options (argc, argv, PROGRAM_NAME, PACKAGE_NAME, Version, usage, AUTHORS, (char const *) NULL); if (getopt_long (argc, argv, "+", NULL, NULL) != -1) usage (EXIT_FAILURE); -- 2.34.1