1#! /bin/sh
2#
3# Generate the webauth/defines.h header, including config.h information.
4#
5# This shell script runs after configure and generates the webauth/defines.h
6# header with the appropriate magic to allow use of int32_t and uint32_t.  It
7# exists because one can't easily insert multiline code into header files
8# using Autoconf; output variables aren't allowed to contain newlines.
9#
10# The first argument should be the path to webauth/defines.h.in and the second
11# argument should be the path to webauth/defines.h.
12#
13# Written by Russ Allbery <eagle@eyrie.org>
14# Copyright 2003, 2009, 2011
15#     The Board of Trustees of the Leland Stanford Junior University
16#
17# See LICENSE for licensing terms.
18
19# Find the definitions of int32_t and uint32_t.
20int32=`grep '^#define int32_t' config.h | sed 's/^#/# /'`
21uint32=`grep '^#define uint32_t' config.h | sed 's/^#/# /'`
22
23# Start building the magic string.  Include the appropriate header files, if
24# they exist.
25magic=''
26if [ -z "$int32" ] || [ -z "$uint32" ] ; then
27    if grep '^#define HAVE_INTTYPES_H' config.h > /dev/null 2>&1 ; then
28        magic="${magic}#include <inttypes.h>
29"
30    fi
31    if grep '^#define HAVE_STDINT_H' config.h > /dev/null 2>&1 ; then
32        magic="${magic}#include <stdint.h>
33"
34    fi
35fi
36
37# Now include the definitions of int32_t and uint32_t if needed.
38if [ -n "$int32" ] ; then
39    magic="${magic}#undef int32_t
40$int32
41"
42fi
43if [ -n "$uint32" ] ; then
44    magic="${magic}#undef uint32_t
45$uint32
46"
47fi
48
49# Add a comment if we have anything.
50if [ -n "$int32" ] || [ -n "$uint32" ] ; then
51    magic="/* The necessary preprocessor magic to get int32_t and uint32_t. */
52$magic"
53fi
54
55# We now have the full magic string.  Generate webauth/defines.h from
56# webauth/defines.h.in.
57sed '/@WEBAUTH_INT32_MAGIC@/q' "$1" | sed '/@WEBAUTH_INT32_MAGIC@/d' > "$2"
58echo "$magic" >> "$2"
59sed '1,/@WEBAUTH_INT32_MAGIC@/d' "$1" >> "$2"
60