posaune
[projects.git] / tools / make / mconfigure
1 #!/bin/bash
2 set -e
3
4 function echo_usage {
5         echo "usage: mconfigure [options] <package>"
6         echo "  -o: old style build (not recommended"
7         ./configure -h
8 }
9
10 function create_conf {
11         if [ -f "debian/$paket.cmake" ]
12         then
13                 echo "compile_type=CMAKE" > debian/$paket.conf
14         elif [ -f "debian/$paket.build" ]
15         then
16                 if [ -f "debian/$paket.cpp" ]
17                 then
18                         echo "compile_type=CPP" > debian/$paket.conf
19                 else
20                         echo "compile_type=ANY" > debian/$paket.conf
21                 fi
22         else
23                 echo "compile_type=NONE" > debian/$paket.conf
24         fi
25         
26         if [ -f "$paket.control" -a -f "$paket.cp" ]
27         then
28                 echo "target_type=DEB" >> debian/$paket.conf
29         else
30                 echo "target_type=FILE" >> debian/$paket.conf
31         fi
32         echo "$paket.conf created."
33 }
34
35 ##############################################################################
36 # Main program
37 ##############################################################################
38
39 if [ ! -d debian ]
40 then
41         echo "run mconfigure in the project base directory with a debian directory in it!"
42         exit 2
43 fi
44
45 configure=0
46 configure_args="-i debian/tmp"
47 while [ $OPTIND -le "$#" ]
48 do
49         if getopts "o" opt
50         then
51                 case $opt in
52                         o) old_build=1
53                                 ;;
54                         \?) $confirure_args="$configure_ars -$OPTARG"
55                                 if [ $OPTARG="a" -o $OPTARG="C" -o $OPTARG="i" -o $OPTARG="v" ]
56                                 then
57                                         eval OPTIND=OPTIND+1
58                                         $confirure_args="$configure_ars ${!OPTIND}"
59                                 fi
60                                 ;;
61                         :) echo "Option -$OPTARG requires an argument."
62                                 echo_usage
63                                 exit 3
64                                 ;;
65                 esac
66         else
67                 paket="${!OPTIND}"
68                 eval OPTIND=OPTIND+1
69         fi
70 done
71
72 if [ -z "$paket" ]
73 then
74         echo_usage
75         exit 4
76 fi
77
78 if [ ! -f debian/$paket.conf ]
79 then
80         # check if any files for $paket are present
81         if ! ls debian/$paket.* 2>/dev/null
82         then
83                 echo "$paket is no build target in this repository."
84                 exit 5
85         fi
86         
87         # build conf file
88         echo "$paket.conf missing. We create it ..."
89         create_conf
90 fi
91
92 if [ ! -e configure ]
93 then
94         ln -s /usr/share/mbuild/configure .
95 fi
96
97 # clean build directory
98 if [ "$compile_type" != "NONE" ]
99 then
100         if [ -e ~/build ]
101         then
102                 rm -rf ~/build
103                 mkdir ~/build
104         fi
105         configure_args="$configure_args -d ~/build"
106 fi
107
108 # perform configure
109 . debian/$paket.conf
110 if [ -n "$old_build" ]
111 then
112         rm debian/$paket.conf
113 fi
114
115 if [ "$compile_type" != "NONE" ]
116 then
117         configure_args="$configure_args -b"
118         if [ -n "$compile_dir" ]
119         then
120                 configure_args="$configure_args -d $compile_dir"
121         fi
122         if [ -z "$compile_type" ]
123         then
124                 echo "compile_type required in $paket.conf"
125                 exit 51
126         fi
127         configure_args="$configure_args -c $compile_type"
128         if [ -z "$compile_target" ]
129         then
130                 echo "compile_target required in $paket.conf"
131                 exit 52
132         fi
133         configure_args="$configure_args -e $compile_target"
134 fi
135 if [ "$target_type" == "FILE" ]
136 then
137         # no version needed
138         configure_args="$configure_args -V"
139 fi
140 configure_args="$configure_args $paket"
141 echo "Executing ./configure $configure_args ..."
142 ./configure $configure_args
143
144 if [ "$compile_type" != "NONE" ]
145 then
146         if grep -- "-prepare" debian/$paket.build >/dev/null
147         then                    
148                 echo "prepare in <paket>.build no longer supported. Use <paket>.prebuild"
149                 exit 6
150         fi
151         # sync build dir
152         . debian/setenv.sh
153         debian/rules sync
154         make
155 fi
156
157 # pack prepare
158 if [ "$target_type" == "DEB" ]
159 then
160         if [ ! -f debian/$paket.cp ]
161         then
162                 echo "debian/$paket.cp missing for target type DEB"
163                 exit 9
164         fi
165         if [ ! -f debian/$paket.control ]
166         then
167                 echo "debian/$paket.control missing for target type DEB"
168                 exit 10
169         fi
170         
171         echo "PACK=binary" >> debian/rules.pre
172         if grep "^Architecture: *all" debian/$paket.control >/dev/null
173         then
174                 echo "arch = all" >> debian/rules.pre
175                 echo 'BINARY_INDEP = copy ../$(paket)_$(version)-$(build)_all.deb' >> debian/rules.pre
176         else
177                 echo 'arch = ${DEB_HOST_ARCH}' >> debian/rules.pre
178                 echo "BINARY_ARCH = copy ../${paket}_$version-${build}_"'$(arch).deb' >> debian/rules.pre
179         fi
180         if ! [ -f debian/$paket.changelog ]
181         then
182                 echo "changelog_source = debian/default.changelog" >> debian/rules.pre
183                 if [ -f debian/default.changelog ]
184                 then
185                         rm debian/default.changelog
186                 fi
187         fi
188 elif [ "$target_type" == "ZIP" ]
189 then
190         echo "PACK=zip" >> debian/rules.pre
191         if [ ! -f debian/$paket.cp ]
192         then
193                 echo "debian/$paket.cp missing for target type ZIP"
194                 exit 11
195         fi
196 elif [ "$target_type" == "FILE" ]
197 then
198         echo "PACK=version" >> debian/rules.pre
199         if [ "$compile_type" != "ANY" ]
200         then
201                 if [ -z "$compile_target" ]
202                 then
203                         echo "compile_target is needed for target_type FILE"
204                         exit 12
205                 fi
206                 echo "COMPILE_TARGET = $compile_target" >> debian/rules.pre
207                 if [ -n "$target_name" ]
208                 then
209                         echo "TARGET = $target_name" >> debian/rules.pre
210                 else
211                         echo "TARGET = $paket" >> debian/rules.pre
212                 fi
213         fi
214 else
215         echo "Unknown target type: $target_type"
216         exit 13
217 fi
218
219 # build package
220 debian/rules pack
221
222