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