Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
borland bpf file of trace usage test case
[simgrid.git] / tools / graspe-slave.in
1 #! /bin/sh 
2 # @WARNING@
3 # It is used to compile on remote hosts
4
5 ###
6 # Configuration
7 ###
8
9 # Where to install the stuff into (REMOTE_PREFIX gets fixed by the makefile)
10 PREFIX=$REMOTE_PREFIX
11 if echo $PREFIX | egrep '^/' > /dev/null ; then
12   echo "Prefix is an absolute path. Good, it makes configure happy"
13 else
14   echo "Change prefix to an absolute path to keep configure happy"
15   PREFIX="$HOME/$PREFIX"
16 fi
17 echo "(PREFIX=$PREFIX)"
18
19 # Where extra libraries are installed (if any)
20 LD_LIBRARY_PATH="$PREFIX/lib"
21
22 # Extra environment to pass to configure
23 CONFIGURE_ENV=""
24
25 # Argument of configure
26 CONFIGURE_ARGS="--prefix=$PREFIX/@PACKAGE@"
27
28 # make target
29 MAKE_ALL="all"
30 MAKE_INSTALL=install
31 MAKE_CHECK="-k check"
32
33 echo "Launching $0"
34
35 ### 
36 # Magic to search a working shell (from autobook)
37 ###
38 # Zsh is not Bourne compatible without the following:
39 if test -n "$ZSH_VERSION"; then
40   emulate sh
41   NULLCMD=:
42 fi
43
44 # Bash is not POSIX compliant without the following:
45 test -n "$BASH_VERSION" && set -o posix
46
47 SHELL="${SHELL-/bin/sh}"
48 if test x"$1" = x--re-executed; then
49   # Functional shell was found.  Remove option and continue
50   shift
51 elif "$SHELL" -c 'foo () { exit 0; }; foo' 2>/dev/null &&
52      "$SHELL" -c 'export toto=tutu' 2>/dev/null ; then
53   # The current shell works already!
54   echo "Current shell ($SHELL) working"
55 else
56   # Try alternative shells that (sometimes) support functions
57   for cmd in bash sh ash bsh ksh zsh sh5
58   do
59     for dir in `echo $PATH | sed -e 's/:/ /g'` /bin /usr/bin
60     do
61       shell="$dir/$cmd"
62       if (test -f "$shell" || test -f "$shell.exe") &&
63          "$shell" -c 'foo () { exit 0; }; foo' 2>/dev/null &&
64          "$shell" -c 'export toto=tutu' 2>/dev/null
65       then
66         # Re-execute with discovered functional shell
67         echo "Reexecute $0 $@ with shell $shell"
68         SHELL="$shell" exec "$shell" "$0" --re-executed ${1+"$@"}
69       fi
70     done
71   done
72   echo "Unable to locate a shell interpreter with function support and export syntax" >&2
73   exit 1
74 fi
75
76
77
78 ###
79 # Real script
80 ###
81 if [ "x$CC" = x ] ; then
82   echo "CC not set. Search for xlC"
83   xlC=`which xlC`
84   if [ "x$xlC" != x ] ; then
85     echo "Found (in $xlC)"
86     CONFIGURE_ARGS="$CONFIGURE_ARGS CC=xlC"
87   else
88     echo "Not found. Stick to the defaults"
89   fi
90 fi
91
92 # expend the path for solaris
93 PATH="$PATH:/usr/xpg4/bin"
94 export PATH
95
96 fail () {
97    echo $1;
98    echo CONFIG-LOG-DUMP-BEGIN
99    cat config.log
100    echo CONFIG-LOG-DUMP-END
101    exit 1;
102 }
103
104 printenv;
105 echo PATH=$PATH
106
107 cd $PREFIX/src || fail "Cannot cd to $PREFIX/src"
108
109 do_cmd() {
110   echo "Do $1"
111   eval `echo $1` 2>&1 || fail "$2"
112   echo "Done $1"
113 }    
114
115 if echo $@ | grep clean >/dev/null ; then
116   for name in @PACKAGE@* ; do
117     if test "$name" != "@PACKAGE@-@VERSION@.tar.gz" ; then 
118       echo "XXX Remove $name";
119       rm -rf $name;
120     fi;
121   done;
122
123   echo "XXX Untar @PACKAGE@-@VERSION@"
124   do_cmd "gunzip @PACKAGE@-@VERSION@.tar.gz" "Cannot gunzip"
125   do_cmd "tar xf @PACKAGE@-@VERSION@.tar" "Cannot untar"
126 fi
127
128 if echo $@ | grep touch >/dev/null ; then
129   echo "XXX Touch everything within the tarball"
130   find @PACKAGE@-@VERSION@ -type f | while read f; do touch $f;done
131   sleep 2
132 fi
133 cd @PACKAGE@-@VERSION@ || fail "Cannot cd to @PACKAGE@-@VERSION@"
134
135 if echo $@ | grep config >/dev/null ; then
136   do_cmd "env  $CONFIGURE_ENV      \
137   ./configure $CONFIGURE_ARGS" "Cannot configure"
138 fi
139
140 if echo $@ | grep compile >/dev/null ; then
141   do_cmd "make $MAKE_ALL" "Cannot make"
142 fi
143
144 if echo $@ | grep install >/dev/null ; then
145   do_cmd "make $MAKE_INSTALL" "Cannot make install"
146 fi
147
148 if echo $@ | grep check >/dev/null ; then
149   do_cmd "make $MAKE_CHECK 2>&1" || fail "Cannot make check"
150 fi
151
152 echo Remote compilation sucessful.
153 echo
154 echo
155 echo CONFIG-LOG-DUMP-BEGIN
156 cat config.log
157 echo CONFIG-LOG-DUMP-END
158 echo
159 echo
160 echo Remote compilation sucessful.
161 exit 0