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