configure
changeset 0 4472ee7c6c3e
child 15 e930a0e817de
equal deleted inserted replaced
-1:000000000000 0:4472ee7c6c3e
       
     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 # Default to little-endian
       
    51 CANOPEN_LITTLE_ENDIAN=1
       
    52 CANOPEN_BIG_ENDIAN=
       
    53 
       
    54 ###########################################################################
       
    55 #                             DEFAULT BUILD OPTIONS                       #
       
    56 ###########################################################################
       
    57 
       
    58 # Leave empty for automatic detection
       
    59 CC=
       
    60 
       
    61 #default target
       
    62 SUB_TARGET=
       
    63 
       
    64 # First compiler option - we will check if it exists
       
    65 CC1=gcc
       
    66 # Second compiler option - we will check if it exists
       
    67 CC2=cc
       
    68 
       
    69 # Install prefix
       
    70 SUB_PREFIX=
       
    71 
       
    72 SUB_TIMERS_ENABLE=YES
       
    73 
       
    74 # Used for C compiler test/detection 
       
    75 CFLAGS=
       
    76 test=conftest
       
    77 rm -f $test $test.c
       
    78 
       
    79 # Jaxe install is now disbaled by default
       
    80 DISABLE_JAXE=1
       
    81 
       
    82 XENO_CONFIG=/usr/xenomai/bin/xeno-config
       
    83 
       
    84 ###########################################################################
       
    85 #                          ARGUMENTS PARSING                              #
       
    86 ###########################################################################
       
    87 while [ $# -ge 1 ]; do
       
    88 	optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
       
    89 	
       
    90 	case $1 in
       
    91 	--cc=*)		CC=$optarg;;
       
    92 	--arch=*)	SUB_ARCH_NAME=$optarg;;
       
    93 	--os=*)		SUB_OS_NAME=$optarg;;
       
    94 	--prefix=*)	SUB_PREFIX=$optarg;;
       
    95 	--target=*)	SUB_TARGET=$optarg;;
       
    96 	--can=*)	SUB_CAN_DRIVER=$optarg;;
       
    97 	--timers=*)	SUB_TIMERS_DRIVER=$optarg;;
       
    98 	--disable-Ox)	DISABLE_OPT=1;
       
    99 			echo "On user request: Won't optimize with \"-Ox\"";;
       
   100 	--enable-jaxe)	DISABLE_JAXE=0;
       
   101 			echo "On user request: Will not install jaxe";;
       
   102 	--debug)	DEBUG=1;
       
   103 			echo "Debug messages enabled !!";;
       
   104 	--debugPDO)	DEBUG=PDO;
       
   105 			echo "Debug messages (PDO) enabled !!";;
       
   106 	--enable-lss)	SUB_LSS_ENABLE=YES;
       
   107 			echo "On user request: Will enable Auto Baudrate detect Feature";;
       
   108 	--enable-led)	SUB_LED_ENABLE=YES;
       
   109 			echo "On user request: Will enable diagnostic LED feature";;
       
   110 	--enable-nvram)	SUB_NVRAM_ENABLE=YES;
       
   111 			echo "On user request: Will enable Non Volatile RAM Feature";;
       
   112 	--desable-timers)	SUB_TIMERS_ENABLE=NO;
       
   113 			echo "On user request: Will enable built-in timer dispatch Feature";;
       
   114 	--MAX_CAN_BUS_ID=*)	MAX_CAN_BUS_ID=$1;;
       
   115 	--SDO_MAX_LENGTH_TRANSFERT=*)	SDO_MAX_LENGTH_TRANSFERT=$1;;
       
   116 	--SDO_MAX_SIMULTANEOUS_TRANSFERTS=*)	SDO_MAX_SIMULTANEOUS_TRANSFERTS=$1;;
       
   117 	--NMT_MAX_NODE_ID=*)	NMT_MAX_NODE_ID=$1;;
       
   118 	--SDO_TIMEOUT_MS=*)	SDO_TIMEOUT_MS=$1;;
       
   119 	--CANOPEN_BIG_ENDIAN=*)	CANOPEN_BIG_ENDIAN=$1;;
       
   120 	--MAX_NB_TIMER=*) MAX_NB_TIMER=$1;;
       
   121 	--help)	echo	"Usage: ./configure [options]"
       
   122     		echo	"Options:"
       
   123     		echo 	" --cc=foo	Use compiler 'foo' instead of defaults ${CC1} or ${CC2}."
       
   124 		echo 	" --arch=foo	Use architecture 'foo' instead of trying to autodetect."
       
   125 		echo 	" --os=foo	Use operative system 'foo' instead of trying to autodetect."
       
   126 		echo 	" --prefix=foo	Use prefix 'foo' instead of default ${SUB_PREFIX}."
       
   127 		echo 	" --target=foo	Use 'foo' as build target."
       
   128 		echo	"		Where 'foo' can be \"generic\" to have independant CAN and TIMERS driver"
       
   129 		echo	"		or"
       
   130 		echo	"		\"hcs12\" for HCS12 micro-controller"
       
   131 		echo	"		\"ecos_lpc2138_sja1000\" for eCOS + Philips ARM LPC21381 + Philips SJA1000" 
       
   132 		echo 	" --can=foo	Use 'foo' as CAN driver (can be either 'peak' or 'virtual')"
       
   133 		echo 	" --timers=foo	Use 'foo' as TIMERS driver (can be either 'unix' or 'xenomai')"
       
   134 		echo	" --disable-Ox	Disable gcc \"-Ox\" optimizations."
       
   135 		echo	" --enable-jaxe	Enable \"jaxe\" installation."
       
   136 		echo	" --debug	Enable debug messages."
       
   137 		echo	" --debugPDO	Enable debug messages, using PDO."
       
   138 		echo	" --enable-lss	Enable Auto Baudrate detect Feature"
       
   139 		echo	" --enable-led	Enable DS-305 LED diagnistic Feature"
       
   140 		echo	" --enable-nvram Enable Non-volatile RAM managment Feature"
       
   141 		echo	" --enable-timers Enable built-in schuduler Feature"
       
   142 		echo	" --enable-	Enable  Feature"
       
   143 		echo
       
   144 		echo	"Stack compilation constants"
       
   145 		echo	" --MAX_CAN_BUS_ID [=1] Number of can bus to use"
       
   146 		echo	" --SDO_MAX_LENGTH_TRANSFERT [=32] max bytes to transmit by SDO"
       
   147 		echo	" --SDO_MAX_SIMULTANEOUS_TRANSFERTS [=4] Number of SDO that the node can manage concurrently"
       
   148 		echo	" --NMT_MAX_NODE_ID [=128] can be reduced to gain memory on small network"
       
   149 		echo	" --SDO_TIMEOUT_MS [=3000] Timeout in milliseconds for SDO (None to disable the feature)"
       
   150 		exit 0;;
       
   151 	*)		echo "Unknown argument ${1}"; exit -1;;
       
   152 	esac
       
   153 
       
   154 	shift
       
   155 done
       
   156 
       
   157 if [ "$DISABLE_JAXE" = "1" ]; then
       
   158 	SUB_OPT_JAXE=
       
   159 else
       
   160 	which java >/dev/null 2>&1
       
   161 	if (( $? )); then 
       
   162 		SUB_OPT_JAXE=
       
   163 		echo "Could not find java VM ! Jaxe XML editor disabled !"
       
   164 	else
       
   165 		SUB_OPT_JAXE=jaxe
       
   166 	fi
       
   167 fi
       
   168 ###########################################################################
       
   169 #                      DEFAULT TARGET/DRIVERS GUESSING                    #
       
   170 ###########################################################################
       
   171 # If target not specified, try to gess one
       
   172 if [ "$SUB_TARGET" = "" ]; then
       
   173 	SUB_TARGET=generic
       
   174 fi
       
   175 
       
   176 # If target generic, try to gess can
       
   177 if [ "$SUB_TARGET" = "generic" -a "$SUB_CAN_DRIVER" = "" ]; then
       
   178 	if [ -e /usr/lib/libpcan.so ]; then 
       
   179 		echo "Choosing installed Peak driver as CAN driver."
       
   180 		SUB_CAN_DRIVER=peak
       
   181 	else
       
   182 		echo "Choosing virtual CAN driver."
       
   183 		SUB_CAN_DRIVER=virtual
       
   184 		SUB_LED_ENABLE=YES
       
   185 	fi
       
   186 fi
       
   187 
       
   188 # If target generic, try to gess timers
       
   189 if [ "$SUB_TARGET" = "generic" -a "$SUB_TIMERS_DRIVER" = "" ]; then
       
   190 	echo "Choosing unix timers driver."
       
   191 	SUB_TIMERS_DRIVER=unix
       
   192 fi
       
   193 
       
   194 if [ "$SUB_CAN_DRIVER" = "peak" ]; then
       
   195 	if [ ! -e /usr/lib/libpcan.so ]; then 
       
   196 		echo "Peak driver hasn't been installed !"
       
   197 		exit -1
       
   198 	fi
       
   199 fi
       
   200 
       
   201 ###########################################################################
       
   202 #                              GUESS OS/ARCH                              #
       
   203 ###########################################################################
       
   204 
       
   205 if [ "$SUB_OS_NAME" = "" ]; then
       
   206 	SUB_OS_NAME="`(uname -s | sed \"s/\//-/\" | sed \"s/_/-/\" \
       
   207 			| sed \"s/-.*//g\") 2>&1`"
       
   208 fi
       
   209 if [ "$SUB_OS_NAME" = "HP" -o "$SUB_OS_NAME" = "HP-UX" ]; then
       
   210 	SUB_OS_NAME=HPUX
       
   211 fi
       
   212 
       
   213 if [ "$SUB_ARCH_NAME" = "" ]; then
       
   214 	if [ "$CC" = "" ]; then
       
   215 		A_NAME="`(uname -m) 2>&1`"
       
   216 	else
       
   217 		A_NAME="`$CC -dumpmachine | sed 's:-.*::'`"
       
   218 	fi
       
   219 fi
       
   220 
       
   221 # x86
       
   222 if [ "$A_NAME" = "i386" ]; then
       
   223 	SUB_ARCH_NAME=x86
       
   224 fi
       
   225 if [ "$A_NAME" = "i486" ]; then
       
   226 	SUB_ARCH_NAME=x86
       
   227 fi
       
   228 if [ "$A_NAME" = "i586" ]; then
       
   229 	SUB_ARCH_NAME=x86
       
   230 fi
       
   231 if [ "$A_NAME" = "i686" ]; then
       
   232 	SUB_ARCH_NAME=x86
       
   233 fi
       
   234 if [ "$A_NAME" = "x86" ]; then
       
   235 	SUB_ARCH_NAME=x86
       
   236 fi
       
   237 
       
   238 # x86_64
       
   239 if [ "$A_NAME" = "x86_64" ]; then
       
   240 	SUB_ARCH_NAME=x86_64
       
   241 fi
       
   242 
       
   243 # ia64
       
   244 if [ "$A_NAME" = "ia64" ]; then
       
   245 	SUB_ARCH_NAME=ia64
       
   246 fi
       
   247 
       
   248 # alpha
       
   249 if [ "$A_NAME" = "alpha" ]; then
       
   250 	SUB_ARCH_NAME=alpha
       
   251 fi
       
   252 
       
   253 # parisc
       
   254 if [ "$A_NAME" = "parisc" ]; then
       
   255 	SUB_ARCH_NAME=parisc
       
   256 fi
       
   257 if [ "$SUB_OS_NAME" = "HPUX" -a "$A_NAME" != "ia64" ]; then
       
   258 	# If we're on HP-UX and the architecture is *not* ia64,
       
   259 	# it's most likely parisc
       
   260 	SUB_ARCH_NAME=parisc
       
   261 fi
       
   262 
       
   263 # sparc
       
   264 if [ "$A_NAME" = "sparc" ]; then
       
   265 	SUB_ARCH_NAME=sparc
       
   266 fi
       
   267 if [ "$A_NAME" = "sun4u" ]; then
       
   268 	SUB_ARCH_NAME=sparc
       
   269 fi
       
   270 
       
   271 # sparc64
       
   272 if [ "$A_NAME" = "sparc64" ]; then
       
   273 	SUB_ARCH_NAME=sparc64
       
   274 fi
       
   275 
       
   276 
       
   277 #
       
   278 # The following has not been verified
       
   279 #
       
   280 
       
   281 # ppc
       
   282 if [ "$A_NAME" = "powerpc" ]; then
       
   283 	SUB_ARCH_NAME=ppc
       
   284 fi
       
   285 
       
   286 # ppc64
       
   287 if [ "$A_NAME" = "powerpc64" ]; then
       
   288 	SUB_ARCH_NAME=ppc64
       
   289 fi
       
   290 
       
   291 # arm
       
   292 if [ "$A_NAME" = "arm" ]; then
       
   293 	SUB_ARCH_NAME=arm
       
   294 fi
       
   295 
       
   296 # mips3
       
   297 if [ "$A_NAME" = "ip32" ]; then		# IRIX
       
   298 	SUB_ARCH_NAME=mips3
       
   299 fi
       
   300 if [ "$A_NAME" = "ip35" ]; then		# IRIX
       
   301 	SUB_ARCH_NAME=mips3
       
   302 fi
       
   303 
       
   304 # mips32
       
   305 if [ "$A_NAME" = "mips32" ]; then
       
   306 	SUB_ARCH_NAME=mips32
       
   307 fi
       
   308 if [ "$A_NAME" = "mips" ]; then
       
   309 	SUB_ARCH_NAME=mips32
       
   310 fi
       
   311 if [ "$A_NAME" = "MIPS" ]; then
       
   312 	SUB_ARCH_NAME=mips32
       
   313 fi
       
   314 if [ "$A_NAME" = "RISC" ]; then		# MIPS Ultrix
       
   315 	SUB_ARCH_NAME=mips32
       
   316 fi
       
   317 
       
   318 # mips64
       
   319 if [ "$A_NAME" = "mips64" ]; then
       
   320 	SUB_ARCH_NAME=mips64
       
   321 fi
       
   322 if [ "$A_NAME" = "MIPS64" ]; then
       
   323 	SUB_ARCH_NAME=mips64
       
   324 fi
       
   325 if [ "$A_NAME" = "IP64" ]; then		# IRIX
       
   326 	SUB_ARCH_NAME=mips64
       
   327 fi
       
   328 
       
   329 # power
       
   330 if [ "$A_NAME" = "power" ]; then	# Manual
       
   331 	SUB_ARCH_NAME=power
       
   332 fi
       
   333 
       
   334 echo "Using OS: ${SUB_OS_NAME}"
       
   335 echo "Using architecture: ${SUB_ARCH_NAME}"
       
   336 
       
   337 if [ "$SUB_ARCH_NAME" = "" ]; then
       
   338 	echo "Error: could not detect what architecture this system is running!"
       
   339 	echo "Please supply manually instead with \"--arch=foo\""
       
   340 	exit -1
       
   341 fi
       
   342 
       
   343 if [ "$SUB_OS_NAME" = "HPUX" -a "$CC" = "gcc" ]; then
       
   344 	# Only if we are on HP-UX, ia64 and using gcc
       
   345 	SUB_PROG_CFLAGS=-mlp64
       
   346 fi
       
   347 
       
   348 if [ "$SUB_OS_NAME" = "SunOS" -a "$SUB_ARCH_NAME" = "sparc" -a "$CC" = "gcc" ]; then
       
   349 	# Only if we are on SunOS, sparc and using gcc
       
   350 	# Tells the assembler that we are dealing with a v8plusa arch sparc
       
   351 	# and -mimpure-text is needed for shared library linking
       
   352 	SUB_PROG_CFLAGS="-Wa,-xarch=v8plusa -mimpure-text"
       
   353 fi
       
   354 
       
   355 if [ "$SUB_OS_NAME" = "AIX" -a "$SUB_ARCH_NAME" = "power" -a "$CC" = "gcc" ]; then
       
   356 	# Only if we are on AIX, power and using gcc
       
   357 	# The assembler may default to generating Power and PowerPC compatible
       
   358 	# code. We need to override that.
       
   359 	SUB_PROG_CFLAGS=-Wa,-mpwr
       
   360 fi
       
   361 
       
   362 if [ "$SUB_OS_NAME" = "AIX" -a "$SUB_ARCH_NAME" = "ppc" -a "$CC" = "gcc" ]; then
       
   363 	# Only if we are on AIX, ppc and using gcc
       
   364 	# The assembler may default to generating Power and PowerPC compatible
       
   365 	# code. We need to override that.
       
   366 	SUB_PROG_CFLAGS=-Wa,-mppc
       
   367 fi
       
   368 
       
   369 if [ "$SUB_ARCH_NAME" = "x86_64" -a "$CC" = "gcc" ]; then
       
   370 	# Only if we are on x86_64 and using gcc
       
   371 	# For shared library generation, it needs this
       
   372 	SUB_PROG_CFLAGS=-fPIC
       
   373 fi
       
   374 
       
   375 ###########################################################################
       
   376 #              TARGET/DRIVER SPECIFIC CFLAGS and OPTIONS                  #
       
   377 ###########################################################################
       
   378 if [ "$SUB_TARGET" = "hcs12" ]; then
       
   379 	# Only if we want to compile for a µC HCS12
       
   380 	# search for gcc hcs12 compiler m6811-elf-gcc or m68hc12-gcc ?
       
   381 	if [ "$CC" = "" ]; then
       
   382 		which m6811-elf-gcc >/dev/null 2>&1
       
   383 		if (( $? )); then 
       
   384 			which m68hc12-gcc >/dev/null 2>&1
       
   385 			if (( $? )); then 
       
   386 				echo "Please use --cc flag to specify compiler"
       
   387 				exit 0
       
   388 			else
       
   389 				CC=m68hc12-gcc 
       
   390 			fi
       
   391 		else
       
   392 			CC=m6811-elf-gcc
       
   393 			SUB_PROG_CFLAGS=-m68hc12
       
   394 		fi
       
   395 	fi
       
   396 	# hcs12 driver implement its own timers
       
   397 	SUB_TIMERS_ENABLE=YES
       
   398 fi	
       
   399 
       
   400 if [ "$SUB_TARGET" = "ecos_lpc2138_sja1000" ]; then
       
   401 	# search for gcc arm compiler arm-elf-gcc or arm-elf-gcc ?
       
   402 	if [ "$CC" = "" ]; then
       
   403 		which arm-elf-gcc >/dev/null 2>&1
       
   404 		if (( $? )); then 
       
   405 			echo "error : Could not find arm-elf-gcc"
       
   406 		else
       
   407 			CC=arm-elf-gcc
       
   408 			SUB_PROG_CFLAGS="-mcpu=arm7tdmi -Wall -Wpointer-arith -Wstrict-prototypes -Winline -Wundef -Os \
       
   409                         -ffunction-sections -fdata-sections -fno-exceptions -finline-functions"
       
   410 		fi
       
   411 	fi
       
   412 	# ecos sja1000 driver implements calls needed by LSS.
       
   413 	SUB_LSS_ENABLE=YES
       
   414 	SUB_LED_ENABLE=YES
       
   415 	SUB_NVRAM_ENABLE=YES
       
   416 	# ecos driver implement its own timers
       
   417 	SUB_TIMERS_ENABLE=NO
       
   418 #	SUB_TIMERS_DRIVER=ecos
       
   419 #	SUB_CAN_DRIVER=ecos_lpc2138_sja1000
       
   420 
       
   421 fi
       
   422 
       
   423 
       
   424 #### CAN_DRIVER ####
       
   425 
       
   426 if [ "$SUB_CAN_DRIVER" = "peak" ]; then
       
   427 	SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lpcan
       
   428 fi
       
   429 
       
   430 if [ "$SUB_CAN_DRIVER" = "ecos_lpc2138_sja1000" ]; then
       
   431 	SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ 
       
   432 fi
       
   433 
       
   434 
       
   435 #### TIMERS_DRIVER ####
       
   436 
       
   437 if [ "$SUB_TIMERS_DRIVER" = "ecos" ]; then
       
   438 	SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -llpthread
       
   439 fi
       
   440 
       
   441 if [ "$SUB_TIMERS_DRIVER" = "unix" ]; then
       
   442 	SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lpthread
       
   443 fi
       
   444 
       
   445 if [ "$SUB_TIMERS_DRIVER" = "xeno" ]; then
       
   446 	SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lnative\
       
   447 \	-L`$XENO_CONFIG --library-dir`
       
   448 	SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ `$XENO_CONFIG --xeno-cflags`
       
   449 fi
       
   450 
       
   451 ###########################################################################
       
   452 #                              GUESS COMPILER                             #
       
   453 ###########################################################################
       
   454 # If CC is empty, the user wanted automatic detection
       
   455 if [ "$CC" = "" ]; then
       
   456 	# Check for second compiler, CC2
       
   457 	cat > $test.c <<EOF
       
   458 	int main() { return 0; }
       
   459 EOF
       
   460 	if test "`($CC2 -c $CFLAGS $test.c) 2>&1`" = ""; then
       
   461 		DETECTCC=$CC2
       
   462 		echo "Checking for ${CC2}... Yes."
       
   463 	else
       
   464 		echo "Checking for ${CC2}... No."
       
   465 	fi
       
   466 	rm -f $test.c $test.o
       
   467 	
       
   468 	# Check for first compiler, CC1
       
   469 	cat > $test.c <<EOF
       
   470 	int main() { return 0; }
       
   471 EOF
       
   472 	if test "`($CC1 -c $CFLAGS $test.c) 2>&1`" = ""; then
       
   473 		DETECTCC=$CC1
       
   474 		echo "Checking for ${CC1}... Yes."
       
   475 	else
       
   476 		echo "Checking for ${CC1}... No."
       
   477 	fi
       
   478 	rm -f $test.c $test.o
       
   479 	CC=$DETECTCC
       
   480 fi
       
   481 # Check if we decided on a compiler after all
       
   482 if [ "$CC" = "" ]; then
       
   483 	echo "Error: Could not find a C compiler"
       
   484 	echo "Please supply the wanted compiler"
       
   485 	exit -1
       
   486 fi
       
   487 
       
   488 echo "Using ${CC}"
       
   489 
       
   490 ###########################################################################
       
   491 #                              GUESS PREFIX's                             #
       
   492 ###########################################################################
       
   493 
       
   494 SUB_BINUTILS_PREFIX=`echo "$CC" | sed 's/gcc$//'`
       
   495 
       
   496 # Guess prefix as regard cross compiling target machine
       
   497 if [ "$SUB_PREFIX" = "" ]; then
       
   498 	$CC -dumpspecs |grep -A 1 'cross_compile'|grep -q 1
       
   499 	if (( $? )); then 
       
   500 		SUB_PREFIX=/usr/local
       
   501 		echo "Not cross-compiling. Will install in $SUB_PREFIX";
       
   502 	else
       
   503 		SUB_PREFIX=/usr/`$CC -dumpmachine`
       
   504 		echo "This is a cross-compiler. Will install in $SUB_PREFIX";			
       
   505 	fi
       
   506 fi
       
   507 
       
   508 echo "Using prefix: ${SUB_PREFIX}"
       
   509 
       
   510 ###########################################################################
       
   511 #                   CANFESTIVAL DEFINES --> config.h                      #
       
   512 ###########################################################################
       
   513 # Some CONSTANTS preparation
       
   514 if [ "$CANOPEN_BIG_ENDIAN" = "" ]; then
       
   515 	CANOPEN_LITTLE_ENDIAN=1
       
   516 else
       
   517 	CANOPEN_LITTLE_ENDIAN=
       
   518 fi
       
   519 
       
   520 # Create include/config.h with the relevant contents
       
   521 rm -f include/config.h
       
   522 echo "/*"\ >  include/config.h
       
   523 echo "This file is part of CanFestival, a library implementing CanOpen Stack." >> include/config.h
       
   524 echo "" >> include/config.h
       
   525 echo "Copyright (C): Edouard TISSERANT and Francis DUPIN" >> include/config.h
       
   526 echo "See COPYING file for copyrights details." >> include/config.h
       
   527 echo "" >> include/config.h
       
   528 echo "This library is free software; you can redistribute it and/or" >> include/config.h
       
   529 echo "modify it under the terms of the GNU Lesser General Public" >> include/config.h
       
   530 echo "License as published by the Free Software Foundation; either" >> include/config.h
       
   531 echo "version 2.1 of the License, or (at your option) any later version." >> include/config.h
       
   532 echo "" >> include/config.h
       
   533 echo "This library is distributed in the hope that it will be useful," >> include/config.h
       
   534 echo "but WITHOUT ANY WARRANTY; without even the implied warranty of" >> include/config.h
       
   535 echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU" >> include/config.h
       
   536 echo "Lesser General Public License for more details." >> include/config.h
       
   537 echo "" >> include/config.h
       
   538 echo "You should have received a copy of the GNU Lesser General Public" >> include/config.h
       
   539 echo "License along with this library; if not, write to the Free Software" >> include/config.h
       
   540 echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA" >> include/config.h
       
   541 echo "*/" >> include/config.h
       
   542 echo "" >> include/config.h
       
   543 echo "#ifndef _CONFIG_H_" >> include/config.h
       
   544 echo "#define _CONFIG_H_" >> include/config.h
       
   545 echo "" >> include/config.h
       
   546 for i in \
       
   547  MAX_CAN_BUS_ID\
       
   548  SDO_MAX_LENGTH_TRANSFERT\
       
   549  SDO_MAX_SIMULTANEOUS_TRANSFERTS\
       
   550  NMT_MAX_NODE_ID\
       
   551  SDO_TIMEOUT_MS\
       
   552  MAX_NB_TIMER\
       
   553  CANOPEN_BIG_ENDIAN\
       
   554  CANOPEN_LITTLE_ENDIAN ; do
       
   555 if [ "${!i}" = "" ]; then
       
   556 echo "// $i is not defined" >> include/config.h
       
   557 else
       
   558 echo "#define $i ${!i}" >> include/config.h
       
   559 fi
       
   560 done	
       
   561 echo "" >> include/config.h
       
   562 echo "#endif /* _CONFIG_H_ */" >> include/config.h
       
   563 
       
   564 ###########################################################################
       
   565 #                           DEBUG DEFINES/CFLAGS                          #
       
   566 ###########################################################################
       
   567 if [ "$DEBUG" != "" ]; then
       
   568 	SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_CAN\ -DDEBUG_WAR_CONSOLE_ON\ -DDEBUG_ERR_CONSOLE_ON\ -g
       
   569 fi
       
   570 
       
   571 if [ "$DEBUG" = "PDO" ]; then
       
   572 	SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DPDO_ERROR
       
   573 fi
       
   574 
       
   575 if [ "$DISABLE_OPT" = "1" ]; then
       
   576 	SUB_OPT_CFLAGS=
       
   577 else
       
   578 	SUB_OPT_CFLAGS=\$\(OPT_CFLAGS\)
       
   579 fi
       
   580 
       
   581 ###########################################################################
       
   582 #                              CREATE MAKEFILES                           #
       
   583 ###########################################################################
       
   584 MAKEFILES=Makefile.in\
       
   585 \ src/Makefile.in\
       
   586 \ drivers/Makefile.in\
       
   587 \ objdictgen/Makefile.in\
       
   588 \ examples/Makefile.in
       
   589 
       
   590 if [ "$SUB_TARGET" = "hcs12" ]; then
       
   591 	MAKEFILES=$MAKEFILES\
       
   592 \	drivers/hcs12/Makefile.in\
       
   593 \	examples/AppliMaster_HCS12/Makefile.in\
       
   594 \	examples/AppliSlave_HCS12/Makefile.in\
       
   595 \	examples/gene_SYNC_HCS12/Makefile.in
       
   596 fi
       
   597 
       
   598 if [ "$SUB_TIMERS_DRIVER" != "" ]; then
       
   599 	MAKEFILES=$MAKEFILES\
       
   600 \	drivers/timers_$SUB_TIMERS_DRIVER/Makefile.in
       
   601 fi
       
   602 
       
   603 if [ "$SUB_CAN_DRIVER" != "" ]; then
       
   604 	MAKEFILES=$MAKEFILES\
       
   605 \	drivers/can_$SUB_CAN_DRIVER/Makefile.in
       
   606 fi
       
   607 
       
   608 if [ "$SUB_TARGET" = "generic" ]; then
       
   609 	MAKEFILES=$MAKEFILES\
       
   610 \	drivers/generic/Makefile.in\
       
   611 \	examples/AppliMaster_Linux/Makefile.in\
       
   612 \	examples/AppliSlave_Linux/Makefile.in\
       
   613 \	examples/TestMasterSlave/Makefile.in
       
   614 fi
       
   615 
       
   616 if [ "$SUB_TARGET" = "ecos_lpc2138_sja1000" ]; then
       
   617 	MAKEFILES=$MAKEFILES\
       
   618 \	drivers/ecos_lpc2138_sja1000/Makefile.in\
       
   619 \	examples/ecos_lpc2138_sja1000/src/Makefile.in
       
   620 fi
       
   621 
       
   622 for makefile_in in $MAKEFILES; do
       
   623 	makefile=`echo $makefile_in | sed 's:.in$::'`
       
   624 	echo "Creating $makefile"
       
   625 	sed < $makefile_in "
       
   626 	s:SUB_CC:${CC}:
       
   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_OPT_JAXE:${SUB_OPT_JAXE}:
       
   636 	s:SUB_LSS_ENABLE:${SUB_LSS_ENABLE}:
       
   637 	s:SUB_LED_ENABLE:${SUB_LED_ENABLE}:
       
   638 	s:SUB_NVRAM_ENABLE:${SUB_NVRAM_ENABLE}:
       
   639 	s:SUB_TIMERS_ENABLE:${SUB_TIMERS_ENABLE}:
       
   640 	s:SUB_TIMERS_DRIVER:timers_${SUB_TIMERS_DRIVER}:
       
   641 	s:SUB_CAN_DRIVER:can_${SUB_CAN_DRIVER}:
       
   642 	" > $makefile
       
   643 done
       
   644 
       
   645 echo "All done."