autoconf-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

autoheader should protect config.h against multiple inclusion


From: Steven G. Johnson
Subject: autoheader should protect config.h against multiple inclusion
Date: Thu, 18 Jan 2001 02:16:33 -0500 (EST)

It occurred to me today that the config.h.in file output by autoheader
does not have the standard #ifndef CONFIG_H ... #endif boilerplate to
protect against multiple inclusions.  Although this is not an issue most
of the time for config.h, it seems like good practice to do it, so I've
attached a patch below.  (I can't think of any reason *not* to do it.)

(The actual variable name is constructed from the name of the resulting
header file.  i.e. it's CONFIG_H for config.h, FOO_BAR_H for foo-bar.h,
etcetera.)

Steven

2001-01-18  Steven G. Johnson <address@hidden>
        
        * autoheader.sh: Bracket the resulting config.h.in file with
        #ifndef CONFIG_H ... #endif, to protect against multiple inclusions.

Index: autoheader.sh
===================================================================
RCS file: /cvs/autoconf/autoheader.sh,v
retrieving revision 1.92
diff -u -r1.92 autoheader.sh
--- autoheader.sh       2001/01/16 10:25:58     1.92
+++ autoheader.sh       2001/01/18 07:11:59
@@ -295,10 +295,19 @@
 *) config_h_in="$config_h.in" ;;
 esac
 
+config_h_var=`echo $config_h | tr a-z A-Z | sed 's/[^A-Z0-9]/_/g'`
+case "$config_h_var" in
+"") config_h_var="AC_CONFIG_H";;
+[^A-Z]*) config_h_var="AC_$config_h_var"  # must begin with a letter
+esac
+
 # Don't write "do not edit" -- it will get copied into the
 # config.h, which it's ok to edit.
 cat <<EOF >$tmp/config.hin
 /* $config_h_in.  Generated automatically from $infile by autoheader.  */
+
+#ifndef $config_h_var
+#define $config_h_var 1
 EOF
 
 # Dump the top.
@@ -320,6 +329,10 @@
   sed -n '/@BOTTOM@/,${/@BOTTOM@/!p;}' $localdir/acconfig.h >>$tmp/config.hin
 test -f $config_h.bot && cat $config_h.bot >>$tmp/config.hin
 
+cat <<EOF >>$tmp/config.hin
+
+#endif /* $config_h_var */
+EOF
 
 # Check that all the symbols have a template.
 $verbose $me: checking completeness of the template >&2





reply via email to

[Prev in Thread] Current Thread [Next in Thread]