Warning, /sdk/kde-dev-scripts/makeobj is written in an unsupported language. File is not indexed.
0001 #! /usr/bin/env bash 0002 0003 # this is a script around make which basicly checks 0004 # if it's in srcdir or in builddir and changes to 0005 # the right directory for calling /usr/bin/make 0006 # (C) Stephan Kulow 0007 0008 # Variable replacement code by Allen Winter <allen.winter@kdab.com> 0009 # Copyright (c) 2011,2013 Klarälvdalens Datakonsult AB, a KDAB Group company <info@kdab.net> 0010 0011 # You may need to set OBJ_REPLACEMENT variable to get it to work. 0012 # In the variable use the sed syntax to switch directories, for example 0013 # export OBJ_REPLACEMENT="s:/home/zack/cvs/kde:/home/zack/build:" 0014 # will assure that the builds are performed under /home/zack/build 0015 # directory, when the cvs is held under /home/zack/cvs/kde. 0016 0017 # Variables: 0018 # %BRANCH% with the name of the Git or SVN branch you are in (as applicable) 0019 # %GITBRANCH% with the name of the Git branch you are in (empty if not in a Git branch) 0020 # %SVNBRANCH% with the name of the SVN branch you are in (empty if not in an SVN branch) 0021 # %CC% with the basename of your C compiler set in $CC (gcc if empty) 0022 # %CXX% with the basename of your C++ compiler set in $CXX (g++ if empty) 0023 # %ARCH% with the machine architecture (i.e. 'uname -m') 0024 # %OS% with the operating system name (i.e. 'uname -o'), in lower-case without "GNU" 0025 0026 findup() { 0027 parg="$1" 0028 _hit="" 0029 spwd="$PWD" 0030 if test -z "$parg"; then return 1; fi 0031 0032 while ! test -e "$parg"; do 0033 cd .. 0034 if test "$PWD" = "/"; then 0035 cd "$spwd" 0036 return 1 0037 fi 0038 done 0039 _hit="$PWD/$parg" 0040 cd "$spwd" 0041 } 0042 0043 gitbranch() { 0044 findup .git 0045 if test -n "$_hit"; then 0046 _gitbranch=`sed -e 's,.*/,,' "$_hit/HEAD"` 0047 fi 0048 } 0049 0050 svnbranch() { 0051 findup .svn 0052 if test -n "$_hit"; then 0053 _root=`svn info . | grep "Repository Root:" | awk '{print $3}'` 0054 _baseurl=`svn info . | grep '^URL:' | awk '{print $2}' | sed -e s,$_root/,,` 0055 _svnbranch=`echo "$_baseurl" | awk -F/ '{print $1}'` 0056 fi 0057 } 0058 0059 branch() { 0060 gitbranch 0061 if test -z "$_gitbranch"; then 0062 svnbranch 0063 if test -z "$_svnbranch"; then 0064 _branch="" 0065 else 0066 _branch=$_svnbranch 0067 fi 0068 else 0069 _branch=$_gitbranch 0070 fi 0071 } 0072 0073 file=Makefile 0074 dir=. 0075 args=() 0076 0077 _branch="" 0078 _gitbranch="" 0079 _svnbranch="" 0080 0081 # We don't support non-GNU Make. 0082 # Try the name that GNU Make has on non-GNU platforms first 0083 GMAKE="`command -v gmake`" 0084 GMAKE="${GMAKE:-`command -v make`}" 0085 0086 while test $# -gt 0 ; do 0087 case "${1}" in 0088 -f) 0089 shift 0090 file="${1}" 0091 shift 0092 args=("${args[@]}" -f $file) 0093 ;; 0094 -C) 0095 shift 0096 dir="${1}" 0097 shift ;; 0098 -v) 0099 shift 0100 exec $GMAKE "${args[@]}" -v $@ 0101 ;; 0102 *) 0103 args=("${args[@]}" "$1") 0104 shift 0105 ;; 0106 esac 0107 done 0108 0109 cd "$dir" 0110 dir=. 0111 cwd=$PWD 0112 0113 # No CMakeList and no Makefile (and no .pro file either)? Maybe we need to go up then. 0114 while test ! -f CMakeLists.txt && test ! -f Makefile ; do 0115 if test "`ls -1 *.pro 2>/dev/null`" && test -n "`ls -1 ../*.pro 2>/dev/null`"; then 0116 break; 0117 fi 0118 if test -f build.ninja; then 0119 file=build.ninja 0120 break; 0121 fi 0122 dir="$dir/`basename \"$PWD\"`" 0123 cd .. 0124 if test X"$PWD" = X"/"; then 0125 cd -- "$cwd" 0126 break 0127 fi 0128 done 0129 0130 if test ! -f "$file"; then 0131 branch 0132 if test -n "$CC"; then 0133 tmp=`echo $CC | awk '{print $1}'` 0134 _cc="`basename \"$tmp\"`" 0135 else 0136 _cc="gcc" 0137 fi 0138 if test -n "$CXX"; then 0139 tmp="`echo \"$CXX\" | awk '{print $1}'`" 0140 _cxx="`basename \"$tmp\"`" 0141 else 0142 _cxx="g++" 0143 fi 0144 _arch="`uname -m`" 0145 _os="`(uname -o 2>/dev/null || uname -s) | tr '[A-Z]' '[a-z]' | sed -e s+gnu/++`" 0146 0147 if test -n "$OBJ_SUBDIR"; then 0148 OBJ_SUBDIR="`echo \"$OBJ_SUBDIR\" | \ 0149 sed -e s+%BRANCH%+\"$_branch\"+g | \ 0150 sed -e s+%GITBRANCH%+\"$_gitbranch\"+g | \ 0151 sed -e s+%SVNBRANCH%+\"$_svnbranch\"+g | \ 0152 sed -e s,%CC%,\"$_cc\",g | \ 0153 sed -e s,%CXX%,\"$_cxx\",g | \ 0154 sed -e s,%ARCH%,\"$_arch\",g | \ 0155 sed -e s,%OS%,\"$_os\",g`" 0156 dir=$PWD 0157 subdir=. 0158 while test ! -f "$dir/$OBJ_SUBDIR/$file"; do 0159 subdir="`basename \"$dir\"`/$subdir" 0160 dir="`dirname \"$dir\"`" 0161 if test X"$dir" = X"/"; then 0162 # the case that someone puts the compile dir in / 0163 # is very unlikely, so we better skip here ;) 0164 echo "can't find $OBJ_SUBDIR above current dir" 0165 exit 1 0166 fi 0167 done 0168 cd -- "$dir/$OBJ_SUBDIR/$subdir" 0169 else 0170 if test -n "$OBJ_REPLACEMENT"; then 0171 OBJ_REPLACEMENT="`echo \"$OBJ_REPLACEMENT\" | \ 0172 sed -e s+%BRANCH%+\"$_branch\"+g | \ 0173 sed -e s+%GITBRANCH%+\"$_gitbranch\"+g | \ 0174 sed -e s+%SVNBRANCH%+\"$_svnbranch\"+g | \ 0175 sed -e s,%CC%,\"$_cc\",g | \ 0176 sed -e s,%CXX%,\"$_cxx\",g | \ 0177 sed -e s,%ARCH%,\"$_arch\",g | \ 0178 sed -e s,%OS%,\"$_os\",g`" 0179 pwd="`echo $PWD | sed -e \"$OBJ_REPLACEMENT\"`" 0180 if test ! -e "$pwd"; then 0181 echo "no objdir found. Tried $pwd" 0182 exit 1 0183 fi 0184 if test ! -f "$pwd/$file"; then 0185 # ninja requires building from the toplevel 0186 cd -- "$pwd" 0187 findup build.ninja 0188 if test -n "$_hit"; then 0189 pwd=`dirname $_hit` 0190 file=build.ninja 0191 fi 0192 # No objdir with a Makefile found. But if "make" will work in srcdir, then go ahead; might be a non-kde project. 0193 test -f "$pwd/GNUmakefile" && file=GNUmakefile 0194 test -f "$pwd/makefile" && file=makefile 0195 if ! test -f "$pwd/$file"; then 0196 echo "no Makefile or build.ninja found in $pwd" 0197 exit 1 0198 fi 0199 fi 0200 cd -- "$pwd" 0201 fi 0202 fi 0203 fi 0204 0205 echo "makeobj[0]: Entering directory \`$PWD'" 0206 0207 if test -z "$MAKE"; then 0208 using_new_unsermake=0 0209 if head -n 1 "$file" 2>/dev/null | grep unsermake >/dev/null; then 0210 using_new_unsermake=1 0211 fi 0212 if head -n 1 "$file" 2>/dev/null | grep automake >/dev/null; then 0213 using_new_unsermake=0 0214 fi 0215 if test $using_new_unsermake -eq 1; then 0216 MAKE="`command -v unsermake`" 0217 if test ! -x "$MAKE"; then 0218 echo 'Makefile was created with unsermake, but there' 0219 echo 'is no unsermake in $PATH' 0220 exit 1 0221 fi 0222 elif test -f "Makefile"; then 0223 MAKE="$GMAKE" 0224 elif test -f "build.ninja"; then 0225 MAKE="ninja" 0226 else 0227 echo "No Makefile or build.ninja found in $PWD!" 0228 fi 0229 fi 0230 LANG=en_US.UTF-8 $MAKE "${args[@]}" 0231 retval=$? 0232 echo "makeobj[0]: Leaving directory \`$PWD'" 0233 exit $retval 0234