Linux multi-monitor fullscreen support
[ryzomcore.git] / ryzom / tools / scripts / linux / build
blob6f97ebd9ffe33393bba26d96a8b7f076d1c470bf
1 #!/bin/sh
3 ###########################################################################
4 ###########################################################################
5 # BUILD:
7 # This tool is aimed to help Nevrax programmers to manage the
8 # compilation of a "debug" and a "release" version of NeL, NeLNS,
9 # and Snowballs2 (http://www.nevrax.org) based on the same source
10 # code and with the possibility to not having to re-compile everything
11 # each time the compilation mode (debug/release) change.
13 # This script is a simple wrapper around the 'autogen.sh'/'configure'
14 # commands ('build init nel/nelns/snowballs ...'), and the 'make'
15 # command ('build nel/nelns/snowballs ...').
17 # Example of use:
19 # $ build mode release static
20 # $ build init nel --enable-sound --enable-ai
21 # $ build nel all install
22 # $ build init nelns
23 # $ build nelns all install
24 # $ build init snowballs
25 # $ build snowballs all install
27 # As you can see there is no need to specify the installed directory
28 # of NeL, etc ... These information are automaticly provided to the
29 # configure script.
31 # Check the following variables to get an idea of the place of the
32 # source code, object, and installed files.
34 # In silent mode it use a perl script named 'buildquiet' which
35 # "cleanup" the 'make' command output to only print the compiled
36 # file name instead of the compilation command line.
38 ###########################################################################
42 ###########################################################################
43 ###########################################################################
44 ###########################################################################
45 # VARIABLES
47 #MAKE_ARGS="-j20 CC=distcc CXX=distcc"
48 MAKE_ARGS="-j2"
50 # Set the source directory. Use the environment SRC_DIR variable, if it's
51 # not set, use $HOME/cvs as a default value
52 if test X"$RYZOM_PATH" = "X"
53 then
54 RYZOM_PATH="$HOME/code"
56 SRC_DIR="$RYZOM_PATH/../../code"
58 # Build diretories
59 BUILD_DEBUG="$SRC_DIR/build/debug"
60 BUILD_RELEASE="$SRC_DIR/build/release"
62 # Install directories
63 INSTALL_DEBUG="$SRC_DIR/install/debug"
64 INSTALL_RELEASE="$SRC_DIR/install/release"
66 # PKG config
67 STLPORT_DIR='/usr'
68 PYTHON_VERSION=2
70 # Compiler options
71 BUILD_CFLAGS="$CFLAGS -pipe"
72 BUILD_CXXFLAGS="$CXXFLAGS -pipe"
74 # Configure options
75 CONFIGURE_OPT="--disable-xmltest --enable-maintainer-mode"
77 ###########################################################################
79 # Flag files associated to each mode
80 DEBUG_FILE="$RYZOM_PATH/.mode_debug"
81 STATIC_FILE="$RYZOM_PATH/.mode_static"
82 DYNAMIC_FILE="$RYZOM_PATH/.mode_dynamic"
83 SILENT_FILE="$RYZOM_PATH/.mode_silent"
85 # Specify the source code directory of each projects
86 NEL_SRC="$SRC_DIR/nel"
87 SNOWBALLS_SRC="$SRC_DIR/snowballs2"
88 NELNS_SRC="$SRC_DIR/nelns"
91 ###########################################################################
92 ###########################################################################
93 ###########################################################################
94 # FUNCTIONS
97 ###########################################################################
98 # Print command usage
99 printUsage()
101 echo ""
102 echo "Usage: $BUILD_CMD mode [debug] [static] [dynamic] [quiet]"
103 echo " debug -> turn ON/OFF debug compilation"
104 echo " static -> turn ON/OFF static linking"
105 echo " dynamic -> turn ON/OFF dynamic linking"
106 echo " quiet -> turn ON/OFF quiet compilation"
107 echo ""
108 echo "Usage: $BUILD_CMD [init] [nel | nelns | snowballs] [ARGS]"
109 echo " init -> init. the build system"
110 echo " nel, nelns, snowballs -> module to init./compile"
111 echo ""
112 echo " ARGS with init are passed to the 'configure' script"
113 echo " otherwise they are passed to 'make'"
114 echo ""
118 ###########################################################################
119 # Print status
120 printMode()
122 echo ""
123 echo "Compilation modes :"
124 echo ""
125 echo " Debug mode : $DEBUG_MODE"
126 echo ""
127 echo " Static linking : $STATIC_MODE"
128 echo " Dynamic linking : $DYNAMIC_MODE"
129 echo ""
130 echo " Quiet compilation : $SILENT_MODE"
131 echo ""
135 ###########################################################################
136 # Print a message error (given in argument) and exit.
137 printError()
139 local MSG=$1
141 echo "*** ERROR: $MSG ***" >&2
143 exit 1
147 ###########################################################################
148 # Get the specific mode value and set the corresponding variable
149 getMode()
151 local VAR=$1
152 local FILE=$2
154 if test -f "$FILE"
155 then
156 eval $VAR=ON
157 else
158 eval $VAR=OFF
163 ###########################################################################
164 # Set a specific mode to ON if it's OFF, and to OFF if its ON
165 setMode()
167 local VAR=$1
168 local FILE=$2
169 local OLD_VALUE NEW_VALUE
171 # Get the current mode value
172 OLD_VALUE=$(eval echo \$$VAR)
174 if test X"$OLD_VALUE" = "XOFF"
175 then
176 # Set the MODE to ON in case it's OFF
177 NEW_VALUE=ON
178 touch -f $FILE || printError "cannot create mode file: $FILE"
179 else
180 # Set the MODE to OFF in case it's ON
181 NEW_VALUE=OFF
182 rm -f $FILE || printError "cannot delete mode file: $FILE"
185 eval $VAR=$NEW_VALUE
189 ###########################################################################
190 ###########################################################################
191 ###########################################################################
193 BUILD_CMD=`basename $0`
195 ###########################################################################
196 # Get current the mode settings
197 getMode DEBUG_MODE $DEBUG_FILE
198 getMode STATIC_MODE $STATIC_FILE
199 getMode DYNAMIC_MODE $DYNAMIC_FILE
200 getMode SILENT_MODE $SILENT_FILE
203 ###########################################################################
204 ###########################################################################
205 ###########################################################################
206 # BUILDMODE / BUILD MODE call
208 if test "$BUILD_CMD" = 'buildmode' -o "$1" = 'mode'
209 then
211 if test "$1" = 'mode'
212 then
213 shift
216 # Print the mode values and exit if there is no argument
217 if test $# -eq 0
218 then
219 printMode
220 exit 0
223 while test $# -gt 0
225 case $1 in
227 debug)
228 setMode DEBUG_MODE $DEBUG_FILE
231 static)
232 setMode STATIC_MODE $STATIC_FILE
235 dynamic)
236 setMode DYNAMIC_MODE $DYNAMIC_FILE
239 silent)
240 setMode SILENT_MODE $SILENT_FILE
243 *) echo "*** ERROR : $1 : Unknown building mode ***" >&2
244 printUsage
245 exit 1
248 esac
250 shift
252 done
254 printMode
256 exit 0
261 ###########################################################################
262 ###########################################################################
263 # Default call: BUILD
266 ###########################################################################
267 # Set the LD_LIBRARY_PATH variable to use the STLPORT
268 if test -n "$STLPORT_DIR"
269 then
270 CONFIGURE_OPT="$CONFIGURE_OPT --with-stlport=$STLPORT_DIR"
272 if test -z "$LD_LIBRARY_PATH"
273 then
274 LD_LIBRARY_PATH="$STLPORT_DIR/lib"
275 else
276 LD_LIBRARY_PATH="$STLPORT_DIR/lib:$LD_LIBRARY_PATH"
280 # Set the configure option to use the rigth python version
281 if test -n "$PYTHON_VERSION"
282 then
283 CONFIGURE_OPT="$CONFIGURE_OPT --with-python-version=$PYTHON_VERSION"
287 ###########################################################################
289 echo ""
290 echo "Using source directory : $SRC_DIR"
292 # If we are in debug mode we use the debug build and install directories
293 # Otherwise we use the release build and install directories
294 if test "$DEBUG_MODE" = 'ON'
295 then
296 BUILD_DIR=$BUILD_DEBUG
297 INSTALL_DIR=$INSTALL_DEBUG
298 CONFIGURE_OPT="$CONFIGURE_OPT --with-debug"
299 PATH="$INSTALL_DEBUG/bin:$PATH"
300 LD_LIBRARY_PATH="$INSTALL_DEBUG/lib:LD_LIBRARY_PATH"
301 else
302 BUILD_DIR=$BUILD_RELEASE
303 INSTALL_DIR=$INSTALL_RELEASE
304 BUILD_CFLAGS="$BUILD_CFLAGS"
305 BUILD_CXXFLAGS="$BUILD_CXXFLAGS"
306 PATH="$INSTALL_RELEASE/bin:$PATH"
307 LD_LIBRARY_PATH="$INSTALL_RELEASE/lib:$LD_LIBRARY_PATH"
309 export PATH
310 export LD_LIBRARY_PATH
312 # Set where to install and where find NeL library files
313 CONFIGURE_OPT="$CONFIGURE_OPT --prefix=$INSTALL_DIR --with-nel=$INSTALL_DIR"
315 # Get if it's a static and/or a dynamic compilation
316 if test "$STATIC_MODE" != "$DYNAMIC_MODE"
317 then
318 if test "$STATIC_MODE" = 'ON'
319 then
320 CONFIGURE_OPT="--enable-static=yes --enable-shared=no $CONFIGURE_OPT"
323 if test "$DYNAMIC_MODE" = 'ON'
324 then
325 CONFIGURE_OPT="--enable-static=no --enable-shared=yes $CONFIGURE_OPT"
327 else
328 if test "$DYNAMIC_MODE" = 'OFF' -a "$STATIC_MODE" = 'OFF'
329 then
330 echo "*** ERROR: You must set building of static and/or dynamic libraries ***" >&2
331 printUsage
332 exit 1
333 else
334 echo "*** WARNING: Building both static and dynamic libraries ***" >&2
338 if test $# -eq 0
339 then
340 echo "*** ERROR: You have to decide what to do !... ***" >&2
341 printUsage
342 exit 1
346 case $1 in
348 # Modules initialisation
349 init)
350 BUILD_ARG=$2
352 $RYZOM_PATH/tools/scripts/linux/buildmode
354 case "$BUILD_ARG" in
356 nel|nelns|snowballs)
357 # Create the build directories
358 if test ! -d $BUILD_DIR/$BUILD_ARG
359 then
360 echo -n "Creating $BUILD_DIR/$ARG ..."
361 mkdir -p $BUILD_DIR/$BUILD_ARG \
362 || printError "cannot create the $BUILD_DIR/$BUILD_ARG directory"
363 echo " done"
366 # Erase the already existing configuration cache
367 rm -f $BUILD_DIR/$BUILD_ARG/config.cache \
368 $BUILD_DIR/$BUILD_ARG/config.h
370 shift
371 shift
373 # Run the bootstrap script
374 cd $SRC_DIR/$BUILD_ARG \
375 || printError "You must get the source files first !..."
376 sh autogen.sh
378 # Run the configure script
379 cd $BUILD_DIR/$BUILD_ARG
380 CFLAGS="$BUILD_CFLAGS" CXXFLAGS="$BUILD_CXXFLAGS" \
381 $SRC_DIR/$BUILD_ARG/configure $CONFIGURE_OPT $* || exit 1
384 *) echo "*** ERROR: $BUILD_ARG : Unknown module ***" >&2
385 printUsage
386 exit 1
389 esac
392 # Modules compilation
393 nel|nelns|snowballs)
394 BUILD_MODULE=$1
395 shift
397 # VPATH compilation and NeL include's Makefile.am command
398 # '$(wildcard *.h)' doesn't like each other very much. So the
399 # include files must be copied in NeL's compilation directory
400 # before each build (in case one or several header files changed).
401 if test "$BUILD_MODULE" = "nel"
402 then
403 # Delete any existing include file in the compilation
404 # directory to avoid any kind of conflict
405 if test -d $BUILD_DIR/nel/include/nel
406 then
407 cd $BUILD_DIR/nel/include/nel
408 find . -type f -name \*.h -exec rm -rf \{\} \;
409 else
410 printError "You must get the source files first !..."
413 # Copy the headers
414 mkdir -p $BUILD_DIR/nel \
415 && cp -RfPp $NEL_SRC/include $BUILD_DIR/nel
417 # Remove from the compilation directory the useless CVS
418 # information
419 cd $BUILD_DIR/nel/include \
420 && find . -prune -type d -name CVS -exec rm -rf \{\} \;
424 cd $BUILD_DIR/$BUILD_MODULE || exit 1
426 # Launch make in silent mode or not, depending of the config.
427 if test $SILENT_MODE = 'ON'
428 then
429 make $MAKE_ARGS $* | buildquiet
430 else
431 make $MAKE_ARGS $*
435 *) echo "*** ERROR: $1 : Unknown argument ***" >&2
436 printUsage
437 exit 1
440 esac
442 exit 0
444 # End of file