OpenCores
URL https://opencores.org/ocsvn/usb_fpga_2_04/usb_fpga_2_04/trunk

Subversion Repositories usb_fpga_2_04

[/] [usb_fpga_2_04/] [trunk/] [bmp/] [configure] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 ZTEX
#!/bin/bash
2
# Makefile.config -- script for automatic configuration of Makefile variables
3
# Copyright (C) 2002-2003 Stefan Ziegenbalg
4
 
5
configfile=Makefile.conf
6
 
7
# nice output routines
8
#    \033          is just ascii ESC
9
#    \033[G   move to column 
10
#    \033[1m       switch bold on
11
#    \033[31m      switch red on
12
#    \033[32m      switch green on
13
#    \033[33m      switch yellow on
14
#    \033[m        switch color/bold off
15
echo_red () {
16
    echo -e "\033[31m\033[1m$1\033[m" >&2
17
}
18
 
19
echo_green () {
20
    echo -e "\033[32m$1\033[m" >&2
21
}
22
 
23
echo_yellow () {
24
    echo -e "\033[33m\033[1m$1\033[m" >&2
25
}
26
 
27
# read config file
28
readconfig () {
29
    result="-"
30
    read var par
31
    while [ "$result" = "-" -a "$var" != "" ]; do
32
        [ "$var" = "$1" ] && result=$par
33
        read var par
34
    done
35
    echo $result
36
}
37
 
38
# remove temporay files
39
rmtmp () {
40
    rm -f $tmpfile $tmpfile.*
41
}
42
 
43
# checks coompilinmg + running
44
# $1 compiler command + flags
45
# $2 test file (without .pas)
46
checkcr () {
47
    echo "$1 $2" >> $tmpfile.log
48
    $1 $2 >> $tmpfile.log 2>> $tmpfile.log
49
    if [ "$?" = "0" ]; then
50
      echo "./$2" >> $tmpfile.log
51
      ./$2
52
    else
53
      return 1
54
    fi
55
}
56
 
57
# checks command
58
findexec () {
59
    result=""
60
    for i; do
61
      if [ "$result" = "" ]; then
62
        if [ "${i#*/}" = "$i" ]; then
63
            which $i >> $tmpfile.log 2>> $tmpfile.log
64
            [ "$?" = "0" ] && result=$i
65
        else
66
            [ -x $i -a ! -d $i ] && result=$i
67
        fi
68
      fi
69
    done
70
    echo $result
71
}
72
 
73
 
74
failure () {
75
    echo -n $failreturn
76
    exit 1
77
}
78
 
79
#####################
80
##### main part #####
81
#####################
82
failreturn=""
83
case "$1" in
84
  "pc2") cmd=pc; failreturn="ppc386" ;;
85
  "install2") cmd=install; failreturn="install" ;;
86
  "findexec2") cmd=findexec; failreturn=${2%% *} ;;
87
  *) cmd=$1 ;;
88
esac
89
 
90
case "$cmd" in
91
    "findexec")  varname=$cmd_$2 ;;
92
    "have_unit") varname=have_$3 ;;
93
    "unit_flags") varname=$3"_flags" ;;
94
    *) varname=$cmd ;;
95
esac
96
tmpfile="conf_$varname"
97
 
98
result="-"
99
[ -f $configfile -a "$varname" != "" ] && result=`readconfig $varname < $configfile`
100
 
101
if [ "$result" != "-" ]; then
102
    echo $result
103
    exit 0
104
fi
105
 
106
result=""
107
rm -f $tmpfile.log
108
case "$cmd" in
109
    "pc")
110
        echo -n "Checking for freepascal compiler (FLAGS=\"$2\"): " >&2
111
        echo -e "begin\nend." > $tmpfile.pas
112
        for i in ppc386 fpc pc $3; do
113
            if [ "$result" = "" ]; then
114
                if [ "${i#*/}" = "$i" ]; then
115
                    which $i >> $tmpfile.log 2>> $tmpfile.log
116
                    [ "$?" = "0" ] && checkcr "$i $2" $tmpfile && result=$i
117
                else
118
                    [ -x $i -a ! -d $i ] && checkcr "$i $2" $tmpfile && result=$i
119
                fi
120
            fi
121
        done
122
        if [ "$result" != "" ]; then
123
            echo_green "$result"
124
            rmtmp
125
        else
126
          echo_red "not found"
127
          failure
128
        fi
129
    ;;
130
    "install")
131
        echo -n "Checking for install command: " >&2
132
        result=`findexec install ginstall $2`
133
        if [ "$result" != "" ]; then
134
            echo_green "$result"
135
            rmtmp
136
        else
137
          echo_red "not found"
138
          failure
139
        fi
140
    ;;
141
    "have_unit" | "unit_flags" )
142
        echo -n "Checking for $3 unit: " >&2
143
        echo -e "uses $3;\nbegin\nend." > $tmpfile.pas
144
        for i in $4 " "; do
145
          if [ "$result" = "" ]; then
146
            if [ "$i" = " " ]; then
147
              checkcr "$2" $tmpfile && result=$i
148
            else
149
              [ -f $i/$3.ppu ] && checkcr "$2 -Fu$i" $tmpfile && result=$i
150
            fi
151
          fi
152
        done
153
        if [ "$result" != "" ]; then
154
          if [ "$result" = " " ]; then
155
            echo_green "available"
156
          else
157
            echo_green "$result"
158
            result="-Fu$result"
159
          fi
160
          if [ "$1" = "have_unit" ]; then
161
            echo "$3""_flags $result" >> $configfile
162
            result=1
163
          else
164
            echo "have_$3 1" >> $configfile
165
          fi
166
          rmtmp
167
        else
168
          echo_yellow "not available"
169
          echo "$3""_flags " >> $configfile
170
          if [ "$1" = "have_unit" ]; then
171
            result=0
172
          else
173
            echo "have_$3 0" >> $configfile
174
            failure
175
          fi
176
        fi
177
    ;;
178
    "optalign")
179
        echo -n "Checking for -Oa flag: " >&2
180
        echo -e "begin\nend." > $tmpfile.pas
181
        checkcr "$2 -Oa" $tmpfile
182
        if [ "$?" = "0" ]; then
183
          echo_green "works"
184
          result=1
185
          rmtmp
186
        else
187
          echo_yellow "failed"
188
          result=0
189
        fi
190
    ;;
191
    "findexec")
192
        echo -n "Checking for $2: " >&2
193
        result=`findexec $3`
194
        if [ "$result" != "" ]; then
195
            echo_green "$result"
196
            rmtmp
197
        else
198
          echo_red "not found"
199
          failure
200
        fi
201
    ;;
202
    *)
203
        echo "$0 -- script for automatic configuration of Makefile variables"
204
        echo
205
        echo
206
        echo "    !! Run make to build the project or run ./update to update the Makefile (e.g. after changing sources)!!"
207
        echo
208
        echo
209
        echo "Usage: $0  [options]"
210
        echo ""
211
        echo "variables:"
212
        echo "  pc [compiler flags [additional compilers]]"
213
        echo "    checks for freepascal compiler, returns \"\" on failure"
214
        echo ""
215
        echo "  pc2 [compiler flags [additional compilers]]"
216
        echo "    as above, but ppc386 is returned on failure"
217
        echo ""
218
        echo "  install [additonal commands]"
219
        echo "    checks for install command, returns \"\" on failure"
220
        echo ""
221
        echo "  install2 [additonal commands]"
222
        echo "    as above, but install is returned on failure"
223
        echo ""
224
        echo "  have_unit   []"
225
        echo "    checks whether  is available; returns 0 on failure, 1 on success; unit list must be coma separated"
226
        echo ""
227
        echo "  unit_flags    []"
228
        echo "    as above, but returns \"-ul\" if unit found in []"
229
        echo ""
230
        echo "  optalign "
231
        echo "    checks whether -Oa flag works"
232
        echo ""
233
        echo "  findexec  "
234
        echo "    checks for existing executable in "
235
        echo ""
236
        echo "  findexec2  "
237
        echo "    as above, but first variant is returned on failure"
238
        echo ""
239
        exit 1
240
    ;;
241
esac
242
 
243
[ "$result" != "" -a "$varname" != "" ] && echo "$varname $result" >> $configfile
244
echo $result
245
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.