Logo AND Algorithmique Numérique Distribuée

Public GIT Repository
Let's document my modifications by myself !!! :)
[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
82 # expend the path for solaris
83 PATH="$PATH:/usr/xpg4/bin"
84 export PATH
85
86 fail () {
87    echo $1;
88    echo CONFIG-LOG-DUMP-BEGIN
89    cat config.log
90    echo CONFIG-LOG-DUMP-END
91    exit 1;
92 }
93
94 printenv;
95 echo PATH=$PATH
96
97 cd $PREFIX/src || fail "Cannot cd to $PREFIX/src"
98
99 do_cmd() {
100   echo "Do $1"
101   eval `echo $1` 2>&1 || fail "$2"
102   echo "Done $1"
103 }    
104
105 if echo $@ | grep clean >/dev/null ; then
106   for name in @PACKAGE@* ; do
107     if test "$name" != "@PACKAGE@-@VERSION@.tar.gz" ; then 
108       echo "XXX Remove $name";
109       rm -rf $name;
110     fi;
111   done;
112
113   echo "XXX Untar @PACKAGE@-@VERSION@"
114   do_cmd "gunzip @PACKAGE@-@VERSION@.tar.gz" "Cannot gunzip"
115   do_cmd "tar xf @PACKAGE@-@VERSION@.tar" "Cannot untar"
116 fi
117
118 if echo $@ | grep touch >/dev/null ; then
119   echo "XXX Touch everything within the tarball"
120   find @PACKAGE@-@VERSION@ -type f | while read f; do touch $f;done
121   sleep 2
122 fi
123 cd @PACKAGE@-@VERSION@ || fail "Cannot cd to @PACKAGE@-@VERSION@"
124
125 if echo $@ | grep config >/dev/null ; then
126   do_cmd "env  $CONFIGURE_ENV      \
127   ./configure $CONFIGURE_ARGS" "Cannot configure"
128 fi
129
130 if echo $@ | grep compile >/dev/null ; then
131   do_cmd "make $MAKE_ALL" "Cannot make"
132 fi
133
134 if echo $@ | grep install >/dev/null ; then
135   do_cmd "make $MAKE_INSTALL" "Cannot make install"
136 fi
137
138 if echo $@ | grep check >/dev/null ; then
139   do_cmd "make $MAKE_CHECK 2>&1" || fail "Cannot make check"
140 fi
141
142 echo Remote compilation sucessful.
143 echo
144 echo
145 echo CONFIG-LOG-DUMP-BEGIN
146 cat config.log
147 echo CONFIG-LOG-DUMP-END
148 echo
149 echo
150 echo Remote compilation sucessful.
151 exit 0