aboutsummaryrefslogtreecommitdiffstats
path: root/libraries/vendors/shared.sh
diff options
context:
space:
mode:
Diffstat (limited to 'libraries/vendors/shared.sh')
-rwxr-xr-xlibraries/vendors/shared.sh336
1 files changed, 243 insertions, 93 deletions
diff --git a/libraries/vendors/shared.sh b/libraries/vendors/shared.sh
index 4f6470b6e..7112b4bb7 100755
--- a/libraries/vendors/shared.sh
+++ b/libraries/vendors/shared.sh
@@ -1,17 +1,18 @@
# EMACS settings: -*- tab-width: 2; indent-tabs-mode: t -*-
# vim: tabstop=2:shiftwidth=2:noexpandtab
# kate: tab-width 2; replace-tabs off; indent-width 2;
-#
+#
# ==============================================================================
# Authors: Patrick Lehmann
-#
-# Bash Script: This is a Bash resource file.
-#
+#
+# Bash Script: This is a Bash resource file.
+#
# Description:
# ------------------------------------
# TODO
#
# ==============================================================================
+# Copyright (C) 2017-2021 Patrick Lehmann - Boetzingen, Germany
# Copyright (C) 2015-2016 Patrick Lehmann - Dresden, Germany
#
# This program is free software: you can redistribute it and/or modify
@@ -28,85 +29,92 @@
# along with this program. If not, see <gnu.org/licenses>.
# ==============================================================================
-# red texts
-COLORED_ERROR="$ANSI_RED[ERROR]$ANSI_NOCOLOR"
-COLORED_FAILED="$ANSI_RED[FAILED]$ANSI_NOCOLOR"
-
-# green texts
-COLORED_DONE="$ANSI_GREEN[DONE]$ANSI_NOCOLOR"
-COLORED_SUCCESSFUL="$ANSI_GREEN[SUCCESSFUL]$ANSI_NOCOLOR"
# set bash options
set -o pipefail
+if [[ -n "$GHDL" ]]; then
+ if [[ ! -f "$GHDL" ]]; then
+ echo 1>&2 -e "${COLORED_ERROR} Found GHDL environment variable, but '$GHDL' is not a file.${ANSI_NOCOLOR}"
+ exit 1
+ elif [[ ! -x "$GHDL" ]]; then
+ echo 1>&2 -e "${COLORED_ERROR} Found GHDL environment variable, but '$GHDL' is not executable.${ANSI_NOCOLOR}"
+ exit 1
+ fi
+else # fall back to GHDL found via PATH
+ GHDL=$(which ghdl 2>/dev/null)
+ if [[ $? -ne 0 ]]; then
+ echo 1>&2 -e "${COLORED_ERROR} GHDL not found in PATH.${ANSI_NOCOLOR}"
+ echo 1>&2 -e " Use adv. options '--ghdl' to set the GHDL binary directory."
+ exit 1
+ fi
+fi
+
+# Analyze_Filter=GHDL/filter.analyze.sh
+Analyze_Parameters=(
+ -frelaxed-rules
+ --mb-comments
+)
+
+VERBOSE=${VERBOSE:-0}
+DEBUG=${DEBUG:-0}
+CONTINUE_ON_ERROR=${CONTINUE_ON_ERROR:-0}
+
+test $VERBOSE -eq 1 && echo -e " Declaring Bash functions for GHDL..."
+
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function SetupDirectories( <Index> <Name> )${ANSI_NOCOLOR}"
+# SetupDirectories
+# -> $Index
+# -> $Name
+# <= $SourceDirectory
+# <= $DestinationDirectory
SetupDirectories() {
- Index=$1
- Name=$2
+ local Index=$1
+ local Name=$2
+
+ declare -n Settings="${Index}_Settings"
# source directory
# ----------------------
# If a command line argument ('--src') was passed in, use it, else use the default value
# from config.sh
- if [ ! -z "$SrcDir" ]; then
+ if [[ ! -z "$SrcDir" ]]; then
SourceDirectory=${SrcDir%/} # remove trailing slashes
- elif [ ! -z "$EnvSourceDir" ]; then
+ elif [[ ! -z "$EnvSourceDir" ]]; then
SourceDirectory=$EnvSourceDir # fall back to environment variable
- elif [ ! -z "${InstallationDirectories[$Index]}" ]; then
- SourceDirectory=${InstallationDirectories[$Index]}/${SourceDirectories[$Index]} # fall back to value from config.sh
+ elif [[ ! -z "${Settings[InstallationDirectory]}" ]]; then
+ SourceDirectory=${Settings[InstallationDirectory]}/${Settings[SourceDirectory]} # fall back to value from config.sh
fi
# output directory
# ----------------------
# If a command line argument ('--out') was passed in, use it, else use the default value
# from config.sh
- if [ ! -z "$DestDir" ]; then
+ if [[ ! -z "$DestDir" ]]; then
DestinationDirectory=${DestDir%/} # remove trailing slashes
else
- DestinationDirectory=${DestinationDirectories[$Index]} # fall back to value from config.sh
+ DestinationDirectory=${Settings[DestinationDirectory]} # fall back to value from config.sh
fi
- if [ -z $SourceDirectory ] || [ -z $DestinationDirectory ]; then
+ if [[ -z $SourceDirectory || -z $DestinationDirectory ]]; then
echo 1>&2 -e "${COLORED_ERROR} $Name is not configured in '$ScriptDir/config.sh'.${ANSI_NOCOLOR}"
echo 1>&2 -e " Use adv. options '--src' and '--out' or configure 'config.sh'."
- exit -1
- elif [ ! -d $SourceDirectory ]; then
+ exit 1
+ elif [[ ! -d $SourceDirectory ]]; then
echo 1>&2 -e "${COLORED_ERROR} Path '$SourceDirectory' does not exist.${ANSI_NOCOLOR}"
- exit -1
+ exit 1
fi
# Resolve paths to an absolute paths
- if greadlink --version > /dev/null 2>&1 ; then
- READLINK=greadlink
- else
- READLINK=readlink
- fi
+ READLINK=readlink; if [[ $(uname) == "Darwin" ]]; then READLINK=greadlink; fi
SourceDirectory=$($READLINK -f $SourceDirectory)
if [[ ! "$DestinationDirectory" = /* ]]; then
DestinationDirectory=$WorkingDir/$DestinationDirectory
fi
-
- # Use GHDL binary directory from command line argument, if set
- if [ ! -z "$GHDLBinDir" ]; then
- GHDLBinary=${GHDLBinDir%/}/ghdl # remove trailing slashes
- if [[ ! -x "$GHDLBinary" ]]; then
- echo 1>&2 -e "${COLORED_ERROR} GHDL not found or is not executable.${ANSI_NOCOLOR}"
- exit -1
- fi
- elif [ ! -z "$GHDL" ]; then
- if [ ! \( -f "$GHDL" -a -x "$GHDL" \) ]; then
- echo 1>&2 -e "${COLORED_ERROR} Found GHDL environment variable, but '$GHDL' is not executable.${ANSI_NOCOLOR}"
- exit -1
- fi
- GHDLBinary=$GHDL
- else # fall back to GHDL found via PATH
- GHDLBinary=$(which ghdl 2>/dev/null)
- if [ $? -ne 0 ]; then
- echo 1>&2 -e "${COLORED_ERROR} GHDL not found in PATH.${ANSI_NOCOLOR}"
- echo 1>&2 -e " Use adv. options '--ghdl' to set the GHDL binary directory."
- exit -1
- fi
- fi
}
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function SetupGRCat( undocumented )${ANSI_NOCOLOR}"
+# SetupGRCat
+# -> undocumented
SetupGRCat() {
if [ -z "$(which grcat 2>/dev/null)" ]; then
# if grcat (generic colourizer) is not installed, use a dummy pipe command like 'cat'
@@ -118,18 +126,27 @@ SetupGRCat() {
fi
}
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function CreateDestinationDirectory( undocumented )${ANSI_NOCOLOR}"
+# CreateDestinationDirectory
+# -> undocumented
CreateDestinationDirectory() {
if [ -d "$DestinationDirectory" ]; then
echo -e "${ANSI_YELLOW}Vendor directory '$DestinationDirectory' already exists.${ANSI_NOCOLOR}"
elif [ -f "$DestinationDirectory" ]; then
echo 1>&2 -e "${COLORED_ERROR} Vendor directory '$DestinationDirectory' already exists as a file.${ANSI_NOCOLOR}"
- exit -1
+ exit 1
else
echo -e "${ANSI_YELLOW}Creating vendor directory: '$DestinationDirectory'.${ANSI_NOCOLOR}"
mkdir -p "$DestinationDirectory"
fi
}
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function GHDLSetup( <VHDLStandard> )${ANSI_NOCOLOR}"
+# GHDLSetup
+# -> $VHDLStandard # FIXME: make it a real parameter
+# <= $VHDLVersion
+# <= $VHDLStandard
+# <= $VHDLFlavor
GHDLSetup() {
if [ $VHDLStandard -eq 93 ]; then
VHDLVersion="v93"
@@ -142,52 +159,185 @@ GHDLSetup() {
fi
}
-GHDLCompileLibrary() {
- # assembling output directory
- LibraryDirectory=$DestinationDirectory/$Library/$VHDLVersion
- mkdir -p $LibraryDirectory
- cd $LibraryDirectory
- echo -e "${ANSI_YELLOW}Compiling library '$Library'...${ANSI_NOCOLOR}"
-
- for File in ${SourceFiles[@]}; do
- FileName=$(basename "$File")
- FileSize=($(wc -c $File))
- if [ $SKIP_EXISTING_FILES -eq 1 ] && [ -e "${FileName%.*}.o" ]; then
- echo -e "${ANSI_CYAN}Skipping existing file '$File'${ANSI_NOCOLOR}"
- elif [ $SKIP_LARGE_FILES -eq 1 ] && [ ${FileSize[0]} -gt $LARGE_FILESIZE ]; then
- echo -e "${ANSI_CYAN}Skipping large file '$File'${ANSI_NOCOLOR}"
- else
- echo -e "${ANSI_DARKCYAN}Analyzing file '$File'${ANSI_NOCOLOR}"
- $GHDLBinary -a ${GHDL_PARAMS[@]} --work=$Library "$File" 2>&1 | $GRC_COMMAND
- if [ $? -ne 0 ]; then
- let ERRORCOUNT++
- test $HALT_ON_ERROR -eq 1 && return 1
- fi
- fi
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function CreateVHDLLibrary( <StructName> <LibraryName> <LibraryPath> <VHDLVersion> <Files[*]> )${ANSI_NOCOLOR}"
+# CreateLibraryStruct
+# -> $StructName
+# -> $LibraryName
+# -> $LibraryPath
+# -> $VHDLVersion
+# -> $Files[*]
+CreateLibraryStruct() {
+ local StructName=$1; shift
+
+ declare -g "${StructName}_LibraryName"=$1; shift
+ declare -g "${StructName}_LibraryPath"=$1; shift
+ declare -g "${StructName}_VHDLVersion"=$1; shift
+
+ declare -n FilesRef="${StructName}_Files"
+ FilesRef=( "$*" )
+}
+
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function DeleteLibraryStruct( <StructName> )${ANSI_NOCOLOR}"
+# DeleteLibraryStruct
+# -> $StructName
+DeleteLibraryStruct() {
+ local StructName=$1
+
+ unset "${StructName}_VHDLVersion"
+ unset "${StructName}_LibraryName"
+ unset "${StructName}_LibraryPath"
+ unset "${StructName}_Files"
+}
+
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function PrintLibraryStruct( <StructName> )${ANSI_NOCOLOR}"
+# PrintLibraryStruct
+# -> $StructName
+PrintLibraryStruct() {
+ local StructName=$1
+ local Indentation=${2:-" "}
+
+ local LibraryName="${StructName}_LibraryName"; local LibraryName=${!LibraryName}
+ local Files="${StructName}_Files[*]"; local Files=${!Files}
+
+ echo -e "$Indentation${ANSI_DARK_GRAY}VHDL Library name: $LibraryName${ANSI_NOCOLOR}"
+ for File in ${Files[*]}; do
+ echo -e "$Indentation ${ANSI_DARK_GRAY}$File${ANSI_NOCOLOR}"
done
- return 0
}
-GHDLCompilePackages() {
- # assembling output directory
- LibraryDirectory=$DestinationDirectory/$Library/$VHDLVersion
- mkdir -p $LibraryDirectory
- cd $LibraryDirectory
- echo -e "${ANSI_YELLOW}Compiling library '$Library'...${ANSI_NOCOLOR}"
-
- for File in ${SourceFiles[@]}; do
- FileName=$(basename "$File")
- if [ $SKIP_EXISTING_FILES -eq 1 ] && [ -e "${FileName%.*}.o" ]; then
- echo -e "${ANSI_CYAN}Skipping existing package '$File'${ANSI_NOCOLOR}"
- else
- echo -e "${ANSI_DARKCYAN}Analyzing package '$File'${ANSI_NOCOLOR}"
- $GHDLBinary -a ${GHDL_PARAMS[@]} --work=$Library "$File" 2>&1 | $GRC_COMMAND
- if [ $? -ne 0 ]; then
- let ERRORCOUNT++
- test $HALT_ON_ERROR -eq 1 && return 1
- fi
+
+declare -A GHDLLibraryMapping
+
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function CreateVHDLLibrary( <LibraryName> <DirectoryName> <VHDLVersion> )${ANSI_NOCOLOR}"
+# CreateVHDLLibrary
+# -> $LibraryName
+# -> $DirectoryName
+# -> $VHDLVersion
+CreateVHDLLibrary() {
+ local LibraryName=$1
+ local DirectoryName=$2
+ local VHDLVersion=${3:-"v08"}
+
+ echo -e "${ANSI_YELLOW}Creating VHDL Library '$LibraryName'...${ANSI_NOCOLOR}"
+
+ test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}mkdir -p \"$DirectoryName/$VHDLVersion\"${ANSI_NOCOLOR}"
+ mkdir -p "$DirectoryName/$VHDLVersion"
+
+ LibraryDir="$(pwd)/$DirectoryName/$VHDLVersion"
+ test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}Mapping library $LibraryName to '$LibraryDir'.${ANSI_NOCOLOR}"
+ GHDLLibraryMapping[$LibraryName]=$LibraryDir
+}
+
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function AnalyzeVHDL( <LibraryName> <SourceDirectory> <LibraryPath> <File> )${ANSI_NOCOLOR}"
+# AnalyzeVHDL
+# -> $LibraryName
+# -> $SourceDirectory
+# -> $LibraryPath
+# -> $File
+AnalyzeVHDL() {
+ local LibraryName=$1
+ local SourceDirectory=$2
+ local LibraryPath=$3
+ local File=$4
+
+ local DestinationDirectory=${GHDLLibraryMapping[$LibraryName]}
+
+ if [[ $DEBUG -eq 1 ]]; then
+ local Parameters=(
+ -v
+ )
+ local Filter_Parameters=(
+ -d
+ )
+ local Filter_Indent=" "
+ elif [[ $VERBOSE -eq 1 ]]; then
+ local Parameters=()
+ local Filter_Parameters=(
+ -v
+ )
+ local Filter_Indent=" "
+ else
+ local Parameters=()
+ local Filter_Parameters=()
+ local Filter_Indent=" "
+ fi
+
+ local SourceFile="$SourceDirectory/$LibraryPath/$File"
+
+ if [[ ! -f "$SourceFile" ]]; then
+ echo 1>&2 -e "${COLORED_ERROR} Source file '$SourceFile' not found.${ANSI_NOCOLOR}"
+ test $CONTINUE_ON_ERROR -eq 0 && exit 1
+ fi
+
+ if [[ $FILTERING -eq 0 ]]; then
+ test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}$GHDL -a ${Analyze_Parameters[*]} ${Parameters[*]} --work=$LibraryName \"$SourceFile\"${ANSI_NOCOLOR}"
+ $GHDL -a ${Analyze_Parameters[@]} ${Parameters[@]} --work=$LibraryName --workdir=$DestinationDirectory "$SourceFile"
+ ExitCode=$?
+ if [[ $ExitCode -ne 0 ]]; then
+ echo 1>&2 -e "${COLORED_ERROR} While analyzing '$File'. ExitCode: $ExitCode${ANSI_NOCOLOR}"
+ test $CONTINUE_ON_ERROR -eq 0 && exit 1
fi
+ # else
+ # test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}$GHDL -a ${Analyze_Parameters[*]} ${Parameters[*]} --work=$LibraryName \"$SourceFile\" | \\\\${ANSI_NOCOLOR}"
+ # test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}$GHDLScriptDir/$Analyze_Filter ${Filter_Parameters[*]} -i \"$Filter_Indent\"${ANSI_NOCOLOR}"
+ # $GHDL -a ${Analyze_Parameters[@]} ${Parameters[@]} --work=$LibraryName "$SourceFile" 2>&1 | $GHDLScriptDir/$Analyze_Filter ${Filter_Parameters[@]} -i "$Filter_Indent"
+ # local PiplineStatus=("${PIPESTATUS[@]}")
+ # if [[ ${PiplineStatus[0]} -ne 0 ]]; then
+ # echo 1>&2 -e "${COLORED_ERROR} While analyzing '$File'. ExitCode: ${PiplineStatus[0]}${ANSI_NOCOLOR}"
+ # if [[ $CONTINUE_ON_ERROR -eq 1 ]]; then
+ # exit 1;
+ # fi
+ # elif [[ ${PiplineStatus[1]} -ne 0 ]]; then
+ # case $(( ${PiplineStatus[1]} % 4 )) in
+ # TODO: implement CONTINUE_ON_ERROR in cases ...
+ # 3) echo 1>&2 -e "$Filter_Indent${ANSI_RED}Fatal errors detected by filtering script. ExitCode: ${PiplineStatus[1]}${ANSI_NOCOLOR}"; exit 1 ;;
+ # 2) echo 1>&2 -e "$Filter_Indent${ANSI_RED}Errors detected by filtering script. ExitCode: ${PiplineStatus[1]}${ANSI_NOCOLOR}"; exit 1 ;;
+ # 1) echo 1>&2 -e "$Filter_Indent${ANSI_YELLOW}Warnings detected by filtering script.${ANSI_NOCOLOR}" ;;
+ # 0) test $DEBUG -eq 1 && echo 1>&2 -e "$Filter_Indent${ANSI_YELLOW}Warnings detected by filtering script.${ANSI_NOCOLOR}" ;;
+ # esac
+ # fi
+ fi
+}
+
+
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function AnalyzeLibrary( <LibraryName> <SourceDirectory> <LibraryPath> <Files[*]> )${ANSI_NOCOLOR}"
+# AnalyzeLibrary
+# -> LibraryName
+# -> SourceDirectory
+# -> LibraryPath
+# -> Files[*]
+AnalyzeLibrary() {
+ local LibraryName=$1; shift
+ local SourceDirectory=$1; shift
+ local LibraryPath=$1; shift
+ local Files=$@
+
+ echo -e "${ANSI_YELLOW}Analyzing files into library '$LibraryName'...${ANSI_NOCOLOR}"
+
+ for File in $Files; do
+ test $VERBOSE -eq 1 && echo -e " Analyzing '$File'"
+
+ AnalyzeVHDL $LibraryName "$SourceDirectory" "$LibraryPath" "$File"
done
- return 0
}
+test $DEBUG -eq 1 && echo -e " ${ANSI_DARK_GRAY}function Compile( <SourceDirectory> <Libraries> )${ANSI_NOCOLOR}"
+# Compile
+# -> SourceDirectory
+# -> VHDLLibraries
+Compile() {
+ local SourceDirectory=$1
+ local VHDLLibraries=$2
+
+ for VHDLLibrary in $VHDLLibraries; do
+ local LibraryName="${VHDLLibrary}_LibraryName"; local LibraryName=${!LibraryName}
+ local LibraryPath="${VHDLLibrary}_LibraryPath"; local LibraryPath=${!LibraryPath}
+ local VHDLVersion="${VHDLLibrary}_VHDLVersion"; local VHDLVersion=${!VHDLVersion}
+ local Files="${VHDLLibrary}_Files[*]"; local Files=${!Files}
+
+ echo -e "${ANSI_LIGHT_CYAN}Analyzing library '$LibraryName'...${ANSI_NOCOLOR}"
+
+ CreateVHDLLibrary $LibraryName $LibraryName $VHDLVersion
+ AnalyzeLibrary $LibraryName "$SourceDirectory" "$LibraryPath" "$Files"
+ done
+}