b102ad77d447b87836306058c1dd1cc8821552b7
[projects.git] / tools / make / mconfigure
1 #!/bin/bash
2 set -e
3
4 function echo_usage {
5         echo "usage: mconfigure [options] <package>"
6         echo "  -c : copy configure/Makefile"
7         echo "  -d : compile"
8         echo "  -p : pack default: do all"
9         ./configure -I
10 }
11
12 ##############################################################################
13 # Main program
14 ##############################################################################
15
16 if [ ! -d debian ]
17 then
18         echo "run mconfigure in the project base directory with a debian directory in it!"
19         exit 2
20 fi
21
22 configure=0
23 compile=0
24 pack=0
25 confirure_args="-b ../build"
26 while [ $OPTIND -le "$#" ]
27 do
28         if getopts "cdp" opt
29         then
30                 case $opt in
31                         c) configure=1
32                                 ;;
33                         d)      compile=1
34                                 ;;
35                         p)      pack=1
36                                 ;;
37                         \?) $confirure_args="$configure_ars -$OPTARG"
38                                 if [ $OPTARG="a" -o $OPTARG="C" -o $OPTARG="i" -o $OPTARG="v" ]
39                                 then
40                                         eval OPTIND=OPTIND+1
41                                         $confirure_args="$configure_ars ${!OPTIND}"
42                                 fi
43                                 ;;
44                         :) echo "Option -$OPTARG requires an argument."
45                                 echo_usage
46                                 exit 1
47                                 ;;
48                 esac
49         else
50                 paket="${!OPTIND}"
51                 eval OPTIND=OPTIND+1
52         fi
53 done
54
55 if [ -z "$paket" ]
56 then
57         echo_usage
58         exit 1
59 fi
60
61 if [ $configure -eq 1 ]
62 then
63         # installation of configure file
64         cp /usr/share/mbuild/configure .
65 else
66         if [ ! -e configure ]
67         then
68                 ln -s /usr/share/mbuild/configure .
69         fi
70 fi
71
72 configure_args="$configure_args $paket"
73 if [ -x debian/$paket.preconfigure ]
74 then
75         # if necessary $configure_args can be added to setenv.sh
76         debian/$paket.preconfigure
77 fi
78
79 #-> configure
80 # .build or .cmake
81 if [ -x debian/$paket.build -o -e debian/$paket.cmake ]
82 then
83         echo "BUILD_DIR=../build" >> debian/setenv.sh
84         if [ -e ../build ]
85         then
86                 rm -rf ../build
87                 mkdir ../build
88         fi
89         if grep -- "-prepare" debian/$paket.build >/dev/null
90         then                    
91                 echo "prepare in <paket>.build no longer supported. Use <paket>.prebuild"
92                 exit 2
93         fi
94         # sync build dir
95         . debian/setenv.sh
96         debian/rules sync
97 fi
98
99 # perform configure
100 . debian/setenv.sh
101 ./configure $configure_args
102
103 # if nothing is selected, select all
104 if [ $compile -eq 0 -a $pack -eq 0 ]
105 then
106         compile=1
107         pack=1
108 fi
109
110 if [ $compile -eq 1 ]
111 then
112         # build
113         make
114 fi
115
116 if [ $pack -eq 1 ]
117 then
118         # build package
119         debian/rules pack
120 fi
121