configure
author greg
Tue, 29 May 2007 12:02:18 +0200
changeset 206 6787754b251b
parent 200 930be51ddc24
child 234 5a17bcb520ef
permissions -rwxr-xr-x
Bugs corrected on objdictedit and networkdict
#!/bin/bash

#
# Copyright (C) 2004 Edouard TISSERRANT, Laurent BESSARD
# Based on Gabriel Gerhardsson's cacheprobe configure script. 
# 
# This file is part of CanFestival, a library implementing CanOpen Stack. 
# 
# This library is free software; you can redistribute it and/or
# modify it under the terms of the GNU Lesser General Public
# License as published by the Free Software Foundation; either
# version 2.1 of the License, or (at your option) any later version.
# 
# This library is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
# Lesser General Public License for more details.
# 
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
# 

###########################################################################
#                       DEFAULT CANFESTIVAL DEFINES                       #
###########################################################################

# Number of can bus to use 
MAX_CAN_BUS_ID=1 

# max bytes to transmit by SDO Put 4 if you only support expedited transfert.
# For a normal transfert, (usually for a string), put the maximum string size to transfer.
SDO_MAX_LENGTH_TRANSFERT=32 

# Number of SDO from differents nodes that the node can manage concurrently.   
# for a slave node, usually put 1.
SDO_MAX_SIMULTANEOUS_TRANSFERTS=4

# Used for NMTable[bus][nodeId]	  
# You can put less of 128 if on the netwo
# are connected only smaller nodeId node.
NMT_MAX_NODE_ID=128  

#Timeout in milliseconds for SDO.
#    Comment the #define if not used (infinite wait for SDO response message)
SDO_TIMEOUT_MS=3000

MAX_NB_TIMER=32

# Generic timers declaration defaults
US_TO_TIMEVAL_FACTOR=
TIMEVAL=
TIMEVAL_MAX=

# Default to little-endian
CANOPEN_BIG_ENDIAN=

###########################################################################
#                             DEFAULT BUILD OPTIONS                       #
###########################################################################

# Leave empty for automatic detection
CC=

#default target
SUB_TARGET=

# First compiler option - we will check if it exists
CC1=gcc
# Second compiler option - we will check if it exists
CC2=cc

# Install prefix
SUB_PREFIX=

# Used for C compiler test/detection 
CFLAGS=
test=conftest
rm -f $test $test.c

if [ "$XENO_CONFIG" == "" ]; then
	XENO_CONFIG=/usr/xenomai/bin/xeno-config
fi

###########################################################################
#                          ARGUMENTS PARSING                              #
###########################################################################
while [ $# -ge 1 ]; do
	optarg=`expr "x$1" : 'x[^=]*=\(.*\)'`
	
	case $1 in
	--cc=*)		CC=$optarg;;
	--arch=*)	SUB_ARCH_NAME=$optarg;;
	--os=*)		SUB_OS_NAME=$optarg;;
	--prefix=*)	SUB_PREFIX=$optarg;;
	--target=*)	SUB_TARGET=$optarg;;
	--can=*)	SUB_CAN_DRIVER=$optarg;;
	--timers=*)	SUB_TIMERS_DRIVER=$optarg;;
	--disable-Ox)	DISABLE_OPT=1;
			echo "On user request: Won't optimize with \"-Ox\"";;
	--disable-dll)	DISABLE_DLL=1;
			echo "On user request: Won't create and link to dll";;
	--debug=*)	DEBUG=$optarg;;
	--MAX_CAN_BUS_ID=*)	MAX_CAN_BUS_ID=$1;;
	--SDO_MAX_LENGTH_TRANSFERT=*)	SDO_MAX_LENGTH_TRANSFERT=$1;;
	--SDO_MAX_SIMULTANEOUS_TRANSFERTS=*)	SDO_MAX_SIMULTANEOUS_TRANSFERTS=$1;;
	--NMT_MAX_NODE_ID=*)	NMT_MAX_NODE_ID=$1;;
	--SDO_TIMEOUT_MS=*)	SDO_TIMEOUT_MS=$1;;
	--CANOPEN_BIG_ENDIAN=*)	CANOPEN_BIG_ENDIAN=$1;;
	--MAX_NB_TIMER=*) MAX_NB_TIMER=$1;;
	--help)	echo	"Usage: ./configure [options]"
    		echo	"Options:"
    		echo 	" --cc=foo      Use compiler 'foo' instead of defaults ${CC1} or ${CC2}."
		echo 	" --arch=foo    Use architecture 'foo' instead of trying to autodetect."
		echo 	" --os=foo      Use operative system 'foo' instead of trying to autodetect."
		echo 	" --prefix=foo  Use prefix 'foo' instead of default ${SUB_PREFIX}."
		echo 	" --target=foo  Use 'foo' as build target."
		echo	"               \"generic\" for have independant CAN and TIMERS driver"
		echo	"               \"unix\" for unix-like systems"
		echo	"               \"win32\" for win32 systems"
		echo	"               \"hcs12\" for HCS12 micro-controller"
		echo	"               \"ecos_lpc2138_sja1000\" for eCOS + Philips ARM LPC21381 + Philips SJA1000" 
		echo 	" --can=foo	Use 'foo' as CAN driver"
		echo	"               \"peak_linux\" use Linux build host installed Peak driver and library"
		echo	"                                please see http://www.peak-system.com/linux/"
		echo	"               \"peak_win32\" use win32 PcanLight Peak driver and library with Cygwin" 
		echo	"                                please see http://www.peak-system.com/themen/download_gb.html"
		echo	"               \"virtual\" use unix pipe based virtual can driver"
		echo	"               \"socket\" use socket-can  "
		echo	"                                please see http://developer.berlios.de/projects/socketcan/"
		echo	"               \"lincan\" for HCS12 micro-controller"
		echo	"                                please see http://www.ocera.org/download/components/WP7/lincan-0.3.3.html"
		echo 	" --timers=foo  Use 'foo' as TIMERS driver (can be either 'unix' or 'xeno')"
		echo 	" --disable-dll Disable run-time dynamic linking of can, led and nvram drivers"
		echo	" --disable-Ox  Disable gcc \"-Ox\" optimizations."
		echo	" --debug=foo   Enable debug messages, ERR -> only errors, WAR)."
		echo	"                 \"PDO\" send errors and warnings through PDO messages"
		echo	"                 \"ERR\" errors only, to stdout"
		echo	"                 \"WAR\" errors and warnings, to stdout"
		echo
		echo	"Stack compilation constants"
		echo	" --MAX_CAN_BUS_ID [=1] Number of can bus to use"
		echo	" --SDO_MAX_LENGTH_TRANSFERT [=32] max bytes to transmit by SDO"
		echo	" --SDO_MAX_SIMULTANEOUS_TRANSFERTS [=4] Number of SDO that the node can manage concurrently"
		echo	" --NMT_MAX_NODE_ID [=128] can be reduced to gain memory on small network"
		echo	" --SDO_TIMEOUT_MS [=3000] Timeout in milliseconds for SDO (None to disable the feature)"
		exit 0;;
	*)		echo "Unknown argument ${1}"; exit -1;;
	esac

	shift
done

###########################################################################
#                              GUESS OS/ARCH                              #
###########################################################################

if [ "$SUB_OS_NAME" = "" ]; then
	SUB_OS_NAME="`(uname -s | sed \"s/\//-/\" | sed \"s/_/-/\" \
			| sed \"s/-.*//g\") 2>&1`"
fi
if [ "$SUB_OS_NAME" = "HP" -o "$SUB_OS_NAME" = "HP-UX" ]; then
	SUB_OS_NAME=HPUX
fi

if [ "$SUB_ARCH_NAME" = "" ]; then
	if [ "$CC" = "" ]; then
		A_NAME="`(uname -m) 2>&1`"
	else
		A_NAME="`$CC -dumpmachine | sed 's:-.*::'`"
	fi
fi

# x86
if [ "$A_NAME" = "i386" ]; then
	SUB_ARCH_NAME=x86
fi
if [ "$A_NAME" = "i486" ]; then
	SUB_ARCH_NAME=x86
fi
if [ "$A_NAME" = "i586" ]; then
	SUB_ARCH_NAME=x86
fi
if [ "$A_NAME" = "i686" ]; then
	SUB_ARCH_NAME=x86
fi
if [ "$A_NAME" = "x86" ]; then
	SUB_ARCH_NAME=x86
fi

# x86_64
if [ "$A_NAME" = "x86_64" ]; then
	SUB_ARCH_NAME=x86_64
fi

# ia64
if [ "$A_NAME" = "ia64" ]; then
	SUB_ARCH_NAME=ia64
fi

# alpha
if [ "$A_NAME" = "alpha" ]; then
	SUB_ARCH_NAME=alpha
fi

# parisc
if [ "$A_NAME" = "parisc" ]; then
	SUB_ARCH_NAME=parisc
fi
if [ "$SUB_OS_NAME" = "HPUX" -a "$A_NAME" != "ia64" ]; then
	# If we're on HP-UX and the architecture is *not* ia64,
	# it's most likely parisc
	SUB_ARCH_NAME=parisc
fi

# sparc
if [ "$A_NAME" = "sparc" ]; then
	SUB_ARCH_NAME=sparc
fi
if [ "$A_NAME" = "sun4u" ]; then
	SUB_ARCH_NAME=sparc
fi

# sparc64
if [ "$A_NAME" = "sparc64" ]; then
	SUB_ARCH_NAME=sparc64
fi

# ppc
if [ "$A_NAME" = "powerpc" ]; then
	SUB_ARCH_NAME=ppc
fi

# ppc64
if [ "$A_NAME" = "powerpc64" ]; then
	SUB_ARCH_NAME=ppc64
fi

# arm
if [ "$A_NAME" = "arm" ]; then
	SUB_ARCH_NAME=arm
fi

# mips3
if [ "$A_NAME" = "ip32" ]; then		# IRIX
	SUB_ARCH_NAME=mips3
fi
if [ "$A_NAME" = "ip35" ]; then		# IRIX
	SUB_ARCH_NAME=mips3
fi

# mips32
if [ "$A_NAME" = "mips32" ]; then
	SUB_ARCH_NAME=mips32
fi
if [ "$A_NAME" = "mips" ]; then
	SUB_ARCH_NAME=mips32
fi
if [ "$A_NAME" = "MIPS" ]; then
	SUB_ARCH_NAME=mips32
fi
if [ "$A_NAME" = "RISC" ]; then		# MIPS Ultrix
	SUB_ARCH_NAME=mips32
fi

# mips64
if [ "$A_NAME" = "mips64" ]; then
	SUB_ARCH_NAME=mips64
fi
if [ "$A_NAME" = "MIPS64" ]; then
	SUB_ARCH_NAME=mips64
fi
if [ "$A_NAME" = "IP64" ]; then		# IRIX
	SUB_ARCH_NAME=mips64
fi

# power
if [ "$A_NAME" = "power" ]; then	# Manual
	SUB_ARCH_NAME=power
fi

echo "Using OS: ${SUB_OS_NAME}"
echo "Using architecture: ${SUB_ARCH_NAME}"

if [ "$SUB_ARCH_NAME" = "" ]; then
	echo "Error: could not detect what architecture this system is running!"
	echo "Please supply manually instead with \"--arch=foo\""
	exit -1
fi

if [ "$SUB_OS_NAME" = "HPUX" -a "$CC" = "gcc" ]; then
	# Only if we are on HP-UX, ia64 and using gcc
	SUB_PROG_CFLAGS=-mlp64
fi

if [ "$SUB_OS_NAME" = "SunOS" -a "$SUB_ARCH_NAME" = "sparc" -a "$CC" = "gcc" ]; then
	# Only if we are on SunOS, sparc and using gcc
	# Tells the assembler that we are dealing with a v8plusa arch sparc
	# and -mimpure-text is needed for shared library linking
	SUB_PROG_CFLAGS="-Wa,-xarch=v8plusa -mimpure-text"
fi

if [ "$SUB_OS_NAME" = "AIX" -a "$SUB_ARCH_NAME" = "power" -a "$CC" = "gcc" ]; then
	# Only if we are on AIX, power and using gcc
	# The assembler may default to generating Power and PowerPC compatible
	# code. We need to override that.
	SUB_PROG_CFLAGS=-Wa,-mpwr
fi

if [ "$SUB_OS_NAME" = "AIX" -a "$SUB_ARCH_NAME" = "ppc" -a "$CC" = "gcc" ]; then
	# Only if we are on AIX, ppc and using gcc
	# The assembler may default to generating Power and PowerPC compatible
	# code. We need to override that.
	SUB_PROG_CFLAGS=-Wa,-mppc
fi

if [ "$SUB_ARCH_NAME" = "x86_64" -a "$CC" = "gcc" ]; then
	# Only if we are on x86_64 and using gcc
	# For shared library generation, it needs this
	SUB_PROG_CFLAGS=-fPIC
fi

if [ "$SUB_ARCH_NAME" = "ppc" -o "$SUB_ARCH_NAME" = "powerpc" ]; then
	# PowerPC uses big endian format
	CANOPEN_BIG_ENDIAN=1
fi

###########################################################################
#                      DEFAULT TARGET/DRIVERS GUESSING                    #
###########################################################################
# If target not specified, try to gess one
if [ "$SUB_TARGET" = "" ]; then
	if [ "$SUB_OS_NAME" = "CYGWIN" ]; then
		echo "Choosing unix (cygwin) target"
		SUB_TARGET=unix
	else
		echo "Choosing unix target"
		SUB_TARGET=unix
	fi
fi

# Try to gess can
if [ "$SUB_CAN_DRIVER" = "" ]; then
	if [ "$SUB_TARGET" = "unix" ]; then
		if [ -e /usr/lib/libpcan.so ]; then 
			echo "Choosing installed Peak driver as CAN driver."
			SUB_CAN_DRIVER=peak_linux
		elif [ "$SUB_OS_NAME" = "CYGWIN" -a "PCAN_LIB" != "" ]; then
			echo "Choosing installed Peak driver as CAN driver."
			SUB_CAN_DRIVER=peak_win32		
		else
			echo "Choosing virtual CAN driver."
			SUB_CAN_DRIVER=virtual
		fi
	fi
fi

# If target is unix, default timers also
if [ "$SUB_TARGET" = "unix" -a "$SUB_TIMERS_DRIVER" = "" ]; then
	echo "Choosing unix timers driver."
	SUB_TIMERS_DRIVER=unix
fi

# Warn for unstalled peak driver if choosen
if [ "$SUB_CAN_DRIVER" = "peak" ]; then
	if [ ! -e /usr/lib/libpcan.so ]; then 
		echo "Peak driver hasn't been installed !"
		exit -1
	fi
fi

###########################################################################
#              TARGET/DRIVER SPECIFIC CFLAGS and OPTIONS                  #
###########################################################################
if [ "$SUB_TARGET" = "generic" ]; then
	if [ "$US_TO_TIMEVAL_FACTOR" = "" ]; then
		US_TO_TIMEVAL_FACTOR=1
	fi
	if [ "$TIMEVAL" = "" ]; then
		TIMEVAL=UNS64
	fi
	if [ "$TIMEVAL_MAX" = "" ]; then
		TIMEVAL_MAX=0xffffffffffffffff
	fi
fi

if [ "$SUB_TARGET" = "hcs12" ]; then
	# Only if we want to compile for a µC HCS12
       # it is a big endian architecture.
       CANOPEN_BIG_ENDIAN=1
	# search for gcc hcs12 compiler m6811-elf-gcc or m68hc12-gcc ?
	if [ "$CC" = "" ]; then
		which m6811-elf-gcc >/dev/null 2>&1
		if (( $? )); then 
			which m68hc12-gcc >/dev/null 2>&1
			if (( $? )); then 
				echo "Please use --cc flag to specify compiler"
				exit 0
			else
				CC=m68hc12-gcc 
			fi
		else
			CC=m6811-elf-gcc
			SUB_PROG_CFLAGS=-m68hc12
		fi
	fi
fi	

#### CAN_DRIVER ####

if [ "$SUB_CAN_DRIVER" = "peak_linux" ]; then
    SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -lpcan
fi

PW32DIR=drivers/can_peak_win32
if [ "$SUB_CAN_DRIVER" = "peak_win32" ]; then
	if [ "$PCAN_HEADER" = "" -o "PCAN_LIB" = "" ]; then
		echo "!!! ERROR !!! Please set PCAN_LIB PCAN_HEADER [PCAN_INCLUDE] to appropriate paths ! "
	fi
   	SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ -liberty\ \'$PCAN_LIB\'
	echo "Converting PcanLib header files for gcc -> $PW32DIR/cancfg.h"
	cat $PW32DIR/cancfg.h.head $PCAN_INCLUDE/$PCAN_HEADER > $PW32DIR/cancfg.h
	# second port handling
	if [ "$PCAN2_HEADER" != "" ]; then
		echo "Stripping down second Pcan Light header "
		echo >> $PW32DIR/cancfg.h
		echo "// Stripped PcanLight header to prevent typedef conflicts ">> $PW32DIR/cancfg.h
		echo >> $PW32DIR/cancfg.h
		grep __stdcall $PCAN_INCLUDE/$PCAN2_HEADER >> $PW32DIR/cancfg.h
		echo '#define PCAN2_HEADER_' >> $PW32DIR/cancfg.h
	   	SUB_CAN_DLL_CFLAGS=$SUB_CAN_DLL_CFLAGS\ \'$PCAN2_LIB\'
	fi
	if grep -q CANHwType $PW32DIR/cancfg.h ; then
		echo "Peak Init HwType, IO_Port and IRQ will be passed in environment :"
		echo "	PCANHwType PCANIO_Port PCANInterupt"
		echo '#define extra_PCAN_init_params' >> $PW32DIR/cancfg.h
	fi
	cat $PW32DIR/cancfg.h.tail >> $PW32DIR/cancfg.h
fi

if [ "$SUB_CAN_DRIVER" = "none" ]; then
	SUB_CAN_DRIVER=
fi

#### TIMERS_DRIVER ####

if [ "$SUB_TIMERS_DRIVER" = "unix" ]; then
	if [ "$SUB_OS_NAME" != "CYGWIN" ]; then
	   SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lpthread\ -lrt
	fi
fi

if [ "$SUB_TIMERS_DRIVER" = "xeno" ]; then
	SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -lnative\ -lrtdm\
\	-L`$XENO_CONFIG --library-dir`
	SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ `$XENO_CONFIG --xeno-cflags`
	RTCAN_SOCKET=1
fi

if [ "$SUB_TIMERS_DRIVER" = "none" ]; then
	SUB_TIMERS_DRIVER=
fi

###########################################################################
#                              GUESS COMPILER                             #
###########################################################################
# If CC is empty, the user wanted automatic detection
if [ "$CC" = "" ]; then
	# Check for second compiler, CC2
	cat > $test.c <<EOF
	int main() { return 0; }
EOF
	if test "`($CC2 -c $CFLAGS $test.c) 2>&1`" = ""; then
		DETECTCC=$CC2
		echo "Checking for ${CC2}... Yes."
	else
		echo "Checking for ${CC2}... No."
	fi
	rm -f $test.c $test.o
	
	# Check for first compiler, CC1
	cat > $test.c <<EOF
	int main() { return 0; }
EOF
	if test "`($CC1 -c $CFLAGS $test.c) 2>&1`" = ""; then
		DETECTCC=$CC1
		echo "Checking for ${CC1}... Yes."
	else
		echo "Checking for ${CC1}... No."
	fi
	rm -f $test.c $test.o
	CC=$DETECTCC
fi
# Check if we decided on a compiler after all
if [ "$CC" = "" ]; then
	echo "Error: Could not find a C compiler"
	echo "Please supply the wanted compiler"
	exit -1
fi

echo "Using ${CC}"

###########################################################################
#                              GUESS PREFIX's                             #
###########################################################################

SUB_BINUTILS_PREFIX=`echo "$CC" | sed 's/gcc$//'`

# Guess prefix as regard cross compiling target machine
if [ "$SUB_PREFIX" = "" ]; then
	$CC -dumpspecs |grep -A 1 'cross_compile'|grep -q 1
	if (( $? )); then 
		SUB_PREFIX=/usr/local
		echo "Not cross-compiling. Will install in $SUB_PREFIX";
	else
		SUB_PREFIX=/usr/`$CC -dumpmachine`
		echo "This is a cross-compiler. Will install in $SUB_PREFIX";			
	fi
fi

echo "Using prefix: ${SUB_PREFIX}"

###########################################################################
#                   CANFESTIVAL DEFINES --> config.h                      #
###########################################################################
# Some CONSTANTS preparation

# Create include/config.h with the relevant contents
rm -f include/config.h
echo "/* !!!!!!!!!! FILE GENERATED by configure. DO NOT EDIT !!!!!!!!!!*/" >>  include/config.h
echo "" >>  include/config.h
echo "/*"\ >>  include/config.h
echo "This file is part of CanFestival, a library implementing CanOpen Stack." >> include/config.h
echo "" >> include/config.h
echo "Copyright (C): Edouard TISSERANT and Francis DUPIN" >> include/config.h
echo "See COPYING file for copyrights details." >> include/config.h
echo "" >> include/config.h
echo "This library is free software; you can redistribute it and/or" >> include/config.h
echo "modify it under the terms of the GNU Lesser General Public" >> include/config.h
echo "License as published by the Free Software Foundation; either" >> include/config.h
echo "version 2.1 of the License, or (at your option) any later version." >> include/config.h
echo "" >> include/config.h
echo "This library is distributed in the hope that it will be useful," >> include/config.h
echo "but WITHOUT ANY WARRANTY; without even the implied warranty of" >> include/config.h
echo "MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU" >> include/config.h
echo "Lesser General Public License for more details." >> include/config.h
echo "" >> include/config.h
echo "You should have received a copy of the GNU Lesser General Public" >> include/config.h
echo "License along with this library; if not, write to the Free Software" >> include/config.h
echo "Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA" >> include/config.h
echo "*/" >> include/config.h
echo "" >> include/config.h
echo "#ifndef _CONFIG_H_" >> include/config.h
echo "#define _CONFIG_H_" >> include/config.h
echo "" >> include/config.h
for i in \
 MAX_CAN_BUS_ID\
 SDO_MAX_LENGTH_TRANSFERT\
 SDO_MAX_SIMULTANEOUS_TRANSFERTS\
 NMT_MAX_NODE_ID\
 SDO_TIMEOUT_MS\
 MAX_NB_TIMER\
 CANOPEN_BIG_ENDIAN\
 US_TO_TIMEVAL_FACTOR\
 TIMEVAL\
 TIMEVAL_MAX\
 RTCAN_SOCKET; do
if [ "${!i}" = "" ]; then
echo "/* $i is not defined */" >> include/config.h
else
echo "#define $i ${!i}" >> include/config.h
fi
done	
echo "" >> include/config.h

for i in \
 SDO_MAX_SIMULTANEOUS_TRANSFERTS\
 NMT_MAX_NODE_ID; do
	echo "#define REPEAT_"$i"_TIMES(repeat)\\">> include/config.h
	times=${!i}
	result=""
	for (( j=0; j<times; j++ ));do
		result="$result repeat"
	done
	echo $result >> include/config.h
done

echo "#endif /* _CONFIG_H_ */" >> include/config.h

###########################################################################
#                           DEBUG DEFINES/CFLAGS                          #
###########################################################################
if [ "$DEBUG" = "WAR" ]; then
	SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_WAR_CONSOLE_ON\ -DDEBUG_ERR_CONSOLE_ON\ -g
fi

if [ "$DEBUG" = "ERR" ]; then
	SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_ERR_CONSOLE_ON\ -g
fi

if [ "$DEBUG" = "PDO" ]; then
	SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DDEBUG_WAR_CONSOLE_ON\ -DDEBUG_ERR_CONSOLE_ON\ -g\ -DPDO_ERROR
fi

if [ "$DISABLE_OPT" = "1" ]; then
	SUB_OPT_CFLAGS=
else
	SUB_OPT_CFLAGS=\$\(OPT_CFLAGS\)
fi

if [ "$DISABLE_DLL" = "1" ]; then
	SUB_PROG_CFLAGS=$SUB_PROG_CFLAGS\ -DNOT_USE_DYNAMIC_LOADING
	SUB_ENABLE_DLL_DRIVERS=0
else
	SUB_ENABLE_DLL_DRIVERS=1
	SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ -ldl
fi


if [ "$DISABLE_DLL" = "1" ]; then
	SUB_EXE_CFLAGS=$SUB_EXE_CFLAGS\ $SUB_CAN_DLL_CFLAGS
fi

###########################################################################
#                              CREATE MAKEFILES                           #
###########################################################################
# General Makefiles
MAKEFILES=Makefile.in\
\ src/Makefile.in\
\ drivers/Makefile.in\
\ objdictgen/Makefile.in\
\ examples/Makefile.in

# Drivers dependent Makefiles
if [ "$SUB_TIMERS_DRIVER" != "" ]; then
	MAKEFILES=$MAKEFILES\
\	drivers/timers_$SUB_TIMERS_DRIVER/Makefile.in
fi

if [ "$SUB_CAN_DRIVER" != "" ]; then
	MAKEFILES=$MAKEFILES\
\	drivers/can_$SUB_CAN_DRIVER/Makefile.in
fi

# Target dependent Makefiles
MAKEFILES=$MAKEFILES\ drivers/$SUB_TARGET/Makefile.in

if [ "$SUB_TARGET" = "unix" ]; then
	MAKEFILES=$MAKEFILES\
\	examples/TestMasterSlave/Makefile.in
fi

if [ "$SUB_TARGET" = "unix" ]; then
	MAKEFILES=$MAKEFILES\
\	examples/TestMasterMicroMod/Makefile.in
fi

if [ "$SUB_TARGET" = "hcs12" ]; then
	MAKEFILES=$MAKEFILES\
\	examples/gene_SYNC_HCS12/Makefile.in
fi

for makefile_in in $MAKEFILES; do
	makefile=`echo $makefile_in | sed 's:.in$::'`
	echo "Creating $makefile"
	sed < $makefile_in "
	s:SUB_CC:${CC}:
	s:SUB_PROG_CFLAGS:${SUB_PROG_CFLAGS}:
	s:SUB_EXE_CFLAGS:${SUB_EXE_CFLAGS}:
	s:SUB_PREFIX:${SUB_PREFIX}:
	s:SUB_OS_NAME:${SUB_OS_NAME}:
	s:SUB_ARCH_NAME:${SUB_ARCH_NAME}:
	s:SUB_OPT_CFLAGS:${SUB_OPT_CFLAGS}:
	s:SUB_TARGET:${SUB_TARGET}:
	s:SUB_BINUTILS_PREFIX:${SUB_BINUTILS_PREFIX}:
	s:SUB_TIMERS_DRIVER:timers_${SUB_TIMERS_DRIVER}:
	s:SUB_CAN_DRIVER:can_${SUB_CAN_DRIVER}:
	s:SUB_CAN_DLL_CFLAGS:${SUB_CAN_DLL_CFLAGS}:
	s:SUB_ENABLE_DLL_DRIVERS:${SUB_ENABLE_DLL_DRIVERS}:
	" > $makefile
done

echo "All done."