gitarre
[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 fi
129 if [ "$target_type" == "FILE" ]
130 then
131         # no version needed
132         configure_args="$configure_args -V"
133 fi
134 configure_args="$configure_args $paket"
135 echo "Executing ./configure $configure_args ..."
136 ./configure $configure_args
137
138 if [ "$compile_type" != "NONE" ]
139 then
140         if grep -- "-prepare" debian/$paket.build >/dev/null
141         then                    
142                 echo "prepare in <paket>.build no longer supported. Use <paket>.prebuild"
143                 exit 6
144         fi
145         # sync build dir
146         . debian/setenv.sh
147         debian/rules sync
148         make
149 fi
150
151 # pack prepare
152 if [ "$target_type" == "DEB" ]
153 then
154         if [ ! -f debian/$paket.cp ]
155         then
156                 echo "debian/$paket.cp missing for target type DEB"
157                 exit 9
158         fi
159         if [ ! -f debian/$paket.control ]
160         then
161                 echo "debian/$paket.control missing for target type DEB"
162                 exit 10
163         fi
164         
165         echo "PACK=binary" >> debian/rules.pre
166         if grep "^Architecture: *all" debian/$paket.control >/dev/null
167         then
168                 echo "arch = all" >> debian/rules.pre
169                 echo 'BINARY_INDEP = copy ../$(paket)_$(version)-$(build)_all.deb' >> debian/rules.pre
170         else
171                 echo 'arch = ${DEB_HOST_ARCH}' >> debian/rules.pre
172                 echo "BINARY_ARCH = copy ../${paket}_$version-${build}_"'$(arch).deb' >> debian/rules.pre
173         fi
174         if ! [ -f debian/$paket.changelog ]
175         then
176                 echo "changelog_source = debian/default.changelog" >> debian/rules.pre
177                 if [ -f debian/default.changelog ]
178                 then
179                         rm debian/default.changelog
180                 fi
181         fi
182 elif [ "$target_type" == "ZIP" ]
183 then
184         echo "PACK=zip" >> debian/rules.pre
185         if [ ! -f debian/$paket.cp ]
186         then
187                 echo "debian/$paket.cp missing for target type ZIP"
188                 exit 11
189         fi
190 elif [ "$target_type" == "FILE" ]
191 then
192         echo "PACK=version" >> debian/rules.pre
193         if [ "$compile_type" != "ANY" ]
194         then
195                 if [ -z "$compile_target" ]
196                 then
197                         echo "compile_target is needed for target_type FILE"
198                         exit 12
199                 fi
200                 echo "COMPILE_TARGET = $compile_target" >> debian/rules.pre
201                 if [ -n "$target_name" ]
202                 then
203                         echo "TARGET = $target_name" >> debian/rules.pre
204                 else
205                         echo "TARGET = $paket" >> debian/rules.pre
206                 fi
207         fi
208 else
209         echo "Unknown target type: $target_type"
210         exit 13
211 fi
212
213 # build package
214 debian/rules pack
215