From: David Champion Date: Tue, 16 Oct 2012 23:13:13 +0000 (-0500) Subject: Add compiler and configure info to mutt -v output (closes #3537) X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f7f687dde11b9f1b0ebf3c85afa9f020b50caeea;p=neomutt Add compiler and configure info to mutt -v output (closes #3537) Makefile(.am) updated to produce conststrings.c, which contains C strings representing: * the compiler's own version information; * the CFLAGS value from the Make environment * the ./configure options main.c is updated to print them when running 'mutt -v'. txt2c.sh is added to produce conststrings.c. txt2c.sh uses a compiled txt2c binary if possible, for complete fidelity to the source strings in whatever encoding they may use. If txt2c is not available (could not be compiled, or was not compiled natively) it falls back on a shell function to approximate the output using sed and tr. --- diff --git a/.hgignore b/.hgignore index 28d1e368c..8995db4c7 100644 --- a/.hgignore +++ b/.hgignore @@ -27,9 +27,11 @@ ^mutt_dotlock(\.c)?$ ^mutt_md5$ ^patchlist\.c$ +^conststrings\.c$ ^pgpewrap|pgpring$ ^reldate\.h$ ^smime_keys$ +^txt2c$ ^stamp-doc-rc$ ^doc/instdoc$ ^doc/manual\.(txt|xml|aux|log|out|tex|pdf)$ diff --git a/Makefile.am b/Makefile.am index 0905a6814..24daaab61 100644 --- a/Makefile.am +++ b/Makefile.am @@ -17,7 +17,7 @@ if BUILD_HCACHE HCVERSION = hcversion.h endif -BUILT_SOURCES = keymap_defs.h patchlist.c reldate.h $(HCVERSION) +BUILT_SOURCES = keymap_defs.h patchlist.c reldate.h conststrings.c $(HCVERSION) bin_PROGRAMS = mutt @DOTLOCK_TARGET@ @PGPAUX_TARGET@ mutt_SOURCES = \ @@ -94,9 +94,26 @@ noinst_PROGRAMS = $(MUTT_MD5) mutt_dotlock.c: dotlock.c cp $(srcdir)/dotlock.c mutt_dotlock.c +# If this fails, we will fall back to the implementation in txt2c.sh +txt2c: txt2c.c + -$${NATIVECC-$(CC)} -o $@ $< + +conststrings.c: txt2c config.status + ( \ + $(CC) -v || \ + $(CC) --version || \ + $(CC) -V || \ + echo "unknown compiler"; \ + ) 2>&1 | ./txt2c.sh cc_version >conststrings_c + echo "$(CFLAGS)" | ./txt2c.sh cc_cflags >>conststrings_c + grep ac_cs_config= config.status | \ + cut -d= -f2- | \ + sed -e 's/^"//' -e 's/"$$//' | ./txt2c.sh configure_options >>conststrings_c + mv -f conststrings_c conststrings.c + CLEANFILES = mutt_dotlock.c keymap_alldefs.h $(BUILT_SOURCES) -DISTCLEANFILES= flea smime_keys +DISTCLEANFILES= flea smime_keys txt2c ACLOCAL_AMFLAGS = -I m4 diff --git a/main.c b/main.c index 0952c93b4..1c3d0b763 100644 --- a/main.c +++ b/main.c @@ -154,6 +154,24 @@ options:\n\ exit (0); } +extern const char cc_version[]; +extern const char cc_cflags[]; +extern const char configure_options[]; + +static char * +rstrip_in_place(char *s) +{ + char *p; + + p = &s[strlen(s)]; + if (p == s) + return s; + p--; + while (p >= s && (*p == '\n' || *p == '\r')) + *p-- = '\0'; + return s; +} + static void show_version (void) { struct utsname uts; @@ -193,6 +211,16 @@ static void show_version (void) printf ("\nhcache backend: %s", mutt_hcache_backend ()); #endif + puts ("\n\nCompiler:"); + rstrip_in_place((char *)cc_version); + puts (cc_version); + + rstrip_in_place((char *)configure_options); + printf ("\nConfigure options: %s\n", configure_options); + + rstrip_in_place((char *)cc_cflags); + printf ("\nCompilation CFLAGS: %s\n", cc_cflags); + puts (_("\nCompile options:")); #ifdef DOMAIN diff --git a/muttbug.sh.in b/muttbug.sh.in index 9bcb95598..b429faeda 100644 --- a/muttbug.sh.in +++ b/muttbug.sh.in @@ -248,21 +248,6 @@ else # Please provide more of these if you have any. fi -echo -echo "-- Build environment information" -echo -echo "(Note: This is the build environment installed on the system" -echo "muttbug is run on. Information may or may not match the environment" -echo "used to build mutt.)" -echo -echo "- gcc version information" -echo "@CC@" -@CC@ -v 2>&1 -echo -echo "- CFLAGS" -echo @CFLAGS@ - - echo echo "-- Mutt Version Information" echo diff --git a/txt2c.c b/txt2c.c new file mode 100644 index 000000000..a9164a3cd --- /dev/null +++ b/txt2c.c @@ -0,0 +1,37 @@ +#include + +#define per_line 12 + +void +txt2c(char *sym, FILE *fp) +{ + unsigned char buf[per_line]; + int i; + int sz = 0; + + printf("unsigned char %s[] = {\n", sym); + while (1) { + sz = fread(buf, sizeof(unsigned char), per_line, fp); + if (sz == 0) + break; + printf("\t"); + for (i = 0; i < sz; i++) + printf("0x%02x, ", buf[i]); + printf("\n"); + } + + printf("\t0x00\n};\n"); +} + + +int +main(int argc, char *argv[]) +{ + if (argc != 2) { + fprintf(stderr, "usage: %s symbol textfile.c\n", argv[0]); + return 2; + } + + txt2c(argv[1], stdin); + return 0; +} diff --git a/txt2c.sh b/txt2c.sh new file mode 100755 index 000000000..e62a82a6e --- /dev/null +++ b/txt2c.sh @@ -0,0 +1,26 @@ +#!/bin/sh + +txt2c_fallback () { + # consumes stdin + + # declaration + echo "unsigned char $1[] = " + + # initializer - filter out unwanted characters, then convert problematic + # or odd-looking sequences. The result is a sequence of quote-bounded + # C strings, which the compiler concatenates into a single C string. + tr -c '\011\012\015\040[!-~]' '?' | + sed \ + -e 's/\\/\\\\/g' \ + -e 's/"/\\"/g' \ + -e 's/??/\?\?/g' \ + -e 's/\t/\\t/'g \ + -e 's/\r/\\r/g' \ + -e 's/^/ "/g' \ + -e 's/$/\\n"/g' + echo ";" +} + +./txt2c test /dev/null 2>&1 && +./txt2c "$1" || +txt2c_fallback "$1"