4 # Copyright (C) 2004 Edouard TISSERRANT, Laurent BESSARD
5 # Based on Gabriel Gerhardsson's cacheprobe configure script.
7 # This file is part of CanFestival, a library implementing CanOpen Stack.
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.
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.
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
24 ###########################################################################
25 # DEFAULT CANFESTIVAL DEFINES #
26 ###########################################################################
28 # Number of can bus to use
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
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
39 # Used for NMTable[bus][nodeId]
40 # You can put less of 128 if on the netwo
41 # are connected only smaller nodeId node.
44 #Timeout in milliseconds for SDO.
45 # Comment the #define if not used (infinite wait for SDO response message)
50 # Generic timers declaration defaults
55 # Default to little-endian
58 # Max number of active errors managed in error_data structure.
61 ###########################################################################
62 # DEFAULT BUILD OPTIONS #
63 ###########################################################################
65 # Leave empty for automatic detection
73 # First compiler option - we will check if it exists
75 # Second compiler option - we will check if it exists
81 # Used for C compiler test/detection
86 if [ "$XENO_CONFIG" = "" ]; then
87 XENO_CONFIG=/usr/xenomai/bin/xeno-config
90 ###########################################################################
92 ###########################################################################
93 while [ $# -ge 1 ]; do
94 optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
98 --cxx=*) CXX=$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 --debug=*) DEBUG=$optarg;;
111 --MAX_CAN_BUS_ID=*) MAX_CAN_BUS_ID=$1;;
112 --SDO_MAX_LENGTH_TRANSFERT=*) SDO_MAX_LENGTH_TRANSFERT=$1;;
113 --SDO_MAX_SIMULTANEOUS_TRANSFERTS=*) SDO_MAX_SIMULTANEOUS_TRANSFERTS=$1;;
114 --NMT_MAX_NODE_ID=*) NMT_MAX_NODE_ID=$1;;
115 --SDO_TIMEOUT_MS=*) SDO_TIMEOUT_MS=$1;;
116 --CANOPEN_BIG_ENDIAN=*) CANOPEN_BIG_ENDIAN=$1;;
117 --MAX_NB_TIMER=*) MAX_NB_TIMER=$1;;
118 --EMCY_MAX_ERRORS=*) EMCY_MAX_ERRORS=$1;;
120 echo "Usage: ./configure [options]"
122 echo " --cc=foo Use C compiler 'foo' instead of defaults ${CC1} or ${CC2}."
123 echo " --cxx=foo Use C++ compiler 'foo' instead of defaults g++."
124 echo " --ld=foo Use linker 'foo' instead of ld."
125 echo " --arch=foo Use architecture 'foo' instead of trying to autodetect."
126 echo " --os=foo Use operative system 'foo' instead of trying to autodetect."
127 echo " --prefix=foo Use prefix 'foo' instead of default ${SUB_PREFIX}."
128 echo " --target=foo Use 'foo' as build target."
129 echo " \"unix\" for unix-like systems (Linux, Cygwin)"
130 echo " \"win32\" for win32 systems (native, mingw or VC++)"
131 echo " \"hcs12\" for HCS12 micro-controller"
132 echo " --can=foo Use 'foo' as CAN driver"
133 echo " \"peak_linux\" use Linux build host installed Peak driver and library"
134 echo " see http://www.peak-system.com/linux/"
135 echo " \"peak_win32\" use win32 PcanLight Peak driver and library with Cygwin"
136 echo " see http://www.peak-system.com/themen/download_gb.html"
137 echo " \"virtual\" use unix pipe based virtual can driver"
138 echo " \"socket\" use socket-can "
139 echo " see http://developer.berlios.de/projects/socketcan/"
140 echo " \"lincan\" lincan driver"
141 echo " see http://www.ocera.org/download/components/WP7/lincan-0.3.3.html"
142 echo " --timers=foo Use 'foo' as TIMERS driver (can be either 'unix' or 'xeno')"
143 echo " --disable-dll Disable run-time dynamic linking of can, led and nvram drivers"
144 echo " --disable-Ox Disable gcc \"-Ox\" optimizations."
145 echo " --debug=foo,foo,.. Enable debug messages, ERR -> only errors, WAR)."
146 echo " \"PDO\" send errors and warnings through PDO messages"
147 echo " \"ERR\" print errors only, to stdout"
148 echo " \"WAR\" print errors and warnings, to stdout"
149 echo " \"MSG\" print messages content, to stdout"
151 echo "Stack compilation constants"
152 echo " --MAX_CAN_BUS_ID [=1] Number of can bus to use"
153 echo " --SDO_MAX_LENGTH_TRANSFERT [=32] max bytes to transmit by SDO"
154 echo " --SDO_MAX_SIMULTANEOUS_TRANSFERTS [=4] Number of SDO that the node can manage concurrently"
155 echo " --NMT_MAX_NODE_ID [=128] can be reduced to gain memory on small network"
156 echo " --SDO_TIMEOUT_MS [=3000] Timeout in milliseconds for SDO (None to disable the feature)"
157 echo " --EMCY_MAX_ERRORS [=8] Max number of active errors managed in error_data structure"
159 *) echo "Unknown argument ${1}"; exit -1;;
165 ###########################################################################
167 ###########################################################################
169 if [ "$SUB_OS_NAME" = "" ]; then
170 SUB_OS_NAME="`(uname -s | sed \"s/\//-/\" | sed \"s/_/-/\" \
171 | sed \"s/-.*//g\") 2>&1`"
174 if [ "$SUB_ARCH_NAME" = "" ]; then
175 if [ "$CC" = "" ]; then
176 A_NAME="`(uname -m) 2>&1`"
178 A_NAME="`$CC -dumpmachine | sed 's:-.*::'`"
183 if [ "$A_NAME" = "i386" -o "$A_NAME" = "i486" -o "$A_NAME" = "i586" -o "$A_NAME" = "i686" -o "$A_NAME" = "x86" ]; then
188 if [ "$A_NAME" = "x86_64" ]; then
193 if [ "$A_NAME" = "powerpc" ]; then
198 if [ "$A_NAME" = "powerpc64" ]; then
203 if [ "$A_NAME" = "arm" ]; then
207 if [ "$SUB_ARCH_NAME" = "" ]; then
208 echo "Error: could not detect what architecture this system is running!"
209 echo "Please supply manually instead with \"--arch=foo\""
213 echo "Using OS: ${SUB_OS_NAME}"
214 echo "Using architecture: ${SUB_ARCH_NAME}"
216 if [ "$SUB_ARCH_NAME" = "x86_64" -a "$CC" = "gcc" ]; then
217 # Only if we are on x86_64 and using gcc
218 # For shared library generation, it needs this
219 SUB_PROG_CFLAGS=-fPIC
222 if [ "$SUB_ARCH_NAME" = "ppc" -o "$SUB_ARCH_NAME" = "powerpc" ]; then
223 # PowerPC uses big endian format
227 ###########################################################################
228 # DEFAULT TARGET/DRIVERS GUESSING #
229 ###########################################################################
230 # If target not specified, try to gess one
231 if [ "$SUB_TARGET" = "" ]; then
232 if [ "$SUB_OS_NAME" = "CYGWIN" ]; then
233 echo "Choosing unix (cygwin) target"
236 if [ "$SUB_OS_NAME" = "Linux" ]; then
237 echo "Choosing unix target"
240 if [ "$SUB_OS_NAME" = "MINGW32" ]; then
241 echo "Choosing windows target"
247 if [ "$SUB_CAN_DRIVER" = "" ]; then
248 if [ "$SUB_TARGET" = "unix" ]; then
249 if [ -e /usr/lib/libpcan.so ]; then
250 echo "Choosing installed Peak driver as CAN driver."
251 SUB_CAN_DRIVER=peak_linux
252 elif [ "$SUB_OS_NAME" = "CYGWIN" -a "PCAN_LIB" != "" ]; then
253 echo "Choosing installed Peak driver as CAN driver."
254 SUB_CAN_DRIVER=peak_win32
256 echo "Choosing virtual CAN driver."
257 SUB_CAN_DRIVER=virtual
262 # If target is unix, default timers also
263 if [ "$SUB_TARGET" = "unix" -a "$SUB_TIMERS_DRIVER" = "" ]; then
264 echo "Choosing unix timers driver."
265 SUB_TIMERS_DRIVER=unix
268 # If target is windows, default timers also
269 if [ "$SUB_TARGET" = "win32" -a "$SUB_TIMERS_DRIVER" = "" ]; then
270 echo "Choosing windows timers driver."
271 SUB_TIMERS_DRIVER=win32
274 # Warn for unstalled peak driver if choosen
275 if [ "$SUB_CAN_DRIVER" = "peak" ]; then
276 if [ ! -e /usr/lib/libpcan.so ]; then
277 echo "Peak driver hasn't been installed !"
282 ###########################################################################
283 # TARGET/DRIVER SPECIFIC CFLAGS and OPTIONS #
284 ###########################################################################
285 if [ "$SUB_TARGET" = "hcs12" ]; then
286 # Only if we want to compile for a µC HCS12
287 # it is a big endian architecture.
289 # search for gcc hcs12 compiler m6811-elf-gcc or m68hc12-gcc ?
290 if [ "$CC" = "" ]; then
291 which m6811-elf-gcc >/dev/null 2>&1
293 which m68hc12-gcc >/dev/null 2>&1
295 echo "Please use --cc flag to specify compiler"
302 SUB_PROG_CFLAGS=-m68hc12
307 if [ "$SUB_TARGET" = "win32" ]; then
309 SUB_PROG_CFLAGS="-mno-cygwin"
312 if [ "$SUB_TARGET" = "unix" ]; then
318 if [ "$SUB_CAN_DRIVER" = "peak_linux" ]; then
319 SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lpcan
322 PW32DIR=drivers/can_peak_win32
323 if [ "$SUB_CAN_DRIVER" = "peak_win32" ]; then
324 if [ "$PCAN_HEADER" = "" -o "PCAN_LIB" = "" ]; then
325 echo "!!! ERROR !!! Please set PCAN_LIB PCAN_HEADER [PCAN_INCLUDE] to appropriate paths ! "
327 SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -liberty\ \'$PCAN_LIB\'
328 echo "Converting PcanLib header files for gcc -> $PW32DIR/cancfg.h"
329 cat $PW32DIR/cancfg.h.head $PCAN_INCLUDE/$PCAN_HEADER > $PW32DIR/cancfg.h
330 echo >> $PW32DIR/cancfg.h
331 # second port handling
332 if [ "$PCAN2_HEADER" != "" ]; then
333 echo "Stripping down second Pcan Light header "
334 echo >> $PW32DIR/cancfg.h
335 echo "// Stripped PcanLight header to prevent typedef conflicts ">> $PW32DIR/cancfg.h
336 echo >> $PW32DIR/cancfg.h
337 grep __stdcall $PCAN_INCLUDE/$PCAN2_HEADER >> $PW32DIR/cancfg.h
338 echo '#define PCAN2_HEADER_' >> $PW32DIR/cancfg.h
339 SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ \'$PCAN2_LIB\'
341 if grep -q CANHwType $PW32DIR/cancfg.h ; then
342 echo "Peak Init HwType, IO_Port and IRQ will be passed in environment :"
343 echo " PCANHwType PCANIO_Port PCANInterupt"
344 echo '#define extra_PCAN_init_params' >> $PW32DIR/cancfg.h
346 if ! grep -q CAN_Init $PW32DIR/cancfg.h ; then
347 echo "Pcan Light header/lib is for second port of device only"
348 echo "CAN_* calls redefined to CAN2_* "
349 echo '#define CAN_Init CAN2_Init' >> $PW32DIR/cancfg.h
350 echo '#define CAN_Read CAN2_Read' >> $PW32DIR/cancfg.h
351 echo '#define CAN_Write CAN2_Write' >> $PW32DIR/cancfg.h
352 echo '#define CAN_Close CAN2_Close' >> $PW32DIR/cancfg.h
354 cat $PW32DIR/cancfg.h.tail >> $PW32DIR/cancfg.h
357 if [ "$SUB_CAN_DRIVER" = "none" ]; then
361 #### TIMERS_DRIVER ####
363 if [ "$SUB_TIMERS_DRIVER" = "unix" ]; then
364 if [ "$SUB_OS_NAME" != "CYGWIN" ]; then
365 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lpthread\ -lrt
369 if [ "$SUB_TIMERS_DRIVER" = "xeno" ]; then
370 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lnative\ -lrtdm\ -L`$XENO_CONFIG --library-dir`
371 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ `$XENO_CONFIG --xeno-cflags`
375 if [ "$SUB_TIMERS_DRIVER" = "none" ]; then
379 ###########################################################################
381 ###########################################################################
382 # If CC is empty, the user wanted automatic detection
383 if [ "$CC" = "" ]; then
384 # Check for second compiler, CC2
386 int main() { return 0; }
388 if test "`($CC2 -c $CFLAGS $test.c) 2>&1`" = ""; then
390 echo "Checking for ${CC2}... Yes."
392 echo "Checking for ${CC2}... No."
394 rm -f $test.c $test.o
396 # Check for first compiler, CC1
398 int main() { return 0; }
400 if test "`($CC1 -c $CFLAGS $test.c) 2>&1`" = ""; then
402 echo "Checking for ${CC1}... Yes."
404 echo "Checking for ${CC1}... No."
406 rm -f $test.c $test.o
409 # Check if we decided on a compiler after all
410 if [ "$CC" = "" ]; then
411 echo "Error: Could not find a C compiler"
412 echo "Please supply the wanted compiler"
418 ###########################################################################
420 ###########################################################################
422 SUB_BINUTILS_PREFIX=`echo "$CC" | sed 's/gcc$//'`
424 # Guess prefix as regard cross compiling target machine
425 if [ "$SUB_PREFIX" = "" ]; then
426 $CC -dumpspecs |grep -A 1 'cross_compile'|grep -q 1
428 SUB_PREFIX=/usr/local
429 echo "Not cross-compiling. Will install in $SUB_PREFIX";
431 SUB_PREFIX=/usr/`$CC -dumpmachine`
432 echo "This is a cross-compiler. Will install in $SUB_PREFIX";
436 echo "Using prefix: ${SUB_PREFIX}"
438 ###########################################################################
439 # CANFESTIVAL DEFINES --> config.h #
440 ###########################################################################
441 # Some CONSTANTS preparation
443 # Create include/config.h with the relevant contents
444 rm -f include/config.h
445 echo "/* !!!!!!!!!! FILE GENERATED by configure. DO NOT EDIT !!!!!!!!!!*/" >> include/config.h
446 echo "" >> include/config.h
447 echo "/*"\ >> include/config.h
448 echo "This file is part of CanFestival, a library implementing CanOpen Stack." >> include/config.h
449 echo "" >> include/config.h
450 echo "Copyright (C): Edouard TISSERANT and Francis DUPIN" >> include/config.h
451 echo "See COPYING file for copyrights details." >> include/config.h
452 echo "" >> include/config.h
453 echo "This library is free software; you can redistribute it and/or" >> include/config.h
454 echo "modify it under the terms of the GNU Lesser General Public" >> include/config.h
455 echo "License as published by the Free Software Foundation; either" >> include/config.h
456 echo "version 2.1 of the License, or (at your option) any later version." >> include/config.h
457 echo "" >> include/config.h
458 echo "This library is distributed in the hope that it will be useful," >> include/config.h
459 echo "but WITHOUT ANY WARRANTY; without even the implied warranty of" >> include/config.h
460 echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU" >> include/config.h
461 echo "Lesser General Public License for more details." >> include/config.h
462 echo "" >> include/config.h
463 echo "You should have received a copy of the GNU Lesser General Public" >> include/config.h
464 echo "License along with this library; if not, write to the Free Software" >> include/config.h
465 echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" >> include/config.h
466 echo "*/" >> include/config.h
467 echo "" >> include/config.h
468 echo "#ifndef _CONFIG_H_" >> include/config.h
469 echo "#define _CONFIG_H_" >> include/config.h
470 echo "" >> include/config.h
473 SDO_MAX_LENGTH_TRANSFERT\
474 SDO_MAX_SIMULTANEOUS_TRANSFERTS\
479 US_TO_TIMEVAL_FACTOR\
484 if [ "${!i}" = "" ]; then
485 echo "/* $i is not defined */" >> include/config.h
487 echo "#define $i ${!i}" >> include/config.h
490 echo "" >> include/config.h
493 SDO_MAX_SIMULTANEOUS_TRANSFERTS\
496 echo "#define REPEAT_"$i"_TIMES(repeat)\\">> include/config.h
499 for (( j=0; j<times; j++ ));do
500 result="$result repeat"
502 echo $result >> include/config.h
505 echo "#endif /* _CONFIG_H_ */" >> include/config.h
507 ###########################################################################
508 # DEBUG DEFINES/CFLAGS #
509 ###########################################################################
511 save_ifs="$IFS"; IFS=','
513 for DEBUG_METHOD in $DEBUG;
516 case $DEBUG_METHOD in
520 PDO)PDO=1;WAR=1;ERR=1;;
522 echo "$DEBUG_METHOD is not a valid debug's method"
523 echo "Possible Debug's methods are : \"ERR\", \"WAR\", \"MSG\", \"PDO\""
530 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_WAR_CONSOLE_ON;
534 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_ERR_CONSOLE_ON;
538 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_MSG_CONSOLE_ON;
542 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_PDO_CONSOLE_ON;
546 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -g
551 if [ "$DISABLE_OPT" = "1" ]; then
554 SUB_OPT_CFLAGS=\$\(OPT_CFLAGS\)
557 if [ "$DISABLE_DLL" = "1" ]; then
558 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DNOT_USE_DYNAMIC_LOADING
559 SUB_ENABLE_DLL_DRIVERS=0
561 SUB_ENABLE_DLL_DRIVERS=1
562 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -ldl
566 if [ "$DISABLE_DLL" = "1" ]; then
567 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ $SUB_CAN_DLL_CFLAGS
570 ###########################################################################
572 ###########################################################################
574 MAKEFILES=Makefile.in\
576 \ drivers/Makefile.in\
577 \ objdictgen/Makefile.in\
578 \ examples/Makefile.in\
579 \ objdictgen/canfestival_config.py.in
581 # Drivers dependent Makefiles
582 if [ "$SUB_TIMERS_DRIVER" != "" ]; then
583 MAKEFILES=$MAKEFILES\
584 \ drivers/timers_$SUB_TIMERS_DRIVER/Makefile.in
587 if [ "$SUB_CAN_DRIVER" != "" ]; then
588 MAKEFILES=$MAKEFILES\
589 \ drivers/can_$SUB_CAN_DRIVER/Makefile.in
592 # Target dependent Makefiles
593 MAKEFILES=$MAKEFILES\ drivers/$SUB_TARGET/Makefile.in
595 if [ "$SUB_TARGET" = "unix" ]; then
596 MAKEFILES=$MAKEFILES\
597 \ examples/TestMasterSlave/Makefile.in
600 if [ "$SUB_TARGET" = "unix" ]; then
601 MAKEFILES=$MAKEFILES\
602 \ examples/DS401_Master/Makefile.in\
603 \ examples/DS401_Slave_Gui/Makefile.in\
604 \ examples/TestMasterMicroMod/Makefile.in
607 if [ "$SUB_TARGET" = "win32" ]; then
608 MAKEFILES=$MAKEFILES\
609 \ examples/TestMasterSlave/Makefile.in\
610 \ examples/TestMasterMicroMod/Makefile.in\
611 \ examples/DS401_Master/Makefile.in\
612 \ examples/DS401_Slave_Gui/Makefile.in
615 if [ "$SUB_TARGET" = "hcs12" ]; then
616 MAKEFILES=$MAKEFILES\
617 \ examples/gene_SYNC_HCS12/Makefile.in
620 for makefile_in in $MAKEFILES; do
621 makefile=`echo $makefile_in | sed 's:.in$::'`
622 echo "Creating $makefile"
627 s:SUB_PROG_CFLAGS:${SUB_PROG_CFLAGS}:
628 s:SUB_EXE_CFLAGS:${SUB_EXE_CFLAGS}:
629 s:SUB_PREFIX:${SUB_PREFIX}:
630 s:SUB_OS_NAME:${SUB_OS_NAME}:
631 s:SUB_ARCH_NAME:${SUB_ARCH_NAME}:
632 s:SUB_OPT_CFLAGS:${SUB_OPT_CFLAGS}:
633 s:SUB_TARGET:${SUB_TARGET}:
634 s:SUB_BINUTILS_PREFIX:${SUB_BINUTILS_PREFIX}:
635 s:SUB_TIMERS_DRIVER:timers_${SUB_TIMERS_DRIVER}:
636 s:SUB_CAN_DRIVER:can_${SUB_CAN_DRIVER}:
637 s:SUB_CAN_DLL_CFLAGS:${SUB_CAN_DLL_CFLAGS}:
638 s:SUB_ENABLE_DLL_DRIVERS:${SUB_ENABLE_DLL_DRIVERS}: