posaune
[projects.git] / tools / make / configure
1 #!/bin/bash
2 set -e
3
4 function echo_usage {
5         echo "usage: configure <package> <revision> [options]"
6         echo "  -b <branch-rev>"
7         echo "  -a <arch>"
8 }
9
10 # to build a package you need ...
11 # <package>.co: checkout commands
12 # <package>.cp (optional): copy step for package production
13 # <package>.cpp (optional): commands to setup the C++ compile environment
14
15 if [ $# -lt 2 ]
16 then
17         echo_usage
18         exit 1
19 fi
20
21 paket=$1
22 build=$2
23 ARCH=""
24 cpp_build=0
25
26 # checkout build utilities
27 if [ ! -d projects ]; then
28         git clone https://github.com/wagner-tech/projects/
29 fi
30 ln -sf projects/tools/make/makefile .
31
32 # check standard files
33 if [ ! -x $paket.co ]
34 then
35         echo "file $paket.co missing or not executable."
36         exit 1
37 fi
38 if [ ! -x $paket.cp ]
39 then
40         echo "warning: file $paket.cp missing or not executable:"
41         echo "  this file is necessary for any package production."
42 fi
43
44 # load util functions for C/C++ - build
45 if [ -f $paket.cpp ]
46 then
47         cpp_build=1
48         . Make/c_configure.sh
49 fi
50
51 # clean dirs and check out
52 if [ -e $paket ]
53 then
54         rm -rf $paket
55 fi
56 rm *.stamp || true
57
58 mkdir -p src
59 cwd=$(pwd)
60
61 # checkout
62 pushd src >/dev/null
63         ../$paket.co $build
64 popd >/dev/null
65
66 # copy package control
67 control=$(find src -name $paket.control)
68 if [ -z "$control" ]
69 then
70         echo "warning: control file not found"
71         echo "  this file is necessary for any package production."
72 else    
73         sed "s/%BUILD%/$build/" $control >$paket.control
74         echo "$paket.control written."
75
76         # extract version
77         version=$(grep Version $paket.control |sed "s/Version: //")
78 fi
79
80 # check for postinst
81 postinst=$(find src -name $paket.postinst)
82 if [ -n "$postinst" ]
83 then
84         ln -sf $postinst .
85 fi
86
87 # create generic make.pre, if not existing
88 if [ ! -f make.pre ]
89 then
90         cat  >>make.pre <<MAKE_PRE
91 # mBuild make.pre script (auto generated)
92 project = $paket
93 version = $version
94 COPY = ./$paket.cp
95 MAKE_PRE
96         echo "make.pre written."
97 fi
98