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