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