gitarre
[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=OLD" > 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 -b"
103 fi
104
105 # perform configure
106 . debian/$paket.conf
107 if [ -n "$compile_dir" ]
108 then
109         configure_args="$configure_args -b $compile_dir"
110 fi
111 if [ -z "$compile_type" ]
112 then
113         echo "compile_type required in $paket.conf"
114         exit 51
115 fi
116 if [ "$target_type" == "FILE" ]
117 then
118         # no version needed
119         configure_args="$configure_args -V"
120 fi
121 configure_args="$configure_args $paket"
122 echo "Executing ./configure $configure_args ..."
123 ./configure $configure_args
124
125 if [ "$compile_type" != "NONE" ]
126 then
127         if grep -- "-prepare" debian/$paket.build >/dev/null
128         then                    
129                 echo "prepare in <paket>.build no longer supported. Use <paket>.prebuild"
130                 exit 6
131         fi
132         # sync build dir
133         . debian/setenv.sh
134         debian/rules sync
135         make
136 fi
137
138 # pack prepare
139 if [ "$target_type" == "DEB" ]
140 then
141         if [ ! -f debian/$paket.cp ]
142         then
143                 echo "debian/$paket.cp missing for target type DEB"
144                 exit 9
145         fi
146         if [ ! -f debian/$paket.control ]
147         then
148                 echo "debian/$paket.control missing for target type DEB"
149                 exit 10
150         fi
151         
152         echo "PACK=binary" >> debian/rules.pre
153         if grep "^Architecture: *all" debian/$paket.control >/dev/null
154         then
155                 echo "arch = all" >> debian/rules.pre
156                 echo 'BINARY_INDEP = copy ../$(paket)_$(version)-$(build)_all.deb' >> debian/rules.pre
157         else
158                 echo 'arch = ${DEB_HOST_ARCH}' >> debian/rules.pre
159                 echo "BINARY_ARCH = copy ../${paket}_$version-${build}_"'$(arch).deb' >> debian/rules.pre
160         fi
161         if ! [ -f debian/$paket.changelog ]
162         then
163                 echo "changelog_source = debian/default.changelog" >> debian/rules.pre
164                 if [ -f debian/default.changelog ]
165                 then
166                         rm debian/default.changelog
167                 fi
168         fi
169 elif [ "$target_type" == "ZIP" ]
170 then
171         echo "PACK=zip" >> debian/rules.pre
172         if [ ! -f debian/$paket.cp ]
173         then
174                 echo "debian/$paket.cp missing for target type ZIP"
175                 exit 11
176         fi
177 elif [ "$target_type" == "FILE" ]
178 then
179         echo "PACK=version" >> debian/rules.pre
180         if [ "$compile_type" != "OLD" ]
181         then
182                 if [ -z "$compile_target" ]
183                 then
184                         echo "compile_target is needed for target_type FILE"
185                         exit 12
186                 fi
187                 echo "TARGET = $compile_target" >> debian/rules.pre
188         fi
189 else
190         echo "Unknown target type: $target_type"
191         exit 13
192 fi
193
194 # build package
195 debian/rules pack
196