functions
295 lines
| 9.0 KiB
| text/plain
|
TextLexer
/ bin / functions
r7 | #!/bin/bash | |||
#/*------------------------------------------------------------------------------ | ||||
#-- This file is a part of the libuc, microcontroler library | ||||
#-- Copyright (C) 2011, Alexis Jeandet | ||||
#-- | ||||
#-- This program is free software; you can redistribute it and/or modify | ||||
#-- it under the terms of the GNU General Public License as published by | ||||
#-- the Free Software Foundation; either version 3 of the License, or | ||||
#-- (at your option) any later version. | ||||
#-- | ||||
#-- This program 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 General Public License for more details. | ||||
#-- | ||||
#-- You should have received a copy of the GNU General Public License | ||||
#-- along with this program; if not, write to the Free Software | ||||
#-- Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||||
#------------------------------------------------------------------------------- | ||||
#-- Author : Alexis Jeandet | ||||
#-- Mail : alexis.jeandet@gmail.com | ||||
#-------------------------------------------------------------------------------*/ | ||||
|
r15 | function readFile { | ||
more $1 | sed 's/#.*//' | grep -i $2' ' | ||||
} | ||||
r7 | function getFilesList { | |||
sed ':a;N;$!ba;s/\\\n/ /g' $1 | sed ':a;N;$!ba;s/\\ \n/ /g' | grep -i $2 | sed 's/\t//g' | ||||
} | ||||
function Template { | ||||
|
r15 | TEMPLATE=`readFile $1 "TEMPLATE" | sed s/TEMPLATE// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
r7 | } | |||
function Arch { | ||||
r9 | if [ -z "$2" ] ; then | |||
|
r15 | ARCH=`readFile $1 "ARCH" | sed s/ARCH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
r9 | else | |||
|
r15 | TEMP=`readFile $1 "$2.ARCH"` | ||
if [ -z "$TEMP" ] ; then | ||||
ARCH=`readFile $1 "*.ARCH" | sed 's/*\.'ARCH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
else | ||||
ARCH=`readFile $1 "$2.ARCH" | sed s/$2'\.'ARCH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
fi | ||||
r9 | fi | |||
r7 | } | |||
function Target { | ||||
r9 | if [ -z "$2" ] ; then | |||
|
r15 | TARGET=`readFile $1 "TARGET" | sed s/TARGET// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
r9 | else | |||
|
r15 | TARGET=`readFile $1 "$2.TARGET" | sed s/$2'\.'TARGET// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
r9 | fi | |||
} | ||||
r12 | ||||
function Objdir { | ||||
if [ -z "$2" ] ; then | ||||
|
r15 | OBJDIR=`readFile $1 "OBJDIR" | sed s/OBJDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
r12 | if [ -z "$OBJDIR" ] ; then | |||
OBJDIR="obj" | ||||
fi | ||||
else | ||||
|
r15 | TEMP=`readFile $1 "$2.OBJDIR"` | ||
if [ -z "$TEMP" ] ; then | ||||
OBJDIR=`readFile $1 "*.OBJDIR" | sed 's/*\.'OBJDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
if [ -z "$OBJDIR" ] ; then | ||||
OBJDIR="obj" | ||||
fi | ||||
else | ||||
OBJDIR=`readFile $1 "$2.OBJDIR" | sed s/$2'\.'OBJDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
if [ -z "$OBJDIR" ] ; then | ||||
OBJDIR="obj" | ||||
fi | ||||
r12 | fi | |||
fi | ||||
} | ||||
function Bindir { | ||||
if [ -z "$2" ] ; then | ||||
|
r15 | BINDIR=`readFile $1 "BINDIR" | sed s/BINDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
r12 | if [ -z "$BINDIR" ] ; then | |||
BINDIR="bin" | ||||
fi | ||||
else | ||||
|
r15 | TEMP=`readFile $1 "$2.BINDIR"` | ||
if [ -z "$TEMP" ] ; then | ||||
BINDIR=`readFile $1 "*.BINDIR" | sed 's/*\.'BINDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
if [ -z "$BINDIR" ] ; then | ||||
BINDIR="bin" | ||||
fi | ||||
else | ||||
BINDIR=`readFile $1 "$2.BINDIR" | sed s/$2'\.'BINDIR// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
if [ -z "$BINDIR" ] ; then | ||||
BINDIR="bin" | ||||
fi | ||||
r12 | fi | |||
fi | ||||
} | ||||
r9 | function Targets { | |||
|
r15 | TARGETS=`readFile $1 ".TARGET" | sed 's/\.TARGET.*//'` | ||
r7 | } | |||
function Libs_Inc { | ||||
r9 | if [ -z "$2" ] ; then | |||
|
r15 | INCLUDEStmp=`readFile $1 "LIBS" | sed s/LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
r9 | for FILES in $INCLUDEStmp | |||
do | ||||
INCLUDES+='$('"LIBUC_INC_DIR_""$FILES""_CMD) " | ||||
r12 | INC_LIBS_DEPS+='$('"LIBUC_INC_DIR_""$FILES"") " | |||
r9 | done | |||
else | ||||
|
r15 | TEMP=`readFile $1 "$2.LIBS"` | ||
if [ -z "$TEMP" ] ; then | ||||
INCLUDEStmp=`readFile $1 "*.LIBS" | sed 's/*\.'LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
for FILES in $INCLUDEStmp | ||||
do | ||||
INCLUDES+='$('"LIBUC_INC_DIR_""$FILES""_CMD) " | ||||
INC_LIBS_DEPS+='$('"LIBUC_INC_DIR_""$FILES"") " | ||||
done | ||||
else | ||||
INCLUDEStmp=`readFile $1 "$2.LIBS" | sed s/$2'\.'LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
for FILES in $INCLUDEStmp | ||||
do | ||||
INCLUDES+='$('"LIBUC_INC_DIR_""$FILES""_CMD) " | ||||
INC_LIBS_DEPS+='$('"LIBUC_INC_DIR_""$FILES"") " | ||||
done | ||||
fi | ||||
r9 | fi | |||
|
r14 | if [ -z "$2" ] ; then | ||
|
r15 | INCLUDEStmp=`readFile $1 "INCLUDES" | sed s/INCLUDES// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
|
r14 | for FILES in $INCLUDEStmp | ||
do | ||||
INCLUDES+="-I "$FILES" " | ||||
done | ||||
else | ||||
|
r15 | TEMP=`readFile $1 "$2.INCLUDES"` | ||
if [ -z "$TEMP" ] ; then | ||||
INCLUDEStmp=`readFile $1 "*.INCLUDES" | sed 's/*\.'INCLUDES// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
for FILES in $INCLUDEStmp | ||||
do | ||||
INCLUDES+="-I "$FILES" " | ||||
done | ||||
else | ||||
INCLUDEStmp=`readFile $1 "$2.INCLUDES" | sed s/$2'\.'INCLUDES// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
for FILES in $INCLUDEStmp | ||||
do | ||||
INCLUDES+="-I "$FILES" " | ||||
done | ||||
fi | ||||
|
r14 | fi | ||
r9 | ||||
r7 | } | |||
r9 | ||||
r7 | function Libs_Link { | |||
r9 | if [ -z "$2" ] ; then | |||
|
r15 | LIBRARIEStmp=`readFile $1 "LIBS" | sed s/LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
r9 | for FILES in $LIBRARIEStmp | |||
do | ||||
LIBRARIES+='$('"LIBUC_LIBS_DIR_""$FILES""_CMD) "'$('"LIBUC_LIBS_$FILES) " | ||||
r12 | BIN_LIBS_DEPS='$('"LIBUC_LIBS_DIR_""$FILES"")" | |||
r9 | done | |||
else | ||||
|
r15 | TEMP=`readFile $1 "$2.LIBS"` | ||
if [ -z "$TEMP" ] ; then | ||||
LIBRARIEStmp=`readFile $1 "*.LIBS" | sed 's/*\.'LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
for FILES in $LIBRARIEStmp | ||||
do | ||||
LIBRARIES+='$('"LIBUC_LIBS_DIR_""$FILES""_CMD) "'$('"LIBUC_LIBS_$FILES) " | ||||
BIN_LIBS_DEPS='$('"LIBUC_LIBS_DIR_""$FILES"")" | ||||
done | ||||
else | ||||
LIBRARIEStmp=`readFile $1 "$2.LIBS" | sed s/$2'\.'LIBS// |sed s/+//|sed s/=//| sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
for FILES in $LIBRARIEStmp | ||||
do | ||||
LIBRARIES+='$('"LIBUC_LIBS_DIR_""$FILES""_CMD) "'$('"LIBUC_LIBS_$FILES) " | ||||
BIN_LIBS_DEPS='$('"LIBUC_LIBS_DIR_""$FILES"")" | ||||
done | ||||
fi | ||||
r9 | fi | |||
r7 | } | |||
function HeadersInstallPath { | ||||
r9 | if [ -z "$2" ] ; then | |||
|
r15 | HEADERSINSTALLPATH=`readFile $1 "HEADERSINSTALLPATH" | sed s/HEADERSINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
else | ||||
TEMP=`readFile $1 "$2.HEADERSINSTALLPATH"` | ||||
if [ -z "$TEMP" ] ; then | ||||
HEADERSINSTALLPATH=`readFile $1 "*.HEADERSINSTALLPATH" | sed 's/*\.'HEADERSINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
else | ||||
HEADERSINSTALLPATH=`readFile $1 "$2.HEADERSINSTALLPATH" | sed s/$2'\.'HEADERSINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
fi | ||||
fi | ||||
if [ -z "$HEADERSINSTALLPATH" ] ; then | ||||
echo "$0 error on file $1 you forget to give the headers install path" | ||||
echo " solution: set the varriable HEADERSINSTALLPATH in $1" | ||||
fi | ||||
} | ||||
function ExtractCFLAGS { | ||||
if [ -z "$2" ] ; then | ||||
CFLAGS=`readFile $1 "CFLAGS" | sed s/CFLAGS/LIBUC_CFLAGS/ ` | ||||
r9 | else | |||
|
r15 | TEMP=`readFile $1 "$2.CFLAGS"` | ||
if [ -z "$TEMP" ] ; then | ||||
CFLAGS=`readFile $1 "*.CFLAGS" | sed 's/*\.'CFLAGS/LIBUC_CFLAGS/ ` | ||||
else | ||||
CFLAGS=`readFile $1 "$2.CFLAGS" | sed s/$2'\.'CFLAGS/LIBUC_CFLAGS/ ` | ||||
fi | ||||
fi | ||||
r7 | } | |||
|
r15 | |||
function ExtractLDFLAGS { | ||||
if [ -z "$2" ] ; then | ||||
LDFLAGS=`readFile $1 "LDFLAGS" | sed s/LDFLAGS/LIBUC_LDFLAGS/ ` | ||||
else | ||||
TEMP=`readFile $1 "$2.LDFLAGS"` | ||||
if [ -z "$TEMP" ] ; then | ||||
LDFLAGS=`readFile $1 "*.LDFLAGS" | sed 's/*\.'LDFLAGS/LIBUC_LDFLAGS/ ` | ||||
else | ||||
LDFLAGS=`readFile $1 "$2.LDFLAGS" | sed s/$2'\.'LDFLAGS/LIBUC_LDFLAGS/ ` | ||||
fi | ||||
fi | ||||
} | ||||
function ExtractODFLAGS { | ||||
if [ -z "$2" ] ; then | ||||
ODFLAGS=`readFile $1 "ODFLAGS" | sed s/ODFLAGS/LIBUC_ODFLAGS/ ` | ||||
else | ||||
TEMP=`readFile $1 "$2.ODFLAGS"` | ||||
if [ -z "$TEMP" ] ; then | ||||
ODFLAGS=`readFile $1 "*.ODFLAGS" | sed 's/*\.'ODFLAGS/LIBUC_ODFLAGS/ ` | ||||
else | ||||
ODFLAGS=`readFile $1 "$2.ODFLAGS" | sed s/$2'\.'ODFLAGS/LIBUC_ODFLAGS/ ` | ||||
fi | ||||
fi | ||||
} | ||||
r7 | function TargetInstallPath { | |||
r9 | if [ -z "$2" ] ; then | |||
|
r15 | TARGETINSTALLPATH=`readFile $1 "TARGETINSTALLPATH" | sed s/TARGETINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||
r9 | else | |||
|
r15 | TEMP=`readFile $1 "$2.TARGETINSTALLPATH"` | ||
if [ -z "$TEMP" ] ; then | ||||
TARGETINSTALLPATH=`readFile $1 '*.TARGETINSTALLPATH' | sed 's/*\.'TARGETINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
else | ||||
TARGETINSTALLPATH=`readFile $1 "$2.TARGETINSTALLPATH" | sed s/$2'\.'TARGETINSTALLPATH// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
fi | ||||
r9 | fi | |||
|
r15 | if [ -z "$TARGETINSTALLPATH" ] ; then | ||
echo "$0 error on file $1 you forget to give the target install path" | ||||
echo " solution: set the varriable TARGETINSTALLPATH in $1" | ||||
fi | ||||
r7 | } | |||
function getBSP { | ||||
r9 | if [ -z "$2" ] ; then | |||
|
r15 | if(more $1 | sed 's/#.*//' | grep -i "BSP ="); then | ||
BSP=`readFile $1 "BSP" | sed s/BSP// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
r9 | fi | |||
else | ||||
|
r15 | TEMP=`readFile $1 "$2.BSP"` | ||
if [ -z "$TEMP" ] ; then | ||||
if(more $1 | sed 's/#.*//' | grep -i "*.BSP ="); then | ||||
BSP=`readFile $1 "*.BSP" | sed 's/*\.'BSP// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
fi | ||||
else | ||||
if(more $1 | sed 's/#.*//' | grep -i "$2.BSP ="); then | ||||
BSP=`readFile $1 "$2.BSP" | sed s/$2'\.'BSP// | sed s/=// | sed 's/^[ \t]*//;s/[ \t]*$//'` | ||||
fi | ||||
r9 | fi | |||
fi | ||||
|
r15 | if [ -z "$BSP" ] ; then | ||
echo "$0 error on file $1 you forget to give the board support package" | ||||
echo " solution: set the varriable BSP in $1" | ||||
fi | ||||
r7 | ||||
} | ||||
r9 | ||||