posaune
[projects.git] / tools / make / mconfigure
1 #!/bin/bash
2 set -e
3
4 function echo_usage {
5         echo "usage: configure <package> [options]"
6         echo "  -a <arch>"
7 }
8
9 function set_build {
10         if [ -e .svn ]
11         then
12                 build=$(svnversion)
13         elif [ -e .git ]
14         then
15                 build=$(git describe --tags 2>/dev/null)
16                 test -n "$build" || build="TOP"
17                 changes=$(git status -s |grep "^ *M") || true
18                 test -z "$changes" || build="${build}M"
19         fi
20 }
21
22 # to build a package you need ...
23 # <package>.cp (optional): copy step for package production
24 # <package>.cpp.sh (optional): commands to setup the C++ compile environment
25
26 if [ $# -lt 1 ]
27 then
28         echo_usage
29         exit 1
30 fi
31
32 paket=$1
33 shift
34 ARCH=""
35 cpp_build=0
36 delete_src=1
37
38 set_build
39 echo "building $paket with build $build"
40
41 while getopts ":a" opt; do
42         case $opt in
43                 a) ARCH=$OPTARG
44                         ;;
45                 \?) echo "Invalid option: -$OPTARG"
46                         echo_usage
47                         exit 1
48                         ;;
49                 :) echo "Option -$OPTARG requires an argument."
50                         echo_usage
51                         exit 1
52                         ;;
53         esac
54 done
55
56 # clean dirs and check out
57 if [ -d build -a $delete_src -eq 1 ]
58 then
59         rm -rf build
60 fi
61
62 mkdir -p build
63 pushd build >/dev/null
64
65 ln -sf /usr/share/mbuild/makefile .
66
67 if [ -e $paket ]
68 then
69         rm -rf $paket
70 fi
71 rm *.stamp || true
72 rm make.pre || true
73
74 # load util functions for C/C++ - build
75 if [ -f $paket.cpp.sh ]
76 then
77         cpp_build=1
78         . projects/tools/make/c_configure.sh
79         . $paket.cpp.sh
80 fi
81
82 # copy package control
83 control=$(find -L src -name $paket.control)
84 build_number=${build#*_}
85 if [ -z "$control" ]
86 then
87         echo "warning: control file not found"
88         echo "  this file is necessary for any package production."
89 else    
90         sed "s/%BUILD%/$build_number/" $control |sed "s/%ARCH%/$ARCH/" >$paket.control
91         echo "$paket.control written."
92
93         # extract version
94         version=$(grep Version $paket.control |sed "s/Version: //")
95 fi
96
97 # check for copy file
98 copy=$(find -L src -name $paket.cp)
99 if [ -n "$copy" ]
100 then
101         ln -sf $copy .
102 else
103         echo "warning: file $paket.cp missing or not executable:"
104         echo "  this file is necessary for any package production."
105 fi
106
107 # check for installation scripts
108 files=$(find src -name $paket.preinst)
109 files="$files $(find -L src -name $paket.postinst)"
110 files="$files $(find -L src -name $paket.prerm)"
111 files="$files $(find -L src -name $paket.postrm)"
112 for file in $files
113 do
114         ln -sf $file .
115 done
116
117 # create generic make.pre, if not existing
118 if [ ! -f make.pre ]
119 then
120         cat  >>make.pre <<MAKE_PRE
121 # mBuild make.pre script (auto generated)
122 project = $paket
123 COPY = ./$paket.cp
124 MAKE_PRE
125         if [ -n "$ARCH" ]
126         then
127                 echo "arch = $ARCH" >>make.pre
128                 echo "_arch = _${ARCH}" >>make.pre
129         fi
130         echo "make.pre written."
131 fi
132
133 # append version to make.pre
134 echo "version = $version" >> make.pre
135 echo "build = $build" >> make.pre
136