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