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