Logo AND Algorithmique Numérique Distribuée

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