Add to git.
[makeplus.git] / make+
1 #!/bin/sh
2 #
3 # This is make+. Make+ is a set of scripts which enhance GNU make and
4 # let you build RPMs, and other packages types with just one control
5 # file. Read more at http://www.annexia.org/freeware/makeplus/
6 #
7 # The original author is Richard W.M. Jones <rich@annexia.org>.
8 #
9 # This software has been explicitly placed in the PUBLIC DOMAIN.  You
10 # do not need any sort of license or agreement to use or copy this
11 # software. You may also copyright this software yourself, and/or
12 # relicense it under any terms you want, at any time and at no cost.
13 # This allows you (among other things) to include this software with
14 # other packages so that the user does not need to download and
15 # install make+ separately.
16
17 # The control file. XXX Parse and remove the -f option.
18 _mp_makefile="Makefile+"; export _mp_makefile
19
20 # Check the control file exists in the current directory. You can only
21 # run make+ from the top level source directory, the one which contains
22 # Makefile+. You should not be doing anything recursive with make+.
23 if [ ! -r "$_mp_makefile" ]; then
24     echo "make+: $_mp_makefile: file not found or not readable"
25     echo "You should always run make+ from the top-level source"
26     echo "directory, the one which contains the Makefile+ file."
27     exit 1
28 fi
29
30 # Find a suitable copy of GNU make. You can override this test
31 # by setting the $MAKE option.
32 if [ "x$MAKE" = "x" ]; then
33     if sh -c 'gmake --version' 2>/dev/null | grep -q 'GNU Make'; then
34         MAKE=gmake
35     elif sh -c 'make --version' 2>/dev/null | grep -q 'GNU Make'; then
36         MAKE=make
37     else
38         echo "make+: I cannot find a copy of GNU make. Please set the \$MAKE"
39         echo "environment variable to point to the GNU make binary."
40     fi
41 fi
42
43 # Check for a sufficiently recent version of GNU make.
44 if $MAKE --version | grep -q '^GNU Make .*3\.'; then
45     # make is up-to-date
46     :
47 else
48     echo "make+: Your 'make' is not GNU make (or not a recent version)"
49     echo "Please install a recent version of GNU make."
50     exit 1
51 fi
52
53 # Check that either MAKEPLUS_HOME or /etc/make+.conf exists, and run it.
54 if [ "x$MAKEPLUS_HOME" = "x" ]; then
55     for d in /etc /usr/etc /usr/local/etc; do
56         if [ -f $d/make+.conf ]; then
57             . $d/make+.conf
58             break
59         fi
60     done
61 fi
62
63 # Check MAKEPLUS_HOME looks reasonable.
64 if [ ! -f "$MAKEPLUS_HOME/main.mk" ]; then
65     echo "make+: MAKEPLUS_HOME environment variable not set correctly."
66     echo "This environment variable should point to the installation"
67     echo "directory for make+ (eg. /usr/share/makeplus). You would normally"
68     echo "do this by creating a file called /etc/make+.conf containing"
69     echo "  export MAKEPLUS_HOME=/usr/share/makeplus"
70     echo "or you can set it as an environment variable each time you run"
71     echo "make+."
72     exit 1
73 fi
74
75 # Set MAKEFILES.
76 MAKEFILES=$MAKEPLUS_HOME/main.mk; export MAKEFILES
77
78 # Construct a suitable target architecture.
79 # XXX Cross compiling.
80 arch=`uname -m`
81 os=`uname -s | tr 'A-Z' 'a-z'`
82 hw=`( uname -i 2>/dev/null || echo "unknown" ) | tr -cd 'A-Za-z0-9'`
83 _mp_builddir=build-$arch-$hw-$os; export _mp_builddir
84
85 # Create the build directory.
86 # XXX
87 mkdir -p $_mp_builddir
88 cd $_mp_builddir
89
90 # Create the directories under the build directory.
91 (cd .. && find . -type d -a \! -name CVS) | grep -v $_mp_builddir |
92     xargs mkdir -p
93
94 # Run GNU make from the build directory.
95 $MAKE -f ../$_mp_makefile "$@"