summaryrefslogtreecommitdiff
path: root/configure
blob: 793e347b839afbee94dffe3e97bf56090b5f78ce (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
#!/bin/sh
# rvs configureation script
# 
# Copyright (C) 2009 Luke Shumaker
# 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.
# 
# Originally written by Luke Shumaker <lukeshu@sbcglobal.net>.

sourcedir=`dirname "$0"`
pre='./var.sed'

while [ $# -gt 0 ]; do case "$1" in
	--*)
		var0=`echo "$1" | sed -e 's/^--//' -e 's/=.*$//'`
		match='false'
		while read line; do
			var1=`echo "$line" | cut -f 1 `
			if [ "$var0" == "$var1" ]; then
				match='true'
				break;
			fi
		done < Variables
		if [ "$match" == 'false' ]; then
			echo "configure: option \`$1' not recognized"
			exit 255;
		else
			val=`echo "$1" | sed -e "s/^--$var0=//"`
			eval _$var0=$val
		fi
		:;;
	*) echo "configure: option \`$1' not recognized"; exit 255;;
	esac
	shift
done

echo '#!/bin/sed -f' > "$pre"
while read line; do
	var=`echo "$line" | cut -f 1 `
	val=$(eval echo `echo "$line" | cut -f 2-`) # load from Variables file
	val=$(eval echo '${'`echo _$var`-$val'}')   # check for option overide
	
	# evaluate the values, so that we may use env variables as values
	# escape slashes, as they cause problems for sed
	var=`echo "$var" | sed 's:/:\\\\/:g'`
	val=`echo "$val" | sed 's:/:\\\\/:g'`
	
	echo       's/$$'"${var}"'$\$/'"${val}"'/' >> "$pre"
	#sed -i.bak 's/$$'"${var}"'$\$/'"${val}"'/' "$files"
	unset var val
done < "$sourcedir/Variables"

chmod +x "$pre"
"$pre" < "$sourcedir/Makefile.orig" > Makefile

n0='# DO NOT edit this file, it has been generated by configure, and will be'
n1='# overwritten. Instead, edit the file `Makefile.orig'\'
sourcedir=`echo "$sourcedir" | sed 's:/:\\\\/:g'`
      pre=`echo "$pre"       | sed 's:/:\\\\/:g'`
sed -i \
-e "10 a$n0" \
-e "10 a$n1" \
-e "s/@@sourcedir@@/$sourcedir/" \
-e "s/@@pre@@/$pre/" \
Makefile