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