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