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