gnublin1
[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.sh (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 # clean dirs and check out
45 if [ -e $paket ]
46 then
47         rm -rf $paket
48 fi
49 rm *.stamp || true
50 rm make.pre || true
51
52 mkdir -p src
53 cwd=$(pwd)
54
55 # checkout
56 pushd src >/dev/null
57         ../$paket.co $build
58 popd >/dev/null
59
60 # load util functions for C/C++ - build
61 if [ -f $paket.cpp.sh ]
62 then
63         cpp_build=1
64         . projects/tools/make/c_configure.sh
65         . $paket.cpp.sh
66 fi
67
68 # copy package control
69 control=$(find src -name $paket.control)
70 if [ -z "$control" ]
71 then
72         echo "warning: control file not found"
73         echo "  this file is necessary for any package production."
74 else    
75         sed "s/%BUILD%/$build/" $control |sed "s/%ARCH%/$ARCH/" >$paket.control
76         echo "$paket.control written."
77
78         # extract version
79         version=$(grep Version $paket.control |sed "s/Version: //")
80 fi
81
82
83 # check for postinst
84 postinst=$(find src -name $paket.postinst)
85 if [ -n "$postinst" ]
86 then
87         ln -sf $postinst .
88 fi
89
90 # create generic make.pre, if not existing
91 if [ ! -f make.pre ]
92 then
93         cat  >>make.pre <<MAKE_PRE
94 # mBuild make.pre script (auto generated)
95 project = $paket
96 COPY = ./$paket.cp
97 MAKE_PRE
98         echo "make.pre written."
99 fi
100
101 # append version to make.pre
102 echo "version = $version" >> make.pre
103