Skip to content
Snippets Groups Projects
Commit 508277d0 authored by Mark OLESEN's avatar Mark OLESEN Committed by Andrew Heather
Browse files

COMFIG: update flex make rules to use '-f' for C-code as well

- add additional rule (ending '.ll') for the combination of
  flex for C-code but compiling the result as C++.
  This can be needed for re-entrant parsers.

- update bison rule to handle renaming of skeleton files.
  Use a wrap-bison script to manage this.
parent 54eab4f2
Branches
Tags
No related merge requests found
SUFFIXES += .y .Y
SUFFIXES += .Y .y .yy
ytoo = $E $(call QUIET_MESSAGE,bison,$(<F)) \
$(WM_SCHEDULER) bison -v -d -y $< $(AND) \
......@@ -11,3 +11,8 @@ Ytoo = $E $(call QUIET_MESSAGE,bison,$(<F)) \
mv y.tab.c $(@D)/$(<F).C $(AND) \
mv y.tab.h $(@D)/$(<F).H $(AND) \
$(CC) $(c++FLAGS) -c $(@D)/$(<F).C -o $@
yytoo = $E $(call QUIET_MESSAGE,bison,$(<F)) \
$(WM_SCHEDULER) $(WM_SCRIPTS)/wrap-bison \
-input=$< -output=$(@D)/$(*F).tab.cc -v -d $(AND) \
$(cc) $(cFLAGS) -c $(@D)/$(*F).tab.cc -o $@
SUFFIXES += .l
ltoo = $E $(call QUIET_MESSAGE,flex,$(<F)) \
$(WM_SCHEDULER) flex -o $(@D)/$(<F).c $< $(AND) \
$(cc) $(cFLAGS) -c $(@D)/$(<F).c -o $@
$(WM_SCHEDULER) flex -f -o $(@D)/$(<F).c $< $(AND) \
$(cc) $(cFLAGS) -c $(@D)/$(<F).c -o $@
SUFFIXES += .L
SUFFIXES += .L .ll
# Use C++-aware Flex
Ltoo = $E $(call QUIET_MESSAGE,flex++,$(<F)) \
$(WM_SCHEDULER) flex -+ -o$(@D)/$(<F).C -f $< $(AND) \
$(WM_SCHEDULER) flex -+ -f -o $(@D)/$(<F).C $< $(AND) \
$(CC) $(c++FLAGS) $(c++LESSWARN) -c $(@D)/$(<F).C -o $@
# Use regular (C) Flex, but compile result as C++
lltoo = $E $(call QUIET_MESSAGE,flex,$(<F)) \
$(WM_SCHEDULER) flex -f -o $(@D)/$(<F).cc $< $(AND) \
$(CC) $(c++FLAGS) $(c++LESSWARN) -c $(@D)/$(<F).cc -o $@
#!/bin/sh
#------------------------------------------------------------------------------
# ========= |
# \\ / F ield | OpenFOAM: The Open Source CFD Toolbox
# \\ / O peration |
# \\ / A nd | Copyright (C) 2019 OpenCFD Ltd.
# \\/ M anipulation |
#-------------------------------------------------------------------------------
# License
# This file is part of OpenFOAM, licensed under GNU General Public License
# <http://www.gnu.org/licenses/>.
#
# Script
# wrap-bison
#
# Usage
# wrap-bison -input=*.yy -output=*.cc [bison-options]
#
# Description
# A wrapper to handle renaming/relocation of bison-generated files.
#
# When bison is used, it generates several output files.
# The names of the regular output files may not match our expectations.
# The skeleton files are always named the same, which can cause
# file-name collisions in some cases.
#
# Input:
# - myFile.yy
#
# Output: <myFile.yy>
# - myFile.tab.hh
# - myFile.tab.cc
# - location.hh
# - position.hh
# - stack.hh
#
# Approach
# - call bison from within a local Make/some-name/ directory.
# - use sed to modify the #include contents and rename files.
# From location.hh -> myFile.location.hh
# - place generated *.hh files directly into lnInclude/
# - place generated *.cc file into the build/ directory
#
# Note
# General idea lifted from swak
#------------------------------------------------------------------------------
usage() {
exec 1>&2
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
cat<<USAGE
Usage: ${0##*/} -file=<name> [bison-options]
options:
-input=NAME Perform the renaming actions
-output=NAME Perform the renaming actions
-h, -help Print the usage
A bison wrapper to handle renaming of the skeleton files
USAGE
exit 1
}
# The file extensions used
extCode="cc"
extHead="hh"
#------------------------------------------------------------------------------
# Parse arguments and options
#------------------------------------------------------------------------------
# bison -input=... -output=...
unset inputFile outputFile
while [ "$#" -gt 0 ]
do
case "$1" in
(-h | -help*) usage ;;
(-input=*) inputFile="${1#*=}" ;;
(-output=*) outputFile="${1#*=}" ;;
(*) break ;;
esac
shift
done
# No rename action supplied? Juet execute bison directly.
if [ -z "$inputFile" ]
then
bison $*
exit $?
fi
#------------------------------------------------------------------------------
# Renaming requested
# Need lnInclude/ directory
[ -d lnInclude ] || mkdir lnInclude 2>/dev/null || {
echo "Cannot continue without an lnInclude directory" 1>&2
pwd -L
exit 1
}
# Get a baseName (stem) for the output
baseName="${inputFile##*/}"
baseName="${baseName%.*}"
# Fallback for output
if [ -z "$outputFile" ]
then
outputFile="$(dirname ${inputFile})/${baseName}.$extCode"
fi
# Run bison in temporary directory (keeps files together)
cwd="$(pwd -L)"
tmpDir="Make/bisonWrapper-$baseName"
rm -rf "$tmpDir" 2>/dev/null
mkdir "$tmpDir" 2>/dev/null
cd "$tmpDir" || exit 1
rc=1
# DO WE WANT THIS?
# trap 'cd $cwd; rm -f $tmpDir 2>/dev/null; exit $rc' EXIT TERM INT
bison "$@" "../../$inputFile"
rc=$?
cd "../.." || exit 1
if [ "$rc" -ne 0 ]
then
rm -rf $tmpDir 2>/dev/null
exit "$rc" # Exit with bison return code
fi
# Check for/remove .tab. tag?
unset untabFilter
# withTab=$/include *"stack/s/"/"'"${baseName}."'/;' \
hasTab="${outputFile##*/}"
hasTab="${hasTab%.*}"
if [ "$hasTab" = "${hasTab%.tab}" ]
then
untab='/^#.*".*\.tab\./s/\.tab\././'
fi
# Filter include names to generate new files
# "$1" = input
# "$2" = output
filterRename()
{
if [ -f "$1" ] && [ -n "$2" ]
then
sed \
-e '/include *"location/s/"/"'"${baseName}."'/;' \
-e '/include *"position/s/"/"'"${baseName}."'/;' \
-e '/include *"stack/s/"/"'"${baseName}."'/;' \
-e "$untab;" \
"$1" >| "$2"
fi
}
# Boilerplate -> lnInclude/ directory with new name
for file in position location stack
do
filterRename \
"${tmpDir}/${file}.$extHead" \
"lnInclude/${baseName}.${file}.$extHead"
done
# Header -> lnInclude/ directory, possibly with .tab.hh to .hh
filterRename \
"${tmpDir}/${baseName}.tab.$extHead" \
"lnInclude/${baseName}${untab:-.tab}.$extHead"
# Code -> build directory, possibly with .tab.hh to .hh
filterRename \
"${tmpDir}/${baseName}.tab.$extCode" \
"${outputFile}"
rm -rf $tmpDir 2>/dev/null
exit "$rc" # Exit with bison return code
#------------------------------------------------------------------------------
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment