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 --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;;
122 echo "Usage: ./configure [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"
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"
162 *) echo "Unknown argument ${1}"; exit -1;;
168 ###########################################################################
170 ###########################################################################
172 if [ "$SUB_OS_NAME" = "" ]; then
173 SUB_OS_NAME="`(uname -s | sed \"s/\//-/\" | sed \"s/_/-/\" \
174 | sed \"s/-.*//g\") 2>&1`"
177 if [ "$SUB_ARCH_NAME" = "" ]; then
178 if [ "$CC" = "" ]; then
179 A_NAME="`(uname -m) 2>&1`"
181 A_NAME="`$CC -dumpmachine | sed 's:-.*::'`"
186 if [ "$A_NAME" = "i386" -o "$A_NAME" = "i486" -o "$A_NAME" = "i586" -o "$A_NAME" = "i686" -o "$A_NAME" = "x86" ]; then
191 if [ "$A_NAME" = "x86_64" ]; then
196 if [ "$A_NAME" = "powerpc" ]; then
201 if [ "$A_NAME" = "powerpc64" ]; then
206 if [ "$A_NAME" = "arm" ]; then
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\""
216 echo "Using OS: ${SUB_OS_NAME}"
217 echo "Using architecture: ${SUB_ARCH_NAME}"
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
225 if [ "$SUB_ARCH_NAME" = "ppc" -o "$SUB_ARCH_NAME" = "powerpc" ]; then
226 # PowerPC uses big endian format
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"
239 if [ "$SUB_OS_NAME" = "Linux" ]; then
240 echo "Choosing unix target"
243 if [ "$SUB_OS_NAME" = "MINGW32" ]; then
244 echo "Choosing windows target"
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
259 echo "Choosing virtual CAN driver."
260 SUB_CAN_DRIVER=virtual
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
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
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 !"
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.
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
296 which m68hc12-gcc >/dev/null 2>&1
298 echo "Please use --cc flag to specify compiler"
305 SUB_PROG_CFLAGS=-m68hc12
310 if [ "$SUB_TARGET" = "win32" ]; then
312 SUB_PROG_CFLAGS="-mno-cygwin"
315 if [ "$SUB_TARGET" = "unix" ]; then
321 if [ "$SUB_CAN_DRIVER" = "peak_linux" ]; then
322 SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lpcan
325 PW32DIR=drivers/can_peak_win32
326 if [ "$SUB_CAN_DRIVER" = "peak_win32" ]; then
327 if [ "$PCAN_HEADER" = "" -o "PCAN_LIB" = "" ]; then
328 echo "!!! ERROR !!! Please set PCAN_LIB PCAN_HEADER [PCAN_INCLUDE] to appropriate paths ! "
330 SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -liberty\ \'$PCAN_LIB\'
331 echo "Converting PcanLib header files for gcc -> $PW32DIR/cancfg.h"
332 cat $PW32DIR/cancfg.h.head $PCAN_INCLUDE/$PCAN_HEADER > $PW32DIR/cancfg.h
333 echo >> $PW32DIR/cancfg.h
334 # second port handling
335 if [ "$PCAN2_HEADER" != "" ]; then
336 echo "Stripping down second Pcan Light header "
337 echo >> $PW32DIR/cancfg.h
338 echo "// Stripped PcanLight header to prevent typedef conflicts ">> $PW32DIR/cancfg.h
339 echo >> $PW32DIR/cancfg.h
340 grep __stdcall $PCAN_INCLUDE/$PCAN2_HEADER >> $PW32DIR/cancfg.h
341 echo '#define PCAN2_HEADER_' >> $PW32DIR/cancfg.h
342 SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ \'$PCAN2_LIB\'
344 if grep -q CANHwType $PW32DIR/cancfg.h ; then
345 echo "Peak Init HwType, IO_Port and IRQ will be passed in environment :"
346 echo " PCANHwType PCANIO_Port PCANInterupt"
347 echo '#define extra_PCAN_init_params' >> $PW32DIR/cancfg.h
349 if ! grep -q CAN_Init $PW32DIR/cancfg.h ; then
350 echo "Pcan Light header/lib is for second port of device only"
351 echo "CAN_* calls redefined to CAN2_* "
352 echo '#define CAN_Init CAN2_Init' >> $PW32DIR/cancfg.h
353 echo '#define CAN_Read CAN2_Read' >> $PW32DIR/cancfg.h
354 echo '#define CAN_Write CAN2_Write' >> $PW32DIR/cancfg.h
355 echo '#define CAN_Close CAN2_Close' >> $PW32DIR/cancfg.h
357 cat $PW32DIR/cancfg.h.tail >> $PW32DIR/cancfg.h
360 if [ "$SUB_CAN_DRIVER" = "none" ]; then
364 #### TIMERS_DRIVER ####
366 if [ "$SUB_TIMERS_DRIVER" = "unix" ]; then
367 if [ "$SUB_OS_NAME" != "CYGWIN" ]; then
368 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lpthread\ -lrt
372 if [ "$SUB_TIMERS_DRIVER" = "xeno" ]; then
373 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lnative\ -lrtdm\ -L`$XENO_CONFIG --library-dir`
374 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ `$XENO_CONFIG --xeno-cflags`
378 if [ "$SUB_TIMERS_DRIVER" = "none" ]; then
382 ###########################################################################
384 ###########################################################################
385 # If CC is empty, the user wanted automatic detection
386 if [ "$CC" = "" ]; then
387 # Check for second compiler, CC2
389 int main() { return 0; }
391 if test "`($CC2 -c $CFLAGS $test.c) 2>&1`" = ""; then
393 echo "Checking for ${CC2}... Yes."
395 echo "Checking for ${CC2}... No."
397 rm -f $test.c $test.o
399 # Check for first compiler, CC1
401 int main() { return 0; }
403 if test "`($CC1 -c $CFLAGS $test.c) 2>&1`" = ""; then
405 echo "Checking for ${CC1}... Yes."
407 echo "Checking for ${CC1}... No."
409 rm -f $test.c $test.o
412 # Check if we decided on a compiler after all
413 if [ "$CC" = "" ]; then
414 echo "Error: Could not find a C compiler"
415 echo "Please supply the wanted compiler"
421 ###########################################################################
423 ###########################################################################
425 SUB_BINUTILS_PREFIX=`echo "$CC" | sed 's/gcc$//'`
427 # Guess prefix as regard cross compiling target machine
428 if [ "$SUB_PREFIX" = "" ]; then
429 $CC -dumpspecs |grep -A 1 'cross_compile'|grep -q 1
431 SUB_PREFIX=/usr/local
432 echo "Not cross-compiling. Will install in $SUB_PREFIX";
434 SUB_PREFIX=/usr/`$CC -dumpmachine`
435 echo "This is a cross-compiler. Will install in $SUB_PREFIX";
439 echo "Using prefix: ${SUB_PREFIX}"
441 ###########################################################################
442 # CANFESTIVAL DEFINES --> config.h #
443 ###########################################################################
444 # Some CONSTANTS preparation
446 # Create include/config.h with the relevant contents
447 rm -f include/config.h
448 echo "/* !!!!!!!!!! FILE GENERATED by configure. DO NOT EDIT !!!!!!!!!!*/" >> include/config.h
449 echo "" >> include/config.h
450 echo "/*"\ >> include/config.h
451 echo "This file is part of CanFestival, a library implementing CanOpen Stack." >> include/config.h
452 echo "" >> include/config.h
453 echo "Copyright (C): Edouard TISSERANT and Francis DUPIN" >> include/config.h
454 echo "See COPYING file for copyrights details." >> include/config.h
455 echo "" >> include/config.h
456 echo "This library is free software; you can redistribute it and/or" >> include/config.h
457 echo "modify it under the terms of the GNU Lesser General Public" >> include/config.h
458 echo "License as published by the Free Software Foundation; either" >> include/config.h
459 echo "version 2.1 of the License, or (at your option) any later version." >> include/config.h
460 echo "" >> include/config.h
461 echo "This library is distributed in the hope that it will be useful," >> include/config.h
462 echo "but WITHOUT ANY WARRANTY; without even the implied warranty of" >> include/config.h
463 echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU" >> include/config.h
464 echo "Lesser General Public License for more details." >> include/config.h
465 echo "" >> include/config.h
466 echo "You should have received a copy of the GNU Lesser General Public" >> include/config.h
467 echo "License along with this library; if not, write to the Free Software" >> include/config.h
468 echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA" >> include/config.h
469 echo "*/" >> include/config.h
470 echo "" >> include/config.h
471 echo "#ifndef _CONFIG_H_" >> include/config.h
472 echo "#define _CONFIG_H_" >> include/config.h
473 echo "" >> include/config.h
476 SDO_MAX_LENGTH_TRANSFERT\
477 SDO_MAX_SIMULTANEOUS_TRANSFERTS\
482 US_TO_TIMEVAL_FACTOR\
487 if [ "${!i}" = "" ]; then
488 echo "/* $i is not defined */" >> include/config.h
490 echo "#define $i ${!i}" >> include/config.h
493 echo "" >> include/config.h
496 SDO_MAX_SIMULTANEOUS_TRANSFERTS\
499 echo "#define REPEAT_"$i"_TIMES(repeat)\\">> include/config.h
502 for (( j=0; j<times; j++ ));do
503 result="$result repeat"
505 echo $result >> include/config.h
508 echo "#endif /* _CONFIG_H_ */" >> include/config.h
510 ###########################################################################
511 # DEBUG DEFINES/CFLAGS #
512 ###########################################################################
514 save_ifs="$IFS"; IFS=','
516 for DEBUG_METHOD in $DEBUG;
519 case $DEBUG_METHOD in
523 PDO)PDO=1;WAR=1;ERR=1;;
525 echo "$DEBUG_METHOD is not a valid debug's method"
526 echo "Possible Debug's methods are : \"ERR\", \"WAR\", \"MSG\", \"PDO\""
533 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_WAR_CONSOLE_ON;
537 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_ERR_CONSOLE_ON;
541 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_MSG_CONSOLE_ON;
545 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_PDO_CONSOLE_ON;
549 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -g
554 if [ "$DISABLE_OPT" = "1" ]; then
557 SUB_OPT_CFLAGS=\$\(OPT_CFLAGS\)
560 if [ "$DISABLE_DLL" = "1" ]; then
561 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DNOT_USE_DYNAMIC_LOADING
562 SUB_ENABLE_DLL_DRIVERS=0
564 SUB_ENABLE_DLL_DRIVERS=1
565 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -ldl
569 if [ "$DISABLE_DLL" = "1" ]; then
570 SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ $SUB_CAN_DLL_CFLAGS
573 if [ $ENABLE_LSS ]; then
574 SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DCO_ENABLE_LSS;
580 ###########################################################################
582 ###########################################################################
584 MAKEFILES=Makefile.in\
586 \ drivers/Makefile.in\
587 \ objdictgen/Makefile.in\
588 \ examples/Makefile.in\
589 \ objdictgen/canfestival_config.py.in
591 # Drivers dependent Makefiles
592 if [ "$SUB_TIMERS_DRIVER" != "" ]; then
593 MAKEFILES=$MAKEFILES\
594 \ drivers/timers_$SUB_TIMERS_DRIVER/Makefile.in
597 if [ "$SUB_CAN_DRIVER" != "" ]; then
598 MAKEFILES=$MAKEFILES\
599 \ drivers/can_$SUB_CAN_DRIVER/Makefile.in
602 # Target dependent Makefiles
603 MAKEFILES=$MAKEFILES\ drivers/$SUB_TARGET/Makefile.in
605 if [ "$SUB_TARGET" = "unix" ]; then
606 MAKEFILES=$MAKEFILES\
607 \ examples/TestMasterSlave/Makefile.in
610 if [ "$SUB_TARGET" = "unix" ]; then
611 MAKEFILES=$MAKEFILES\
612 \ examples/DS401_Master/Makefile.in\
613 \ examples/DS401_Slave_Gui/Makefile.in\
614 \ examples/TestMasterMicroMod/Makefile.in
617 if [ "$SUB_TARGET" = "win32" ]; then
618 MAKEFILES=$MAKEFILES\
619 \ examples/TestMasterSlave/Makefile.in\
620 \ examples/TestMasterMicroMod/Makefile.in\
621 \ examples/DS401_Master/Makefile.in\
622 \ examples/DS401_Slave_Gui/Makefile.in
625 if [ "$SUB_TARGET" = "hcs12" ]; then
626 MAKEFILES=$MAKEFILES\
627 \ examples/gene_SYNC_HCS12/Makefile.in
630 for makefile_in in $MAKEFILES; do
631 makefile=`echo $makefile_in | sed 's:.in$::'`
632 echo "Creating $makefile"
637 s:SUB_PROG_CFLAGS:${SUB_PROG_CFLAGS}:
638 s:SUB_EXE_CFLAGS:${SUB_EXE_CFLAGS}:
639 s:SUB_PREFIX:${SUB_PREFIX}:
640 s:SUB_OS_NAME:${SUB_OS_NAME}:
641 s:SUB_ARCH_NAME:${SUB_ARCH_NAME}:
642 s:SUB_OPT_CFLAGS:${SUB_OPT_CFLAGS}:
643 s:SUB_TARGET:${SUB_TARGET}:
644 s:SUB_BINUTILS_PREFIX:${SUB_BINUTILS_PREFIX}:
645 s:SUB_TIMERS_DRIVER:timers_${SUB_TIMERS_DRIVER}:
646 s:SUB_CAN_DRIVER:can_${SUB_CAN_DRIVER}:
647 s:SUB_CAN_DLL_CFLAGS:${SUB_CAN_DLL_CFLAGS}:
648 s:SUB_ENABLE_DLL_DRIVERS:${SUB_ENABLE_DLL_DRIVERS}:
649 s:SUB_ENABLE_LSS:${SUB_ENABLE_LSS}: