File: configure

package info (click to toggle)
magicrescue 1.1.10-4
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 1,180 kB
  • sloc: ansic: 1,948; perl: 1,735; sh: 334; makefile: 70
file content (209 lines) | stat: -rwxr-xr-x 4,310 bytes parent folder | download | duplicates (3)
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
#!/bin/sh

# This is a flexible yet simple configure script that can be used instead of
# GNU autoconf for simple projects written in C. It depends on the file
# config.config for application-specific globals and the files in config.d/ for
# tests to perform.


# Copyright (C) 2004 Jonas Jensen <jbj@knef.dk>
# 
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
# as published by the Free Software Foundation; either version 2
# of the License, or (at your option) any later version.
# 
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
# 
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.

#
# Default options
#
app="the application"
prefix=/usr/local
env_vars="CC CFLAGS CPPFLAGS LDFLAGS"
def_CC=cc
def_CFLAGS="-O3 -Wall"
MAKE_VARS=

if [ -f config.config ]; then
    . ./config.config
fi

#
# Helper functions
#

echo1() { echo $ECHO_N "$* $ECHO_C"; }
echo2() { echo "$ECHO_T$*"; }

conftest() {
    conftest_compile && conftest_link
}

conftest_compile() {
    cat >&5 << EOF

Compiling:
---------------------------
EOF
    cat conftest.c >&5
    echo "---------------------------" >&5
    echo "$CC -c $CPPFLAGS $CFLAGS -o conftest.o conftest.c" >&5

    rm -f conftest.o
    $CC -c $CPPFLAGS $CFLAGS -o conftest.o conftest.c >&5 2>&5 \
	&& [ -f conftest.o ]
}

conftest_link() {
    echo "$CC -o conftest conftest.o $LDFLAGS" >&5
    echo >&5
    $CC -o conftest conftest.o $LDFLAGS >&5 2>&5 \
	&& [ -x conftest ] && ./conftest 2>&5
}

conftest_define() {
    echo1 "$2"
    if conftest; then
	echo "#define $1 1" >> config.h
	echo2 "yes"
	return 0
    else
	echo2 "no"
	return 1
    fi
}

#
# Initialize
#
exec 5>config.log
date >&5

[ -d config.d ] || {
    echo "Directory config.d not found. Run configure from the source root."
    exit 1
}

if mv -f config.h config.h.bak 2>/dev/null; then
    trap "mv config.h.bak config.h" 0
fi
cat > config.h << EOF
/* XXX This file was automatically generated by configure. */

EOF

#
# Environment
#
for var in $env_vars; do
    eval "$var=\${$var:-\$def_$var}"
done

#
# Parse arguments
#
for option do
    case "$option" in

    --help)
	cat << EOF
This will configure $app for your system.

Options:
  --prefix=DIR    Path to install under [$prefix]
  CC=COMMAND      C compiler to use [$CC]
  CFLAGS=OPTIONS  C compiler flags [$CFLAGS]
EOF
	exit
	;;

    --strict)
	CFLAGS="$CFLAGS -std=c9x -W -Wshadow -Wpointer-arith -Wstrict-prototypes -Wmissing-prototypes -Wredundant-decls"
	echo "#define _POSIX_C_SOURCE 200112L" >> config.h
	echo "#define _XOPEN_SOURCE 600" >> config.h
	;;

    --*=*)
	arg=`echo "$option"|cut -d= -f 2-`
	case "$option" in
	--prefix=*)
	    prefix="$arg"
	    ;;
	*)
	    echo "configure: warning: ignoring option $option"
	    ;;
	esac
	;;

    *=*)
	#export "$option" # doesn't work on Solaris

	var=`echo "$option"|cut -d= -f 1`
	arg=`echo "$option"|cut -d= -f 2-`
	eval "$var='$arg'"
    esac
done

#
# Do tests
#

# echo test, stolen from GNU autoconf. This really shows UNIX at its worst...
case `echo "testing\c"; echo 1,2,3`,`echo -n testing; echo 1,2,3` in
  *c*,-n*) ECHO_N= ECHO_C='
' ECHO_T='	' ;;
  *c*,*  ) ECHO_N=-n ECHO_C= ECHO_T= ;;
  *)       ECHO_N= ECHO_C='\c' ECHO_T= ;;
esac

for f in config.d/*; do
    cat >&5 << EOF

configure: PERFORMING TEST $f

EOF
    . "$f"
done

#
# Clean up
#
trap "" 0
rm -f config.h.bak conftest.c conftest.o conftest

#
# Generate Makefile
#
make clean >/dev/null 2>&1

rm -f Makefile 2>/dev/null || chmod 644 Makefile
cat > Makefile << EOF
# XXX This Makefile is automatically generated by configure.
# XXX Modify Makefile.in to change it.

PREFIX = $prefix
EOF

for var in $env_vars $MAKE_VARS; do
    eval "val=\"\$$var\""
    echo "$var = $val" >> Makefile
done

cat "Makefile.in" >> Makefile
if [ -f Makefile.dep ]; then
    cat Makefile.dep >> Makefile
    rm -f Makefile.dep
fi

chmod 444 Makefile

echo
echo "Done. Now type 'make' to compile"