]> rtime.felk.cvut.cz Git - CanFestival-3.git/blob - configure
Segmentation Fault on closing fixed
[CanFestival-3.git] / configure
1 #!/bin/bash
2
3 #
4 # Copyright (C) 2004 Edouard TISSERRANT, Laurent BESSARD
5 # Based on Gabriel Gerhardsson's cacheprobe configure script. 
6
7 # This file is part of CanFestival, a library implementing CanOpen Stack. 
8
9 # This library is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU Lesser General Public
11 # License as published by the Free Software Foundation; either
12 # version 2.1 of the License, or (at your option) any later version.
13
14 # This library is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17 # Lesser General Public License for more details.
18
19 # You should have received a copy of the GNU Lesser General Public
20 # License along with this library; if not, write to the Free Software
21 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
22
23
24 ###########################################################################
25 #                       DEFAULT CANFESTIVAL DEFINES                       #
26 ###########################################################################
27
28 # Number of can bus to use 
29 MAX_CAN_BUS_ID=1
30
31 # max bytes to transmit by SDO Put 4 if you only support expedited transfert.
32 #For a normal transfert, (usually for a string), put the maximum string size to transfer.
33 SDO_MAX_LENGTH_TRANSFERT=32
34
35 # Number of SDO from differents nodes that the node can manage concurrently.   
36 #for a slave node, usually put 1.
37 SDO_MAX_SIMULTANEOUS_TRANSFERTS=4
38
39 # Used for NMTable[bus][nodeId]   
40 # You can put less of 128 if on the netwo
41 # are connected only smaller nodeId node.
42 NMT_MAX_NODE_ID=128
43
44 #Timeout in milliseconds for SDO.
45 #    Comment the #define if not used (infinite wait for SDO response message)
46 SDO_TIMEOUT_MS=3000
47
48 MAX_NB_TIMER=32
49
50 # Generic timers declaration defaults
51 US_TO_TIMEVAL_FACTOR=
52 TIMEVAL=
53 TIMEVAL_MAX=
54
55 # Default to little-endian
56 CANOPEN_BIG_ENDIAN=
57
58 # Max number of active errors managed in error_data structure.
59 EMCY_MAX_ERRORS=8
60
61 #Timeout in milliseconds for LSS.
62 LSS_TIMEOUT_MS=1000
63 #Timeout in milliseconds for LSS FastScan.
64 LSS_FS_TIMEOUT_MS=100
65
66 ###########################################################################
67 #                             DEFAULT BUILD OPTIONS                       #
68 ###########################################################################
69
70 #default target
71 SUB_TARGET=
72
73 # First compiler option - we will check if it exists
74 CC1=gcc
75 # Second compiler option - we will check if it exists
76 CC2=cc
77
78 # Install prefix
79 SUB_PREFIX=
80
81 # Used for C compiler test/detection 
82 CFLAGS=
83 test=conftest
84 rm -f $test $test.c
85
86 if [ "$XENO_CONFIG" = "" ]; then
87         XENO_CONFIG=/usr/xenomai/bin/xeno-config
88 fi
89
90 if [ "$RTAI_CONFIG" = "" ]; then
91         RTAI_CONFIG=/usr/realtime/bin/rtai-config
92 fi
93
94 ###########################################################################
95 #                          ARGUMENTS PARSING                              #
96 ###########################################################################
97 while [ $# -ge 1 ]; do
98         optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
99         
100         case $1 in
101         --cc=*)         CC=$optarg;;
102         --cxx=*)        CXX=$optarg;;
103         --ld=*)         LD=$optarg;;
104         --binutils=*)   BINUTILS_PREFIX=$optarg;;
105         --arch=*)       SUB_ARCH_NAME=$optarg;;
106         --os=*)         SUB_OS_NAME=$optarg;;
107         --kerneldir=*)  SUB_KERNELDIR=$optarg;;
108         --prefix=*)     SUB_PREFIX=$optarg;;
109         --target=*)     SUB_TARGET=$optarg;;
110         --can=*)        SUB_CAN_DRIVER=$optarg;;
111         --timers=*)     SUB_TIMERS_DRIVER=$optarg;;
112         --wx=*)         SUB_WX=$optarg;
113                         echo "Forced wx detection to $optarg";;
114         --disable-Ox)   DISABLE_OPT=1;
115                         echo "On user request: Won't optimize with \"-Ox\"";;
116         --disable-dll)  DISABLE_DLL=1;
117                         echo "On user request: Won't create and link to dll";;
118         --enable-lss)   ENABLE_LSS=1;
119                         echo "On user request: LSS services enabled";;
120         --enable-lss-fs)        ENABLE_LSS_FS=1;
121                         echo "On user request: LSS FastScan service enabled";;
122         --debug=*)      DEBUG=$optarg;;
123         --MAX_CAN_BUS_ID=*)     MAX_CAN_BUS_ID=$optarg;;
124         --SDO_MAX_LENGTH_TRANSFERT=*)   SDO_MAX_LENGTH_TRANSFERT=$optarg;;
125         --SDO_MAX_SIMULTANEOUS_TRANSFERTS=*)    SDO_MAX_SIMULTANEOUS_TRANSFERTS=$optarg;;
126         --NMT_MAX_NODE_ID=*)    NMT_MAX_NODE_ID=$optarg;;
127         --SDO_TIMEOUT_MS=*)     SDO_TIMEOUT_MS=$optarg;;
128         --CANOPEN_BIG_ENDIAN=*) CANOPEN_BIG_ENDIAN=$optarg;;
129         --MAX_NB_TIMER=*) MAX_NB_TIMER=$optarg;;
130         --EMCY_MAX_ERRORS=*) EMCY_MAX_ERRORS=$optarg;;
131         --LSS_TIMEOUT_MS=*)     LSS_TIMEOUT_MS=$optarg;;
132         --LSS_FS_TIMEOUT_MS=*)  LSS_FS_TIMEOUT_MS=$optarg;;
133         --help)
134                 echo    "Usage: ./configure [options]"
135                 echo    "Options:"
136                 echo    " --cc=foo      Use C compiler 'foo' instead of defaults ${CC1} or ${CC2}."
137                 echo    " --cxx=foo     Use C++ compiler 'foo' instead of defaults g++."
138                 echo    " --ld=foo      Use linker 'foo' instead of ld."
139                 echo    " --arch=foo    Use architecture 'foo' instead of trying to autodetect."
140                 echo    " --os=foo      Use operative system 'foo' instead of trying to autodetect."
141                 echo    " --kerneldir=foo   Use 'foo' as kernel source directory instead of default"
142                 echo    " --prefix=foo  Use prefix 'foo' instead of default ${SUB_PREFIX}."
143                 echo    " --target=foo  Use 'foo' as build target."
144                 echo    "               \"unix\" for unix-like systems (Linux, Cygwin)"
145                 echo    "               \"win32\" for win32 systems (native, mingw or VC++)"
146                 echo    "               \"hcs12\" for HCS12 micro-controller"
147                 echo    " --can=foo     Use 'foo' as CAN driver"
148                 echo    "               \"peak_linux\" use Linux build host installed Peak driver and library"
149                 echo    "                 see http://www.peak-system.com/linux/"
150                 echo    "               \"peak_win32\" use win32 PcanLight Peak driver and library with Cygwin" 
151                 echo    "                 see http://www.peak-system.com/themen/download_gb.html"
152                 echo    "               \"virtual\" use unix pipe based virtual can driver"
153                 echo    "               \"virtual_kernel\" use kernel module virtual can driver"
154                 echo    "               \"socket\" use socket-can  "
155                 echo    "                 see http://developer.berlios.de/projects/socketcan/"
156                 echo    "               \"lincan\" lincan driver"
157                 echo    "                 see http://www.ocera.org/download/components/WP7/lincan-0.3.3.html"
158                 echo    "               \"can4linux\" can4linux driver"
159                 echo    "                 see http://www.port.de/engl/canprod/hw_can4linux.html"
160                 echo    " --timers=foo  Use 'foo' as TIMERS driver (can be 'unix', 'xeno', 'rtai' or 'kernel')"
161                 echo    " --wx=foo      Force result of WxWidgets detection (0 or 1)"
162                 echo    " --binutils=path   Override binutils path detection (as regards \$CC content)"
163                 echo    " --disable-dll Disable run-time dynamic linking of can, led and nvram drivers"
164                 echo    " --enable-lss  Enable the LSS services"
165                 echo    " --enable-lss-fs  Enable the LSS FastScan service"
166                 echo    " --disable-Ox  Disable gcc \"-Ox\" optimizations."
167                 echo    " --debug=foo,foo,..   Enable debug messages, ERR -> only errors, WAR)."
168                 echo    "               \"PDO\" send errors and warnings through PDO messages"
169                 echo    "               \"ERR\" print errors only, to stdout"
170                 echo    "               \"WAR\" print errors and warnings, to stdout"
171                 echo    "               \"MSG\" print messages content, to stdout"
172                 echo
173                 echo    "Stack compilation constants"
174                 echo    " --MAX_CAN_BUS_ID [=1] Number of can bus to use"
175                 echo    " --SDO_MAX_LENGTH_TRANSFERT [=32] max bytes to transmit by SDO"
176                 echo    " --SDO_MAX_SIMULTANEOUS_TRANSFERTS [=4] Number of SDO that the node can manage concurrently"
177                 echo    " --NMT_MAX_NODE_ID [=128] can be reduced to gain memory on small network"
178                 echo    " --SDO_TIMEOUT_MS [=3000] Timeout in milliseconds for SDO (None to disable the feature)"
179                 echo    " --EMCY_MAX_ERRORS [=8] Max number of active errors managed in error_data structure"
180                 echo    " --LSS_TIMEOUT_MS [=1000] Timeout in milliseconds for LSS services."
181                 echo    "                          LSS must be enabled with \"--enable-lss\""
182                 echo    " --LSS_FS_TIMEOUT_MS [=100] Timeout in milliseconds for LSS FastScan service."
183                 echo    "                            LSS FastScan must be enabled with \"--enable-lss-fs\""
184                 exit 0;;
185         *)              echo "Unknown argument ${1}"; exit -1;;
186         esac
187
188         shift
189 done
190
191 ###########################################################################
192 #                              GUESS OS/ARCH                              #
193 ###########################################################################
194
195 if [ "$SUB_OS_NAME" = "" ]; then
196         SUB_OS_NAME="`(uname -s | sed \"s/\//-/\" | sed \"s/_/-/\" \
197                         | sed \"s/-.*//g\") 2>&1`"
198 fi
199
200 if [ "$SUB_ARCH_NAME" = "" ]; then
201         if [ "$CC" = "" ]; then
202                 A_NAME="`(uname -m) 2>&1`"
203         else
204                 A_NAME="`$CC -dumpmachine | sed 's:-.*::'`"
205         fi
206 fi
207
208 # x86
209 if [ "$A_NAME" = "i386" -o "$A_NAME" = "i486" -o "$A_NAME" = "i586" -o "$A_NAME" = "i686" -o "$A_NAME" = "x86" ]; then
210         SUB_ARCH_NAME=x86
211 fi
212
213 # x86_64
214 if [ "$A_NAME" = "x86_64" ]; then
215         SUB_ARCH_NAME=x86_64
216 fi
217
218 # ppc
219 if [ "$A_NAME" = "powerpc" ]; then
220         SUB_ARCH_NAME=ppc
221 fi
222
223 # ppc64
224 if [ "$A_NAME" = "powerpc64" ]; then
225         SUB_ARCH_NAME=ppc64
226 fi
227
228 # arm
229 if [ "$A_NAME" = "arm" ]; then
230         SUB_ARCH_NAME=arm
231 fi
232
233 # mingw32
234 if [ "$A_NAME" = "mingw32" ]; then
235         SUB_ARCH_NAME=mingw32
236 fi
237
238 if [ "$SUB_ARCH_NAME" = "" ]; then
239         echo "Error: could not detect what architecture this system is running!"
240         echo "Please supply manually instead with \"--arch=foo\""
241         exit -1
242 fi
243
244 echo "Host OS: ${SUB_OS_NAME}"
245 echo "Host arch: ${SUB_ARCH_NAME}"
246
247 if [ "$SUB_ARCH_NAME" = "x86_64" -a "$CC" = "gcc" ]; then
248         # Only if we are on x86_64 and using gcc
249         # For shared library generation, it needs this
250         SUB_PROG_CFLAGS=-fPIC
251 fi
252
253 if [ "$SUB_ARCH_NAME" = "ppc" -o "$SUB_ARCH_NAME" = "powerpc" ]; then
254         # PowerPC uses big endian format
255         CANOPEN_BIG_ENDIAN=1
256 fi
257
258 ###########################################################################
259 #                      DEFAULT TARGET/DRIVERS GUESSING                    #
260 ###########################################################################
261 # If target not specified, try to guess one
262 if [ "$SUB_TARGET" = "" ]; then
263         if [ "$SUB_OS_NAME" = "CYGWIN" ]; then
264                 echo "Choosing unix (cygwin) target"
265                 SUB_TARGET=unix
266         fi
267         if [ "$SUB_OS_NAME" = "Linux" ]; then
268                 echo "Choosing unix target"
269                 SUB_TARGET=unix
270         fi
271         if [ "$SUB_OS_NAME" = "MINGW32" ]; then
272                 echo "Choosing windows target"
273                 SUB_TARGET=win32
274         fi
275 fi
276
277 # Try to guess can
278 if [ "$SUB_CAN_DRIVER" = "" ]; then
279         if [ "$SUB_TARGET" = "unix" ]; then
280                 if [ -e /usr/lib/libpcan.so ]; then 
281                         echo "Choosing installed Peak driver as CAN driver."
282                         SUB_CAN_DRIVER=peak_linux
283                 elif [ "$SUB_OS_NAME" = "CYGWIN" -a "PCAN_LIB" != "" ]; then
284                         echo "Choosing installed Peak driver as CAN driver."
285                         SUB_CAN_DRIVER=peak_win32               
286                 elif [ -e /usr/lib/libcanlib.so ]; then 
287                         echo "Choosing installed Kvaser driver as CAN driver. (unix)"
288                         SUB_CAN_DRIVER=kvaser
289                 elif [ "$SUB_OS_NAME" = "CYGWIN" -a "$KVASER_DLL_PATH" != "" ]; then
290                         echo "Choosing installed Kvaser driver as CAN driver. (cygwin)"
291                         SUB_CAN_DRIVER=kvaser
292                 else
293                         echo "Choosing virtual CAN driver."
294                         SUB_CAN_DRIVER=virtual
295                 fi
296         fi
297 fi
298
299 # If target is unix, default timers also
300 if [ "$SUB_TARGET" = "unix" -a "$SUB_TIMERS_DRIVER" = "" ]; then
301         echo "Choosing unix timers driver."
302         SUB_TIMERS_DRIVER=unix
303 fi
304
305 # If target is windows, default timers also
306 if [ "$SUB_TARGET" = "win32" -a "$SUB_TIMERS_DRIVER" = "" ]; then
307         echo "Choosing windows timers driver."
308         SUB_TIMERS_DRIVER=win32
309 fi
310
311 # Warn for unstalled peak driver if choosen
312 if [ "$SUB_CAN_DRIVER" = "peak" ]; then
313         if [ ! -e /usr/lib/libpcan.so ]; then 
314                 echo "Peak driver hasn't been installed !"
315                 exit -1
316         fi
317 fi
318
319 # Warn for unstalled kvaser driver if choosen
320 if [ "$SUB_CAN_DRIVER" = "kvaser" ]; then
321         if [ "$SUB_OS_NAME" = "CYGWIN" ]; then
322         if [ ! -e "$KVASER_DLL_PATH/canlib32.dll" ]; then 
323             echo "Kvaser driver hasn't been installed (cygwin)"
324             exit -1
325         fi
326     elif  [ "$SUB_OS_NAME" = "LINUX" ]; then
327         if [ ! -e /usr/lib/libcanlib.so ]; then 
328             echo "Kvaser driver hasn't been installed (unix)"
329             exit -1
330         fi
331         fi
332 fi
333
334 ###########################################################################
335 #              TARGET/DRIVER SPECIFIC CFLAGS and OPTIONS                  #
336 ###########################################################################
337 if [ "$SUB_TARGET" = "hcs12" ]; then
338         # Only if we want to compile for a C HCS12
339        # it is a big endian architecture.
340        CANOPEN_BIG_ENDIAN=1
341         # search for gcc hcs12 compiler m6811-elf-gcc or m68hc12-gcc ?
342         if [ "$CC" = "" ]; then
343                 which m6811-elf-gcc >/dev/null 2>&1
344                 if (( $? )); then 
345                         which m68hc12-gcc >/dev/null 2>&1
346                         if (( $? )); then 
347                                 echo "Please use --cc flag to specify compiler"
348                                 exit 0
349                         else
350                                 CC=m68hc12-gcc 
351                         fi
352                 else
353                         CC=m6811-elf-gcc
354                         SUB_PROG_CFLAGS=-m68hc12
355                 fi
356         fi
357 fi      
358
359 #### CAN_DRIVER ####
360
361 if [ "$SUB_CAN_DRIVER" = "kvaser" ]; then
362         if [ "$SUB_TARGET" = "unix" ]; then
363         if  [ "$SUB_OS_NAME" = "LINUX" ]; then
364             SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lcanlib
365                 elif [ "$SUB_OS_NAME" = "CYGWIN" ]; then
366                 if [ "$KVASER_INCLUDE_PATH" = "" -o "$KVASER_DLL_PATH" = "" ]; then
367                         echo "!!! ERROR !!! Please set KVASER_DLL_PATH and KVASER_INCLUDE_PATH to appropriate paths ! "
368             else
369                 SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -L$KVASER_DLL_PATH\ -lcanlib32
370                 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -I$KVASER_INCLUDE_PATH
371             fi
372         fi
373     fi        
374 fi
375
376 if [ "$SUB_CAN_DRIVER" = "peak_linux" ]; then
377     SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lpcan
378 fi
379
380 if [ "$SUB_CAN_DRIVER" = "vscom" ]; then
381     SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lvs_can_api
382 fi
383
384 PW32DIR=drivers/can_peak_win32
385 if [ "$SUB_CAN_DRIVER" = "peak_win32" ]; then
386         if [ "$PCAN_HEADER" = "" -o "$PCAN_LIB" = "" ]; then
387                 echo "!!! ERROR !!! Please set PCAN_LIB PCAN_HEADER [PCAN_INCLUDE] to appropriate paths ! "
388         fi
389         SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -liberty\ \'$PCAN_LIB\'
390         echo "Converting PcanLib header files for gcc -> $PW32DIR/cancfg.h"
391         cat $PW32DIR/cancfg.h.head $PCAN_INCLUDE/$PCAN_HEADER > $PW32DIR/cancfg.h
392         echo >> $PW32DIR/cancfg.h
393         # second port handling
394         if [ "$PCAN2_HEADER" != "" ]; then
395                 echo "Stripping down second Pcan Light header "
396                 echo >> $PW32DIR/cancfg.h
397                 echo "// Stripped PcanLight header to prevent typedef conflicts ">> $PW32DIR/cancfg.h
398                 echo >> $PW32DIR/cancfg.h
399                 grep __stdcall $PCAN_INCLUDE/$PCAN2_HEADER >> $PW32DIR/cancfg.h
400                 echo '#define PCAN2_HEADER_' >> $PW32DIR/cancfg.h
401                 SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ \'$PCAN2_LIB\'
402         fi
403         if grep -q CANHwType $PW32DIR/cancfg.h ; then
404                 echo "Peak Init HwType, IO_Port and IRQ will be passed in environment :"
405                 echo "  PCANHwType PCANIO_Port PCANInterupt"
406                 echo '#define extra_PCAN_init_params' >> $PW32DIR/cancfg.h
407         fi
408         if ! grep -q CAN_Init $PW32DIR/cancfg.h ; then
409                 echo "Pcan Light header/lib is for second port of device only"
410                 echo "CAN_* calls redefined to CAN2_* "
411                 echo '#define CAN_Init CAN2_Init' >> $PW32DIR/cancfg.h
412                 echo '#define CAN_Read CAN2_Read' >> $PW32DIR/cancfg.h
413                 echo '#define CAN_Write CAN2_Write' >> $PW32DIR/cancfg.h
414                 echo '#define CAN_Close CAN2_Close' >> $PW32DIR/cancfg.h
415         fi
416         cat $PW32DIR/cancfg.h.tail >> $PW32DIR/cancfg.h
417 fi
418
419 if [ "$SUB_CAN_DRIVER" = "none" ]; then
420         SUB_CAN_DRIVER=
421 fi
422
423 #### TIMERS_DRIVER ####
424
425 if [ "$SUB_TIMERS_DRIVER" = "unix" ]; then
426         if [ "$SUB_OS_NAME" != "CYGWIN" ]; then
427            SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lpthread\ -lrt
428         fi
429 fi
430
431 if [ "$SUB_TIMERS_DRIVER" = "xeno" ]; then
432         RT_LIB_DIR=`$XENO_CONFIG --library-dir`\ -Wl,-rpath\ `$XENO_CONFIG --library-dir`
433     SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ `$XENO_CONFIG --xeno-ldflags`\ -L$RT_LIB_DIR\ -lnative\ -lrtdm
434         SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DUSE_XENO\ `$XENO_CONFIG --xeno-cflags`
435     RTCAN_SOCKET=1
436 fi
437
438 if [ "$SUB_TIMERS_DRIVER" = "rtai" ]; then
439         RT_LIB_DIR=`$RTAI_CONFIG --library-dir`\ -Wl,-rpath\ `$RTAI_CONFIG --library-dir`
440     SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ `$RTAI_CONFIG --lxrt-ldflags`\ -L$RT_LIB_DIR\ -llxrt\ -lrtdm
441         SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DUSE_RTAI\ `$RTAI_CONFIG --lxrt-cflags`
442     RTCAN_SOCKET=1
443 fi
444
445 if [ "$SUB_TIMERS_DRIVER" = "kernel" ]; then
446         DISABLE_DLL=1
447         if [ "$SUB_KERNELDIR" = "" ]; then
448                 # use directory of current kernel
449                 SUB_KERNELDIR=/lib/modules/$(uname -r)/build
450         fi
451 fi
452
453 if [ "$SUB_TIMERS_DRIVER" = "none" ]; then
454         SUB_TIMERS_DRIVER=
455 fi
456
457 ###########################################################################
458 #                              GUESS TOOLCHAIN                            #
459 ###########################################################################
460 # If CC is empty, the user wanted automatic detection
461 if [ "$CC" = "" ]; then
462         # Check for second compiler, CC2
463         cat > $test.c <<EOF
464         int main() { return 0; }
465 EOF
466         if test "`($CC2 -c $CFLAGS $test.c) 2>&1`" = ""; then
467                 DETECTCC=$CC2
468                 echo "Checking for ${CC2}... Yes."
469         else
470                 echo "Checking for ${CC2}... No."
471         fi
472         rm -f $test.c $test.o
473         
474         # Check for first compiler, CC1
475         cat > $test.c <<EOF
476         int main() { return 0; }
477 EOF
478         if test "`($CC1 -c $CFLAGS $test.c) 2>&1`" = ""; then
479                 DETECTCC=$CC1
480                 echo "Checking for ${CC1}... Yes."
481         else
482                 echo "Checking for ${CC1}... No."
483         fi
484         rm -f $test.c $test.o
485         CC=$DETECTCC
486 fi
487 # Check if we decided on a compiler after all
488 if [ "$CC" = "" ]; then
489         echo "Error: Could not find a C compiler"
490         echo "Please supply the wanted compiler"
491         exit -1
492 fi
493
494 echo "Using ${CC} as a C compiler"
495
496 if [ "$BINUTILS_PREFIX" = "" ]; then
497         SUB_BINUTILS_PREFIX=`echo "$CC" | sed 's/gcc$//'`
498 else
499         SUB_BINUTILS_PREFIX=$BINUTILS_PREFIX
500 fi
501
502 if [ "$CXX" = "" ]; then
503         CXX=${SUB_BINUTILS_PREFIX}g++
504 fi
505
506 echo "Using ${CXX} as a C++ compiler"
507
508 if [ "$SUB_TARGET" = "win32" ]; then
509         # on cygwin/mingw, choose  g++ as a linker for native target
510         if [ "$LD" = "" ]; then
511                 LD=$CXX
512         fi
513         if [ "$SUB_OS_NAME" = "CYGWIN" ]; then
514                 SUB_PROG_CFLAGS="-mno-cygwin"
515         fi
516 fi      
517
518 if [ "$SUB_TARGET" = "unix" ]; then
519         if [ "$LD" = "" ]; then
520                 LD=$CC
521         fi
522 fi
523
524 echo "Using ${LD} as a linker"
525
526 # Guess prefix as regard cross compiling target machine
527 if [ "$SUB_PREFIX" = "" ]; then
528         $CC -dumpspecs |grep -A 1 'cross_compile'|grep -q 1
529         if (( $? )); then 
530                 SUB_PREFIX=/usr/local
531                 echo "Not cross-compiling. Will install in $SUB_PREFIX";
532         else
533                 SUB_PREFIX=/usr/`$CC -dumpmachine`
534                 echo "This is a cross-compiler. Will install in $SUB_PREFIX";                   
535         fi
536 fi
537
538 echo "Using prefix: ${SUB_PREFIX}"
539
540 ###########################################################################
541 #                           GUESS DEPENDENCIES                            #
542 ###########################################################################
543
544 if [ "$SUB_WX" = "" ]; then
545         if which wx-config >/dev/null 2>&1; then
546                 echo -n "Testing wxWidgets compiles ... "
547                 cat > /tmp/wx_test.cpp <<EOF
548 #include "wx/wx.h"
549 class MyApp : public wxApp
550 {
551 };
552 IMPLEMENT_APP(MyApp)
553 EOF
554                 if $CXX /tmp/wx_test.cpp `wx-config --cxxflags` `wx-config --libs` -o /tmp/wx_test >/dev/null 2>&1 ; then
555                         SUB_WX=1
556                         echo "Yes"
557                 else
558                         SUB_WX=0
559                         echo "No"
560                 fi
561                 rm -f /tmp/wx_test*
562         else
563                 SUB_WX=0
564                 echo "No wxWidgets available"
565         fi
566 fi
567 ###########################################################################
568 #                   CANFESTIVAL DEFINES --> config.h                      #
569 ###########################################################################
570 # Some CONSTANTS preparation
571
572 # Create include/config.h with the relevant contents
573 rm -f include/config.h
574 echo "/* !!!!!!!!!! FILE GENERATED by configure. DO NOT EDIT !!!!!!!!!!*/" >>  include/config.h
575 echo "" >>  include/config.h
576 echo "/*"\ >>  include/config.h
577 echo "This file is part of CanFestival, a library implementing CanOpen Stack." >> include/config.h
578 echo "" >> include/config.h
579 echo "Copyright (C): Edouard TISSERANT and Francis DUPIN" >> include/config.h
580 echo "See COPYING file for copyrights details." >> include/config.h
581 echo "" >> include/config.h
582 echo "This library is free software; you can redistribute it and/or" >> include/config.h
583 echo "modify it under the terms of the GNU Lesser General Public" >> include/config.h
584 echo "License as published by the Free Software Foundation; either" >> include/config.h
585 echo "version 2.1 of the License, or (at your option) any later version." >> include/config.h
586 echo "" >> include/config.h
587 echo "This library is distributed in the hope that it will be useful," >> include/config.h
588 echo "but WITHOUT ANY WARRANTY; without even the implied warranty of" >> include/config.h
589 echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU" >> include/config.h
590 echo "Lesser General Public License for more details." >> include/config.h
591 echo "" >> include/config.h
592 echo "You should have received a copy of the GNU Lesser General Public" >> include/config.h
593 echo "License along with this library; if not, write to the Free Software" >> include/config.h
594 echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA" >> include/config.h
595 echo "*/" >> include/config.h
596 echo "" >> include/config.h
597 echo "#ifndef _CONFIG_H_" >> include/config.h
598 echo "#define _CONFIG_H_" >> include/config.h
599 echo "" >> include/config.h
600 for i in \
601  MAX_CAN_BUS_ID\
602  SDO_MAX_LENGTH_TRANSFERT\
603  SDO_MAX_SIMULTANEOUS_TRANSFERTS\
604  NMT_MAX_NODE_ID\
605  SDO_TIMEOUT_MS\
606  MAX_NB_TIMER\
607  CANOPEN_BIG_ENDIAN\
608  US_TO_TIMEVAL_FACTOR\
609  TIMEVAL\
610  TIMEVAL_MAX\
611  RTCAN_SOCKET\
612  EMCY_MAX_ERRORS\
613  LSS_TIMEOUT_MS\
614  LSS_FS_TIMEOUT_MS; do
615 if [ "${!i}" = "" ]; then
616 echo "/* $i is not defined */" >> include/config.h
617 else
618 echo "#define $i ${!i}" >> include/config.h
619 fi
620 done    
621 echo "" >> include/config.h
622
623 for i in \
624  SDO_MAX_SIMULTANEOUS_TRANSFERTS\
625  NMT_MAX_NODE_ID\
626  EMCY_MAX_ERRORS; do
627         echo "#define REPEAT_"$i"_TIMES(repeat)\\">> include/config.h
628         times=${!i}
629         result=""
630         for (( j=0; j<times; j++ ));do
631                 result="$result repeat"
632         done
633         echo $result >> include/config.h
634 done
635
636 echo "#endif /* _CONFIG_H_ */" >> include/config.h
637
638 ###########################################################################
639 #                           DEBUG DEFINES/CFLAGS                          #
640 ###########################################################################
641
642 save_ifs="$IFS"; IFS=','
643
644 for DEBUG_METHOD in $DEBUG; 
645         do
646             IFS="$save_ifs"
647             case $DEBUG_METHOD in
648                 ERR)ERR=1;;
649                 WAR)WAR=1;ERR=1;;
650                 MSG)MSG=1;;
651                 PDO)PDO=1;WAR=1;ERR=1;;
652                 *)echo ""
653                   echo "$DEBUG_METHOD is not a valid debug's method"
654                   echo "Possible Debug's methods are : \"ERR\", \"WAR\", \"MSG\", \"PDO\""
655                   exit -1
656                   ;;
657         esac    
658 done
659
660 if [ $WAR ]; then
661         SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_WAR_CONSOLE_ON;
662 fi
663
664 if [ $ERR ]; then
665         SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_ERR_CONSOLE_ON;
666 fi
667
668 if [ $MSG ]; then
669         SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_MSG_CONSOLE_ON;
670 fi
671
672 if [ $PDO ]; then
673         SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_PDO_CONSOLE_ON;
674 fi
675
676 if [ $DEBUG ]; then
677         SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -g
678 fi
679
680 IFS="$save_ifs"
681
682 if [ "$DISABLE_OPT" = "1" ]; then
683         SUB_OPT_CFLAGS=
684 else
685         SUB_OPT_CFLAGS=\$\(OPT_CFLAGS\)
686 fi
687
688 if [ "$DISABLE_DLL" = "1" ]; then
689         SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DNOT_USE_DYNAMIC_LOADING
690         SUB_ENABLE_DLL_DRIVERS=0
691 else
692         SUB_ENABLE_DLL_DRIVERS=1
693         if [ "$SUB_TARGET" = "win32" ]; then
694                 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS
695         else
696                 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -ldl
697         fi
698         
699 fi
700
701
702 if [ "$DISABLE_DLL" = "1" ]; then
703         SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ $SUB_CAN_DLL_CFLAGS
704 fi
705
706 if [ $ENABLE_LSS ]; then
707         SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DCO_ENABLE_LSS;
708         SUB_ENABLE_LSS=1
709         if [ $ENABLE_LSS_FS ]; then
710                 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DCO_ENABLE_LSS_FS;
711         fi
712 else
713         SUB_ENABLE_LSS=0
714 fi
715
716 ###########################################################################
717 #                              CREATE MAKEFILES                           #
718 ###########################################################################
719 # General Makefiles
720 MAKEFILES=Makefile.in\
721 \ src/Makefile.in\
722 \ drivers/Makefile.in\
723 \ objdictgen/Makefile.in\
724 \ examples/Makefile.in\
725 \ objdictgen/canfestival_config.py.in
726
727 # Drivers dependent Makefiles
728 if [ "$SUB_TIMERS_DRIVER" != "" ]; then
729         MAKEFILES=$MAKEFILES\
730 \       drivers/timers_$SUB_TIMERS_DRIVER/Makefile.in
731 fi
732
733 if [ "$SUB_CAN_DRIVER" != "" ]; then
734         MAKEFILES=$MAKEFILES\
735 \       drivers/can_$SUB_CAN_DRIVER/Makefile.in
736 fi
737
738 # Target dependent Makefiles
739 MAKEFILES=$MAKEFILES\ drivers/$SUB_TARGET/Makefile.in
740
741 if [ "$SUB_TARGET" = "unix" -a "$SUB_TIMERS_DRIVER" = "kernel" ]; then
742         MAKEFILES=$MAKEFILES\
743 \       examples/kerneltest/Makefile.in
744
745 elif [ "$SUB_TARGET" = "unix" ]; then
746         MAKEFILES=$MAKEFILES\
747 \       examples/TestMasterSlave/Makefile.in\
748 \       examples/TestMasterSlaveLSS/Makefile.in\
749 \       examples/SillySlave/Makefile.in\
750 \       examples/TestMasterMicroMod/Makefile.in
751 fi
752
753 if [ "$SUB_TARGET" = "win32" ]; then
754         MAKEFILES=$MAKEFILES\
755 \       examples/TestMasterSlave/Makefile.in\
756 \       examples/TestMasterSlaveLSS/Makefile.in\
757 \       examples/SillySlave/Makefile.in\
758 \       examples/TestMasterMicroMod/Makefile.in
759 fi
760
761 if [ "$SUB_WX" = "1" ]; then
762         MAKEFILES=$MAKEFILES\
763 \       examples/DS401_Master/Makefile.in\
764 \       examples/DS401_Slave_Gui/Makefile.in
765 fi
766
767 if [ "$SUB_TARGET" = "hcs12" ]; then
768         MAKEFILES=$MAKEFILES\
769 \       examples/gene_SYNC_HCS12/Makefile.in
770 fi
771
772 for makefile_in in $MAKEFILES; do
773         makefile=`echo $makefile_in | sed 's:.in$::'`
774         echo "Creating $makefile"
775         sed < $makefile_in "
776         s:SUB_CC:${CC}:
777         s:SUB_CXX:${CXX}:
778         s:SUB_LD:${LD}:
779         s:SUB_PROG_CFLAGS:${SUB_PROG_CFLAGS}:
780         s:SUB_EXE_CFLAGS:${SUB_EXE_CFLAGS}:
781         s:SUB_KERNELDIR:${SUB_KERNELDIR}:
782         s:SUB_PREFIX:${SUB_PREFIX}:
783         s:SUB_OS_NAME:${SUB_OS_NAME}:
784         s:SUB_ARCH_NAME:${SUB_ARCH_NAME}:
785         s:SUB_OPT_CFLAGS:${SUB_OPT_CFLAGS}:
786         s:SUB_TARGET:${SUB_TARGET}:
787         s:SUB_BINUTILS_PREFIX:${SUB_BINUTILS_PREFIX}:
788         s:SUB_TIMERS_DRIVER:timers_${SUB_TIMERS_DRIVER}:
789         s:SUB_CAN_DRIVER:can_${SUB_CAN_DRIVER}:
790         s:SUB_CAN_DLL_CFLAGS:${SUB_CAN_DLL_CFLAGS}:
791         s:SUB_ENABLE_DLL_DRIVERS:${SUB_ENABLE_DLL_DRIVERS}:
792         s:SUB_ENABLE_LSS:${SUB_ENABLE_LSS}:
793         s:SUB_WX:${SUB_WX}:
794         " > $makefile
795 done
796
797 echo "All done."