summaryrefslogtreecommitdiffstats
path: root/scripts/makeobj
blob: cc79c663215a6245346db7034a732e44dbcc478e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#! /usr/bin/env bash

# this is a script around make which basicly checks
# if it's in srcdir or in builddir and changes to 
# the right directory for calling /usr/bin/make
# (C) Stephan Kulow

# You may need to set OBJ_REPLACEMENT variable to get it to work.
# In the variable use the sed syntax to switch directories, for example
# export OBJ_REPLACEMENT="s:/home/zack/cvs/kde:/home/zack/build:"
# will assure that the builds are performed under /home/zack/build
# directory, when the cvs is held under /home/zack/cvs/kde.

file=Makefile
dir=.
args=()

while test $# -gt 0 ; do
   case "${1}" in
      -f)
	shift
	file="${1}" 
	shift 
	args=("${args[@]}" -f $file)
	;;
      -C)
	shift
	dir="${1}"
	shift ;;
      *)
	args=("${args[@]}" "$1")
	shift 
	;;
    esac
done

if test ! -f $dir/$file; then
  if test -n "$OBJ_SUBDIR"; then
    dir=$PWD
    subdir=.
    while test ! -f $dir/$OBJ_SUBDIR/$file; do
       subdir=`basename $dir`"/$subdir"
       dir=`dirname $dir`
       if test "$dir" = "/"; then
         # the case that someone puts the compile dir in /
         # is very unlikely, so we better skip here ;)
         echo "can't find $OBJ_SUBDIR above current dir"
         exit 1
       fi
    done
    cd $dir/$OBJ_SUBDIR/$subdir
  else
    if test -n "$OBJ_REPLACEMENT"; then
      pwd=`echo $PWD | sed -e "$OBJ_REPLACEMENT"`
      if test ! -f $pwd/$dir/$file; then
         # No objdir found. But if "make" will work in srcdir, then go ahead; might be a non-kde project.
         test -f $dir/GNUmakefile && file=GNUmakefile
         test -f $dir/makefile && file=makefile
         test -f $dir/$file || file=""
         if test -z "$file"; then
           echo "no objdir found. Tried $pwd"
           exit 1
         fi
      fi
      cd $pwd/$dir
    fi
  fi
else
  cd $dir
fi

echo "makeobj[0]: Entering directory \`$PWD'"
if test -z "$MAKE"; then
    using_new_unsermake=0
    if head -n 1 $file | grep unsermake >/dev/null; then
        using_new_unsermake=1
    fi
    if head -n 1 $file | grep automake >/dev/null; then
        using_new_unsermake=0
    fi
    if test $using_new_unsermake -eq 1; then
        MAKE=`type -p unsermake`
	if test ! -x "$MAKE"; then
		echo 'Makefile was created with unsermake, but there'
		echo 'is no unsermake in $PATH'
		exit 1
	fi
    else
        MAKE=/usr/bin/make
    fi
fi
LANGUAGE=C $MAKE "${args[@]}"
retval=$?
echo "makeobj[0]: Leaving directory \`$PWD'"
exit $retval