438321e36d3f828d1ca4c041803c64173dd1f59f
[projects.git] / tools / make / mconfigure
1 #!/bin/bash
2 set -e
3
4 function echo_usage {
5         echo "usage: mconfigure <package> [options]"
6         echo "  -a <arch>"
7         echo "  -c : configure"
8         echo "  -d : compile"
9         echo "  -p : pack default: do all"
10 }
11
12 function set_build {
13         if [ -e .svn ]
14         then
15                 version="0.0"
16                 build=$(svnversion)
17                 build=${build/:/-}
18         elif [ -e .git ]
19         then
20                 tag=$(git describe --tags 2>/dev/null) || true
21                 if test -z "$tag"
22                 then
23                         tag="0.0-TOP"
24                 fi
25                 changes=$(git status -s |grep "^ *M") || true
26                 if test -n "$changes"
27                 then
28                         tag="${tag}M"
29                 fi
30                 version=${tag%%-*}
31                 version=${version##*_}
32                 build=${tag#*-}
33         else
34                 echo "No configuration system found. Cannot determine version."
35                 exit 1
36         fi
37 }
38
39 function check_version {
40         vline=$(head -1 debian/$paket.changelog)
41         vline=${vline%-*}
42         clversion=${vline#*(}
43         if [ $version = "0.0" ]
44         then
45                 version=$clversion
46                 return
47         fi
48         if [ "$clversion" != $version ]
49         then
50                 echo "version mismatch: git: $version, changelog: $clversion"
51                 exit 1
52         fi
53 }
54 # to build a package you need ...
55 # <package>.cp (optional): copy step for package production
56 # <package>.cpp.sh (optional): commands to setup the C++ compile environment
57
58 if [ $# -lt 1 ]
59 then
60         echo_usage
61         exit 1
62 fi
63
64 if [ ! -d debian ]
65 then
66         echo "run mconfigure in the project base directory with a debian directory in it!"
67         exit 2
68 fi
69
70 paket=$1
71
72 configure=0
73 compile=0
74 pack=0
75 shift
76 while getopts ":acdp" opt; do
77         case $opt in
78                 a) ARCH=$OPTARG
79                         ;;
80                 c) configure=1
81                         ;;
82                 d)      compile=1
83                         ;;
84                 p)      pack=1
85                         ;;
86                 \?) echo "Invalid option: -$OPTARG"
87                         echo_usage
88                         exit 1
89                         ;;
90                 :) echo "Option -$OPTARG requires an argument."
91                         echo_usage
92                         exit 1
93                         ;;
94         esac
95 done
96
97 # if nothing is selected, select all
98 if [ $configure -eq 0 -a $compile -eq 0 -a $pack -eq 0 ]
99 then
100         configure=1
101         compile=1
102         pack=1
103 fi
104
105 if [ $configure -eq 1 ]
106 then
107         echo "paket=$paket" > debian/rules.pre
108 #       shift
109         ARCH=""
110         cpp_build=0
111
112         set_build
113         check_version
114         echo "version=$version" >> debian/rules.pre
115         echo "build=$build" >> debian/rules.pre
116
117         # get repository name
118 #       tmp=$(pwd)
119 #       pwd=${tmp##*/}
120 #       pwd=${pwd,,*}
121 #       echo "pwd=$pwd" >> debian/rules.pre
122
123         echo "building $paket with build $version-$build"
124
125         pushd debian >/dev/null
126         # ./debian -------------------------------------
127
128         ln -sf /usr/share/mbuild/rules .
129
130         if [ -e tmp ]
131         then
132                 rm -rf tmp
133         fi
134
135         # check for pre/post installation scripts
136         if [ -f $paket.preinst ]
137         then
138                 echo "add_inst_tgt += debian/tmp/DEBIAN/preinst" >> rules.pre
139         fi
140         if [ -f $paket.postinst ]
141         then
142                 echo "add_inst_tgt += debian/tmp/DEBIAN/postinst" >> rules.pre
143         fi
144         if [ -f $paket.prerm ]
145         then
146                 echo "add_inst_tgt += debian/tmp/DEBIAN/prerm" >> rules.pre
147         fi
148         if [ -f $paket.postrm ]
149         then
150                 echo "add_inst_tgt += debian/tmp/DEBIAN/postrm" >> rules.pre
151         fi
152
153         mkdir -p tmp/DEBIAN
154
155         # load util functions for C/C++ - build
156         if [ -f $paket.cpp.sh ]
157         then
158                 cpp_build=1
159                 . projects/tools/make/c_configure.sh
160                 . $paket.cpp.sh
161         fi
162
163         popd >/dev/null
164         # ./. ---------------------------------------------
165
166         # copy package control
167         if [ ! -f debian/control ]
168         then
169                 control=$(find etc -name $paket.control)
170                 if [ -z "$control" ]
171                 then
172                         echo "warning: control file not found"
173                         echo "  this file is necessary for any package production."
174                 else    
175                         echo "Source: $pwd
176         Section: main
177         Priority: optional
178         Maintainer: WagnerTech UG <mail@wagnertech.de>
179         " > debian/control
180                         grep -v "Version:" $control |grep -v "Maintainer:" >> debian/control 
181                 fi
182         fi
183 fi
184
185 # check for copy file
186 #if [ ! -f debian/$paket.cp ]
187 #then
188 #       # search for copy file
189 #       copy=$(find . -name $paket.cp)
190 #       if [ -n "$copy" ]
191 #       then
192 #               echo "ln -sf ../$copy debian/"
193 #               ln -sf ../$copy debian/
194 #       else
195 #               echo "warning: file $paket.cp missing or not executable:"
196 #               echo "  this file is necessary for any package production."
197 #       fi
198 #fi
199
200 if [ ! -e debian/build.sh ]
201 then
202         echo "no debian/build.sh: skipping build step"
203         compile=0
204 fi
205 if [ $compile -eq 1 ]
206 then
207         # build artefacts
208         debian/rules build
209 fi
210
211 if [ $pack -eq 1 ]
212 then
213         # build package
214         debian/rules binary
215 fi
216