Logo AND Algorithmique Numérique Distribuée

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