summaryrefslogtreecommitdiff
path: root/config/mk-shdefs.in
blob: aa388ccc7fffa528e1b184f40634e8e43c4ee318 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
#! @CONFIG_SHELL@
# -*- Mode: shell-script -*-

die() {
    echo "$prog fatal error:  $*"
    kill -TERM $progpid
    exit 1
} >&2

init() {
    prog=`basename $1 .sh`
    progpid=$$

    SED='@SED@'
    AWK='@AWK@'
    GREP='@GREP@'
    EGREP='@EGREP@'
    target=`basename $2`
    builddir=`dirname $2`
    builddir=`cd $builddir && pwd`
    srcdir=`dirname $1`
    srcdir=`cd $srcdir >/dev/null && pwd`

    cd ${builddir} || die no builddir

    # top_builddir may be relative to the build directory that corresponds
    # to the source directory for this file.  Make it absolute
    #
    top_builddir=`cd @top_builddir@ >/dev/null && pwd`
    top_srcdir=`
        cd ${builddir} >/dev/null && cd @top_srcdir@ >/dev/null && pwd`

    rm -f ${target}
    exec 3> shdef-temp.in || die cannot create output
    cd ..
}

mk_config() {
    cat >&3 <<- _EOF_
	prefix='@prefix@'
	exec_prefix="@exec_prefix@"
	PACKAGE_TARNAME='@PACKAGE_TARNAME@'
	_EOF_

    # Skip the stuff we force to be first
    #
    skip_list='top_srcdir|top_builddir|prefix|exec_prefix|PACKAGE_TARNAME'

    # skip the autoconf/automake internal names
    #
    skip_list=${skip_list}"|a[mc]_.*|.*_TRUE|.*_FALSE|HAVE_.*|AM*"

    # These must be in the correct order.  Ensure it and don't do 'em twice
    #
    eval_fmt='eval "%s=\\"@%s@\\""\n'
    for v in datarootdir mandir localedir infodir docdir datadir \
        libdir libexecdir sbindir bindir \
        includedir localstatedir sharedstatedir sysconfdir oldincludedir
    do  printf "${eval_fmt}" $v $v
        skip_list=${skip_list}"|$v"
    done >&3

    for f in `${GREP} '^S\["' config.status`
    do
        v=`echo "$f" | ${SED}   's/".=.*//;s/[SD]\["//'`
        x=`echo "$v" | ${EGREP} "^($skip_list)\$"`
        test "X$x" = X || continue

        case "$f" in
        *'$('* ) : ;; # no make file only substitutions
        *'missing --run '* ) : ;; # no bootstrap tools
        S*\$* )  printf "${eval_fmt}" $v $v ;;
        S*    )  echo   "$v='@$v@'" ;;
        esac
    done >&3

    exec 3>&-
}

configure() {
    cd config

    ../config.status --file shdef-temp
    {
        cmd='`set -o | '${AWK}" '/^allexport/ {print \$2}'"\`
        cat <<- _EOF_
		#! `which echo` this-file-should-be-sourced,-not-executed
		# -*- Mode: shell-script -*-

		case "$cmd" in
		on  ) cleara=: ;;
		*   ) cleara='set +a' ; set -a ;;
		esac

		top_srcdir="$top_srcdir"
		top_builddir="$top_builddir"
		_EOF_

        cat shdef-temp
        echo 'eval $cleara'
    } > ${target}

    rm -f shdef-temp*
}

init $0 $1
mk_config
configure