blob: c17563f4411d8bf2edb1cd100a5e5afbdfbaa995 [file] [log] [blame]
cristy430a7312010-01-21 20:44:04 +00001# ===========================================================================
cristy964cb7f2010-04-25 23:18:00 +00002# http://www.gnu.org/software/autoconf-archive/ax_prefix_config_h.html
cristy430a7312010-01-21 20:44:04 +00003# ===========================================================================
cristy3ed852e2009-09-05 21:47:34 +00004#
5# SYNOPSIS
6#
7# AX_PREFIX_CONFIG_H [(OUTPUT-HEADER [,PREFIX [,ORIG-HEADER]])]
8#
9# DESCRIPTION
10#
cristy17491be2014-06-24 01:10:53 +000011# Generate an installable config.h.
cristy3ed852e2009-09-05 21:47:34 +000012#
cristy17491be2014-06-24 01:10:53 +000013# A package should not normally install its config.h as a system header,
14# but if it must, this macro can be used to avoid namespace pollution by
15# making a copy of config.h with a prefix added to all the macro names.
16#
17# Each "#define SOMEDEF" line of the configuration header has the given
18# prefix added, in the same case as the first character of the macro name.
cristy3ed852e2009-09-05 21:47:34 +000019#
20# Defaults:
21#
22# OUTPUT-HEADER = $PACKAGE-config.h
23# PREFIX = $PACKAGE
24# ORIG-HEADER, from AM_CONFIG_HEADER(config.h)
25#
cristy17491be2014-06-24 01:10:53 +000026# Your configure.ac script should contain both macros in this order.
cristy3ed852e2009-09-05 21:47:34 +000027#
28# Example:
29#
30# AC_INIT(config.h.in) # config.h.in as created by "autoheader"
31# AM_INIT_AUTOMAKE(testpkg, 0.1.1) # makes #undef VERSION and PACKAGE
32# AM_CONFIG_HEADER(config.h) # prep config.h from config.h.in
33# AX_PREFIX_CONFIG_H(mylib/_config.h) # prep mylib/_config.h from it..
34# AC_MEMORY_H # makes "#undef NEED_MEMORY_H"
35# AC_C_CONST_H # makes "#undef const"
36# AC_OUTPUT(Makefile) # creates the "config.h" now
37# # and also mylib/_config.h
38#
cristy17491be2014-06-24 01:10:53 +000039# If the argument to AX_PREFIX_CONFIG_H would have been omitted then the
40# default output file would have been called simply "testpkg-config.h",
41# but even under the name "mylib/_config.h" it contains prefix-defines
42# like
cristy3ed852e2009-09-05 21:47:34 +000043#
44# #ifndef TESTPKG_VERSION
45# #define TESTPKG_VERSION "0.1.1"
46# #endif
47# #ifndef TESTPKG_NEED_MEMORY_H
48# #define TESTPKG_NEED_MEMORY_H 1
49# #endif
50# #ifndef _testpkg_const
51# #define _testpkg_const _const
52# #endif
53#
cristy17491be2014-06-24 01:10:53 +000054# and this "mylib/_config.h" can be installed along with other header
55# files, which is most convenient when creating a shared library (that has
56# some headers) whose functionality depends on features detected at
57# compile-time. No need to invent some "mylib-confdefs.h.in" manually.
cristy3ed852e2009-09-05 21:47:34 +000058#
cristy430a7312010-01-21 20:44:04 +000059# Note that some AC_DEFINEs that end up in the config.h file are actually
60# self-referential - e.g. AC_C_INLINE, AC_C_CONST, and the AC_TYPE_OFF_T
61# say that they "will define inline|const|off_t if the system does not do
62# it by itself". You might want to clean up about these - consider an
63# extra mylib/conf.h that reads something like:
cristy3ed852e2009-09-05 21:47:34 +000064#
cristy964cb7f2010-04-25 23:18:00 +000065# #include <mylib/_config.h>
66# #ifndef _testpkg_const
67# #define _testpkg_const const
68# #endif
cristy3ed852e2009-09-05 21:47:34 +000069#
cristy430a7312010-01-21 20:44:04 +000070# and then start using _testpkg_const in the header files. That is also a
71# good thing to differentiate whether some library-user has starting to
72# take up with a different compiler, so perhaps it could read something
73# like this:
cristy3ed852e2009-09-05 21:47:34 +000074#
75# #ifdef _MSC_VER
76# #include <mylib/_msvc.h>
77# #else
78# #include <mylib/_config.h>
79# #endif
80# #ifndef _testpkg_const
81# #define _testpkg_const const
82# #endif
83#
cristy430a7312010-01-21 20:44:04 +000084# LICENSE
cristy3ed852e2009-09-05 21:47:34 +000085#
cristy17491be2014-06-24 01:10:53 +000086# Copyright (c) 2014 Reuben Thomas <rrt@sc3d.org>
cristy430a7312010-01-21 20:44:04 +000087# Copyright (c) 2008 Guido U. Draheim <guidod@gmx.de>
88# Copyright (c) 2008 Marten Svantesson
89# Copyright (c) 2008 Gerald Point <Gerald.Point@labri.fr>
cristy3ed852e2009-09-05 21:47:34 +000090#
cristy430a7312010-01-21 20:44:04 +000091# This program is free software; you can redistribute it and/or modify it
92# under the terms of the GNU General Public License as published by the
cristyc3aa2ff2011-02-21 01:46:51 +000093# Free Software Foundation; either version 3 of the License, or (at your
cristy430a7312010-01-21 20:44:04 +000094# option) any later version.
cristy3ed852e2009-09-05 21:47:34 +000095#
96# This program is distributed in the hope that it will be useful, but
97# WITHOUT ANY WARRANTY; without even the implied warranty of
cristy430a7312010-01-21 20:44:04 +000098# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General
99# Public License for more details.
cristy3ed852e2009-09-05 21:47:34 +0000100#
cristy430a7312010-01-21 20:44:04 +0000101# You should have received a copy of the GNU General Public License along
102# with this program. If not, see <http://www.gnu.org/licenses/>.
cristy3ed852e2009-09-05 21:47:34 +0000103#
cristy430a7312010-01-21 20:44:04 +0000104# As a special exception, the respective Autoconf Macro's copyright owner
105# gives unlimited permission to copy, distribute and modify the configure
106# scripts that are the output of Autoconf when processing the Macro. You
107# need not follow the terms of the GNU General Public License when using
108# or distributing such scripts, even though portions of the text of the
109# Macro appear in them. The GNU General Public License (GPL) does govern
110# all other use of the material that constitutes the Autoconf Macro.
cristy3ed852e2009-09-05 21:47:34 +0000111#
cristy430a7312010-01-21 20:44:04 +0000112# This special exception to the GPL applies to versions of the Autoconf
113# Macro released by the Autoconf Archive. When you make and distribute a
114# modified version of the Autoconf Macro, you may extend this special
115# exception to the GPL to apply to your modified version as well.
cristy3ed852e2009-09-05 21:47:34 +0000116
cristy17491be2014-06-24 01:10:53 +0000117#serial 15
cristy964cb7f2010-04-25 23:18:00 +0000118
cristy3ed852e2009-09-05 21:47:34 +0000119AC_DEFUN([AX_PREFIX_CONFIG_H],[dnl
cristya3d62e42010-10-22 20:36:32 +0000120AC_PREREQ([2.62])
cristy3ed852e2009-09-05 21:47:34 +0000121AC_BEFORE([AC_CONFIG_HEADERS],[$0])dnl
cristy17491be2014-06-24 01:10:53 +0000122AC_CONFIG_COMMANDS(m4_default([$1], [$PACKAGE-config.h]),[dnl
cristy3ed852e2009-09-05 21:47:34 +0000123AS_VAR_PUSHDEF([_OUT],[ac_prefix_conf_OUT])dnl
124AS_VAR_PUSHDEF([_DEF],[ac_prefix_conf_DEF])dnl
125AS_VAR_PUSHDEF([_PKG],[ac_prefix_conf_PKG])dnl
126AS_VAR_PUSHDEF([_LOW],[ac_prefix_conf_LOW])dnl
127AS_VAR_PUSHDEF([_UPP],[ac_prefix_conf_UPP])dnl
128AS_VAR_PUSHDEF([_INP],[ac_prefix_conf_INP])dnl
129m4_pushdef([_script],[conftest.prefix])dnl
130m4_pushdef([_symbol],[m4_cr_Letters[]m4_cr_digits[]_])dnl
cristy17491be2014-06-24 01:10:53 +0000131_OUT=`echo m4_default([$1], [$PACKAGE-config.h])`
cristy3ed852e2009-09-05 21:47:34 +0000132_DEF=`echo _$_OUT | sed -e "y:m4_cr_letters:m4_cr_LETTERS[]:" -e "s/@<:@^m4_cr_Letters@:>@/_/g"`
cristy17491be2014-06-24 01:10:53 +0000133_PKG=`echo m4_default([$2], [$PACKAGE])`
cristy3ed852e2009-09-05 21:47:34 +0000134_LOW=`echo _$_PKG | sed -e "y:m4_cr_LETTERS-:m4_cr_letters[]_:"`
135_UPP=`echo $_PKG | sed -e "y:m4_cr_letters-:m4_cr_LETTERS[]_:" -e "/^@<:@m4_cr_digits@:>@/s/^/_/"`
cristy17491be2014-06-24 01:10:53 +0000136_INP=`echo "$3" | sed -e 's/ *//'`
cristy3ed852e2009-09-05 21:47:34 +0000137if test ".$_INP" = "."; then
138 for ac_file in : $CONFIG_HEADERS; do test "_$ac_file" = _: && continue
139 case "$ac_file" in
140 *.h) _INP=$ac_file ;;
141 *)
142 esac
143 test ".$_INP" != "." && break
144 done
145fi
146if test ".$_INP" = "."; then
147 case "$_OUT" in
148 */*) _INP=`basename "$_OUT"`
149 ;;
150 *-*) _INP=`echo "$_OUT" | sed -e "s/@<:@_symbol@:>@*-//"`
151 ;;
152 *) _INP=config.h
153 ;;
154 esac
155fi
156if test -z "$_PKG" ; then
157 AC_MSG_ERROR([no prefix for _PREFIX_PKG_CONFIG_H])
158else
159 if test ! -f "$_INP" ; then if test -f "$srcdir/$_INP" ; then
160 _INP="$srcdir/$_INP"
161 fi fi
162 AC_MSG_NOTICE(creating $_OUT - prefix $_UPP for $_INP defines)
163 if test -f $_INP ; then
cristya3d62e42010-10-22 20:36:32 +0000164 AS_ECHO(["s/^@%:@undef *\\(@<:@m4_cr_LETTERS[]_@:>@\\)/@%:@undef $_UPP""_\\1/"]) > _script
165 AS_ECHO(["s/^@%:@undef *\\(@<:@m4_cr_letters@:>@\\)/@%:@undef $_LOW""_\\1/"]) >> _script
166 AS_ECHO(["s/^@%:@def[]ine *\\(@<:@m4_cr_LETTERS[]_@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_UPP""_\\1\\"]) >> _script
167 AS_ECHO(["@%:@def[]ine $_UPP""_\\1\\2\\"]) >> _script
168 AS_ECHO(["@%:@endif/"]) >> _script
169 AS_ECHO(["s/^@%:@def[]ine *\\(@<:@m4_cr_letters@:>@@<:@_symbol@:>@*\\)\\(.*\\)/@%:@ifndef $_LOW""_\\1\\"]) >> _script
170 AS_ECHO(["@%:@define $_LOW""_\\1\\2\\"]) >> _script
171 AS_ECHO(["@%:@endif/"]) >> _script
cristy3ed852e2009-09-05 21:47:34 +0000172 # now executing _script on _DEF input to create _OUT output file
173 echo "@%:@ifndef $_DEF" >$tmp/pconfig.h
174 echo "@%:@def[]ine $_DEF 1" >>$tmp/pconfig.h
175 echo ' ' >>$tmp/pconfig.h
176 echo /'*' $_OUT. Generated automatically at end of configure. '*'/ >>$tmp/pconfig.h
177
178 sed -f _script $_INP >>$tmp/pconfig.h
179 echo ' ' >>$tmp/pconfig.h
180 echo '/* once:' $_DEF '*/' >>$tmp/pconfig.h
181 echo "@%:@endif" >>$tmp/pconfig.h
182 if cmp -s $_OUT $tmp/pconfig.h 2>/dev/null; then
183 AC_MSG_NOTICE([$_OUT is unchanged])
184 else
185 ac_dir=`AS_DIRNAME(["$_OUT"])`
186 AS_MKDIR_P(["$ac_dir"])
187 rm -f "$_OUT"
188 mv $tmp/pconfig.h "$_OUT"
189 fi
cristy3ed852e2009-09-05 21:47:34 +0000190 else
191 AC_MSG_ERROR([input file $_INP does not exist - skip generating $_OUT])
192 fi
193 rm -f conftest.*
194fi
195m4_popdef([_symbol])dnl
196m4_popdef([_script])dnl
197AS_VAR_POPDEF([_INP])dnl
198AS_VAR_POPDEF([_UPP])dnl
199AS_VAR_POPDEF([_LOW])dnl
200AS_VAR_POPDEF([_PKG])dnl
201AS_VAR_POPDEF([_DEF])dnl
202AS_VAR_POPDEF([_OUT])dnl
203],[PACKAGE="$PACKAGE"])])