forked from mangband/mangband
-
Notifications
You must be signed in to change notification settings - Fork 0
/
autogen.sh
executable file
·188 lines (170 loc) · 5.12 KB
/
autogen.sh
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
#!/bin/sh
# Greet user.
echo "MAngband Autogen/Helper"
# Use getopt(s) to fetch flags.
usage=0; norma=0; devel=0; distr=0; clean=0;
force=0; verbo=0; autoc=0; gitdl=0;
# you can use either line depending of getopt(s) availiablity
#flags=`getopt hndrcfva $*`; set -- $flags; for flag; do
while getopts "hndrcfva" flag; do flag="-$flag"
case "$flag" in
-\? ) usage=1 ;;
-h ) usage=1 ;;
-n ) norma=1 ;;
-d ) devel=1 ;;
-r ) distr=1 ;;
-c ) clean=1 ;;
-f ) force=1 ;;
-v ) verbo=1 ;;
-a ) autoc=1 ;;
-- ) break ;;
esac
done
# Detect .git checkout
if [ -d .git ]; then
echo " * Seeing .git, course-correcting."
#cat README
gitdl=1;
fi
# Test flags for errors
TMODE=$((${norma} + ${devel} + ${distr} + ${clean} + ${usage}));
#echo "NDR: $TMODE N: $norma D: $devel R: $distr C: $clean V: $verbo F: $force A: $autoc V: $verbo ?: $usage"
if [ ${TMODE} -eq 0 ]; then
echo " * No mode specified. Try -h flag to find out more!"
norma=1;
if [ ${gitdl} -eq 1 ]; then
norma=0;
echo "--FAILED"
echo "Please specify one of the -n, -d, -r options explicitly. See -h for details."
#usage=1;
exit 1
fi
fi
if [ ${TMODE} -ge 2 ]; then
echo " -- FAILED"
echo " The -n, -d, -r, -c and -h flags are in conflict. See -h for details:"
usage=1;
fi
# Display help and exit
if [ "$usage" = "1" ]; then
echo "Usage: ./autogen.sh [MODE] [OPTION]"
echo " MODE flag selects the task:"
echo " -n NORMAL mode. Will run autotools to create a './configure' script."
echo " (default) "
echo " -d DEBUG/DEVELOPER mode. Similar to NORMAL, but, several hacks are added"
echo " to the config file, allowing MAngband to run from 'current' directory."
echo " NOTE: Using it makes your working copy unsuitable for release !"
echo " -r RELEASE mode. Prepares the package for distribution."
echo " -c CLEANING mode. Pretty useless. Deletes excessive autotool files."
echo " -h HELP mode. Displays this message and exits."
echo " OPTION flags control mode behavior:"
echo " -f Force download of latest GNU config.* files."
echo " -v Verbose logging - display additional information."
echo " -a Automaticly invoke ./configure when it's ready."
exit 0
fi
# Select logger
if [ "$verbo" = "1" ]; then
echo " * Verbose logging enabled"
VLOG="/dev/stdout"
else
VLOG="/dev/null"
fi
# Auto-configure when Releasing
[ "$distr" = "1" ] && autoc=1
# Auto-force when Cleaning
[ "$clean" = "1" ] && force=1
# Show some info
[ "$norma" = "1" ] && echo " * Using NORMAL mode"
[ "$devel" = "1" ] && echo " * Using DEVELOPER mode"
[ "$distr" = "1" ] && echo " * Using RELEASE mode"
[ "$clean" = "1" ] && echo " * Using CLEANING mode"
#echo " * Using $1 mode."
# Delete downloadable files
if [ "$force" = "1" ]; then
echo " * Removing 'config.sub' and 'config.guess'"
rm ./config.sub
rm ./config.guess
fi
# Delete generated files
if [ "$clean" = "1" ]; then
echo " * Removing makefiles"
find . -name "Makefile.in" -exec rm {} \;
find . -name "Makefile" -exec rm {} \;
echo " * Removing various generated files"
rm aclocal.m4
rm src/config.h
rm config.h
rm stamp-h1
rm config.log
rm config.status
rm install-sh
rm missing
rm depcomp
exit 0
fi
HAS_WGET=`which wget`
HAS_CURL=`which curl`
download_file() {
NAME=$1
URL=$2
if [ "$HAS_WGET" != "" ]; then
wget -O "$NAME" "$URL" >${VLOG} 2>${VLOG}
elif [ "$HAS_CURL" != "" ]; then
curl -o "$NAME" "$URL" >${VLOG} 2>${VLOG}
else
"No wget, no curl, can't download file $NAME"
return 1
fi
return $?
}
# Update GNU config.* files
[ -f ./config.sub ] || {
echo " * Downloading 'config.sub' from GNU.org";
download_file "config.sub" "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.sub;hb=HEAD" ||
echo " -- FAILED"; }
[ -f ./config.guess ] || {
echo " * Downloading 'config.guess' from GNU.org";
download_file "config.guess" "http://git.savannah.gnu.org/gitweb/?p=config.git;a=blob_plain;f=config.guess;hb=HEAD" ||
echo " -- FAILED"; }
# The real purpose of autogen:
echo " * Running 'autoreconf -i'"
autoreconf -i >${VLOG} 2>${VLOG} || { echo " -- FAILED"; exit 1; }
# Prepare for debug
if [ "$devel" = "1" ]; then
echo " * Preparing debug environment"
CFG="./mangband.cfg"
TMP="./$(basename $0).$$.tmp"
sed "/*\{0,3\}\(BONE\|EDIT\|DATA\|SAVE\|USER\|HELP\)_DIR = /d" ${CFG} > ${TMP}
echo "EDIT_DIR = \"./lib/edit\"" >> ${TMP}
echo "DATA_DIR = \"./lib/data\"" >> ${TMP}
echo "SAVE_DIR = \"./lib/save\"" >> ${TMP}
echo "BONE_DIR = \"./lib/user\"" >> ${TMP}
echo "HELP_DIR = \"./lib/help\"" >> ${TMP}
mv ${TMP} ${CFG}
CFG="${HOME}/.mangrc"
TMP="./$(basename $0).$$.tmp"
sed "/\(LibDir \|\[MAngband\]\)/d" ${CFG} > ${TMP}
echo "[MAngband]" > ${HOME}/.mangrc
echo "LibDir ./lib/" >> ${HOME}/.mangrc
cat ${TMP} >> ${HOME}/.mangrc
fi
# Auto-run configure
if [ "$autoc" = "1" ]; then
echo " * Running './configure'"
./configure >${VLOG} 2>${VLOG} || { echo " -- FAILED"; exit 1; }
fi
# Prepare release
if [ "$distr" = "1" ]; then
echo " * Running 'make dist'"
make dist >${VLOG} 2>${VLOG} || { echo " -- FAILED"; exit 1; }
echo -n " * Ready! "
ls *.tar.gz
exit 0
fi
# DONE
if [ "$autoc" = "1" ]; then
echo " * Ready!"
else
echo " * Ready! You can use './configure' now!"
fi