dda9b97ffc319ed71f2c56050a378e93271d3757
[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 ##############################################################################
10 # Main program
11 ##############################################################################
12
13 if [ ! -d debian ]
14 then
15         echo "run mconfigure in the project base directory with a debian directory in it!"
16         exit 2
17 fi
18
19 configure=0
20 configure_args="-i debian/tmp"
21 while [ $OPTIND -le "$#" ]
22 do
23         if getopts "c" opt
24         then
25                 case $opt in
26                         \?) $confirure_args="$configure_ars -$OPTARG"
27                                 if [ $OPTARG="a" -o $OPTARG="C" -o $OPTARG="i" -o $OPTARG="v" ]
28                                 then
29                                         eval OPTIND=OPTIND+1
30                                         $confirure_args="$configure_ars ${!OPTIND}"
31                                 fi
32                                 ;;
33                         :) echo "Option -$OPTARG requires an argument."
34                                 echo_usage
35                                 exit 3
36                                 ;;
37                 esac
38         else
39                 paket="${!OPTIND}"
40                 eval OPTIND=OPTIND+1
41         fi
42 done
43
44 if [ -z "$paket" ]
45 then
46         echo_usage
47         exit 4
48 fi
49
50 if [ ! -f debian/$paket.conf ]
51 then
52         echo "$paket.conf missing. We create it ..."
53         echo "to be implemented ..."
54         exit 5
55 fi
56
57 if [ ! -e configure ]
58 then
59         ln -s /usr/share/mbuild/configure .
60 fi
61
62 # clean build directory
63 if [ "$compile_type" != "NONE" ]
64 then
65         if [ -e ~/build ]
66         then
67                 rm -rf ~/build
68                 mkdir ~/build
69         fi
70 fi
71
72 # perform configure
73 . debian/$paket.conf
74 if [ -n "$compile_dir" ]
75 then
76         configure_args="$configure_args -b $compile_dir"
77 fi
78 if [ -z "$compile_type" ]
79 then
80         echo "compile_type required in $paket.conf"
81         exit 51
82 fi
83 if [ "$target_type" == "FILE" ]
84 then
85         # no version needed
86         configure_args="$configure_args -V"
87 fi
88 configure_args="$configure_args $paket"
89 echo "Executing ./configure $configure_args ..."
90 ./configure $configure_args
91
92 if [ "$compile_type" != "NONE" ]
93 then
94         if grep -- "-prepare" debian/$paket.build >/dev/null
95         then                    
96                 echo "prepare in <paket>.build no longer supported. Use <paket>.prebuild"
97                 exit 6
98         fi
99         # sync build dir
100         . debian/setenv.sh
101         debian/rules sync
102         make
103 fi
104
105 # pack prepare
106 if [ "$target_type" == "DEB" ]
107 then
108         if [ ! -f debian/$paket.cp ]
109         then
110                 echo "debian/$paket.cp missing for target type DEB"
111                 exit 9
112         fi
113         if [ ! -f debian/$paket.control ]
114         then
115                 echo "debian/$paket.control missing for target type DEB"
116                 exit 10
117         fi
118         
119         echo "PACK=binary" >> debian/rules.pre
120         if grep "^Architecture: *all" debian/$paket.control >/dev/null
121         then
122                 echo "arch = all" >> debian/rules.pre
123                 echo 'BINARY_INDEP = copy ../$(paket)_$(version)-$(build)_all.deb' >> debian/rules.pre
124         else
125                 echo 'arch = ${DEB_HOST_ARCH}' >> debian/rules.pre
126                 echo "BINARY_ARCH = copy ../${paket}_$version-${build}_"'$(arch).deb' >> debian/rules.pre
127         fi
128         if ! [ -f debian/$paket.changelog ]
129         then
130                 echo "changelog_source = debian/default.changelog" >> debian/rules.pre
131                 if [ -f debian/default.changelog ]
132                 then
133                         rm debian/default.changelog
134                 fi
135         fi
136 elif [ "$target_type" == "ZIP" ]
137 then
138         echo "PACK=zip" >> debian/rules.pre
139         if [ ! -f debian/$paket.cp ]
140         then
141                 echo "debian/$paket.cp missing for target type ZIP"
142                 exit 11
143         fi
144 elif [ "$target_type" == "FILE" ]
145 then
146         echo "PACK=version" >> debian/rules.pre
147         if [ -z "$compile_target" ]
148         then
149                 echo "compile_target is needed for target_type FILE"
150                 exit 12
151         fi
152         echo "TARGET = $compile_target" >> debian/rules.pre
153         
154 else
155         echo "Unknown target type: $target_type"
156         exit 13
157 fi
158
159 # build package
160 debian/rules pack
161