File: configure

package info (click to toggle)
ztex-bmp 20120314-2
  • links: PTS, VCS
  • area: main
  • in suites: bullseye, jessie-kfreebsd, sid
  • size: 324 kB
  • ctags: 184
  • sloc: pascal: 1,767; sh: 208; makefile: 75
file content (245 lines) | stat: -rwxr-xr-x 5,928 bytes parent folder | download
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
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
#!/bin/bash
# Makefile.config -- script for automatic configuration of Makefile variables
# Copyright (C) 2002-2003 Stefan Ziegenbalg

configfile=Makefile.conf

# nice output routines
#    \033          is just ascii ESC
#    \033[<NUM>G   move to column <NUM>
#    \033[1m       switch bold on
#    \033[31m      switch red on
#    \033[32m      switch green on
#    \033[33m      switch yellow on
#    \033[m        switch color/bold off
echo_red () {
    echo -e "\033[31m\033[1m$1\033[m" >&2
}

echo_green () {
    echo -e "\033[32m$1\033[m" >&2
}

echo_yellow () {
    echo -e "\033[33m\033[1m$1\033[m" >&2
}

# read config file 
readconfig () {
    result="-"
    read var par
    while [ "$result" = "-" -a "$var" != "" ]; do
	[ "$var" = "$1" ] && result=$par
	read var par
    done
    echo $result
}
 
# remove temporay files 
rmtmp () {
    rm -f $tmpfile $tmpfile.*
}

# checks coompilinmg + running
# $1 compiler command + flags
# $2 test file (without .pas) 
checkcr () {
    echo "$1 $2" >> $tmpfile.log
    $1 $2 >> $tmpfile.log 2>> $tmpfile.log
    if [ "$?" = "0" ]; then
      echo "./$2" >> $tmpfile.log
      ./$2
    else 
      return 1  
    fi
}

# checks command
findexec () {
    result=""
    for i; do
      if [ "$result" = "" ]; then
        if [ "${i#*/}" = "$i" ]; then 
    	    which $i >> $tmpfile.log 2>> $tmpfile.log
	    [ "$?" = "0" ] && result=$i
	else
	    [ -x $i -a ! -d $i ] && result=$i
	fi
      fi	
    done
    echo $result
}


failure () {
    echo -n $failreturn
    exit 1
}    

#####################
##### main part #####
#####################
failreturn=""
case "$1" in
  "pc2") cmd=pc; failreturn="ppc386" ;;
  "install2") cmd=install; failreturn="install" ;;
  "findexec2") cmd=findexec; failreturn=${2%% *} ;;
  *) cmd=$1 ;;
esac

case "$cmd" in
    "findexec")	 varname=$cmd_$2 ;;
    "have_unit") varname=have_$3 ;;
    "unit_flags") varname=$3"_flags" ;;
    *) varname=$cmd ;;
esac
tmpfile="conf_$varname"

result="-"
[ -f $configfile -a "$varname" != "" ] && result=`readconfig $varname < $configfile` 

if [ "$result" != "-" ]; then
    echo $result
    exit 0
fi

result=""
rm -f $tmpfile.log
case "$cmd" in
    "pc")
        echo -n "Checking for freepascal compiler (FLAGS=\"$2\"): " >&2
	echo -e "begin\nend." > $tmpfile.pas
	for i in ppc386 fpc pc $3; do
	    if [ "$result" = "" ]; then
    		if [ "${i#*/}" = "$i" ]; then 
    		    which $i >> $tmpfile.log 2>> $tmpfile.log
		    [ "$?" = "0" ] && checkcr "$i $2" $tmpfile && result=$i
		else
		    [ -x $i -a ! -d $i ] && checkcr "$i $2" $tmpfile && result=$i
		fi
            fi
	done       
	if [ "$result" != "" ]; then
	    echo_green "$result"
	    rmtmp
	else 
	  echo_red "not found"
	  failure
	fi
    ;;  
    "install")
        echo -n "Checking for install command: " >&2
	result=`findexec install ginstall $2`
	if [ "$result" != "" ]; then
	    echo_green "$result"
	    rmtmp
	else 
	  echo_red "not found"
	  failure
	fi
    ;;
    "have_unit" | "unit_flags" )
        echo -n "Checking for $3 unit: " >&2
	echo -e "uses $3;\nbegin\nend." > $tmpfile.pas
	for i in $4 " "; do
	  if [ "$result" = "" ]; then
	    if [ "$i" = " " ]; then
     	      checkcr "$2" $tmpfile && result=$i
	    else   
     	      [ -f $i/$3.ppu ] && checkcr "$2 -Fu$i" $tmpfile && result=$i
	    fi
	  fi       
	done
	if [ "$result" != "" ]; then 
	  if [ "$result" = " " ]; then
	    echo_green "available"
	  else
	    echo_green "$result"
	    result="-Fu$result"
	  fi    
	  if [ "$1" = "have_unit" ]; then
            echo "$3""_flags $result" >> $configfile 
	    result=1
	  else 
            echo "have_$3 1" >> $configfile 
	  fi
	  rmtmp
	else 
	  echo_yellow "not available"
          echo "$3""_flags " >> $configfile 
	  if [ "$1" = "have_unit" ]; then
	    result=0
	  else 
            echo "have_$3 0" >> $configfile
	    failure	  
	  fi
	fi
    ;;  
    "optalign")
        echo -n "Checking for -Oa flag: " >&2
	echo -e "begin\nend." > $tmpfile.pas
	checkcr "$2 -Oa" $tmpfile
	if [ "$?" = "0" ]; then 
	  echo_green "works"
	  result=1
	  rmtmp
	else 
	  echo_yellow "failed"
	  result=0
	fi
    ;;  
    "findexec")
        echo -n "Checking for $2: " >&2
	result=`findexec $3`
	if [ "$result" != "" ]; then
	    echo_green "$result"
	    rmtmp
	else 
	  echo_red "not found"
	  failure
	fi
    ;;
    *)
	echo "$0 -- script for automatic configuration of Makefile variables"
	echo
	echo
	echo "    !! Run make to build the project or run ./update to update the Makefile (e.g. after changing sources)!!"
	echo
	echo
	echo "Usage: $0 <variable> [options]"
	echo ""
	echo "variables:"
	echo "  pc [compiler flags [additional compilers]]"
	echo " 	  checks for freepascal compiler, returns \"\" on failure"
	echo ""
	echo "  pc2 [compiler flags [additional compilers]]"
	echo " 	  as above, but ppc386 is returned on failure"
	echo ""
	echo "  install [additonal commands]"
	echo "    checks for install command, returns \"\" on failure"
	echo ""
	echo "  install2 [additonal commands]"
	echo "    as above, but install is returned on failure"
	echo ""
	echo "  have_unit <compiler command> <unit name> [<alternate locations>]"
	echo "    checks whether <unit list> is available; returns 0 on failure, 1 on success; unit list must be coma separated"
	echo ""
	echo "  unit_flags <compiler command> <name of unit package> <unit list> [<alternate locations>]"
	echo "    as above, but returns \"-ul<location>\" if unit found in [<alternate locations>]"
	echo ""
	echo "  optalign <compiler command>"
	echo "    checks whether -Oa flag works"
	echo ""
	echo "  findexec <name> <list variants>"
	echo "    checks for existing executable in <list variants>"
	echo ""
	echo "  findexec2 <name> <list variants>"
	echo "    as above, but first variant is returned on failure"
	echo ""
	exit 1
    ;;
esac	

[ "$result" != "" -a "$varname" != "" ] && echo "$varname $result" >> $configfile 
echo $result