mirror of
https://develop.openfoam.com/Development/openfoam.git
synced 2025-11-28 03:28:01 +00:00
COMP: update make rules for lemon, add helper infrastructure for ragel
This commit is contained in:
committed by
Andrew Heather
parent
f7528a2ac5
commit
4a6cd8f194
@ -1,9 +1,9 @@
|
|||||||
SUFFIXES += .ly .lyy
|
SUFFIXES += .ly .lyy
|
||||||
|
|
||||||
lytoo = $E $(call QUIET_MESSAGE,lemon,$(<F)) \
|
lytoo = $E $(call QUIET_MESSAGE,lemon,$(<F)) \
|
||||||
$(WM_SCHEDULER) $(WM_SCRIPTS)/wrap-lemon -q $< $(AND) \
|
$(WM_SCHEDULER) $(WM_SCRIPTS)/wrap-lemon -d$(@D) $< $(AND) \
|
||||||
$(cc) $(cFLAGS) -c $(@D)/$(<F).c -o $@
|
$(cc) $(cFLAGS) -c $(@D)/$(*F).c -o $@
|
||||||
|
|
||||||
lyytoo = $E $(call QUIET_MESSAGE,lemon,$(<F)) \
|
lyytoo = $E $(call QUIET_MESSAGE,lemon,$(<F)) \
|
||||||
$(WM_SCHEDULER) $(WM_SCRIPTS)/wrap-lemon -q $< $(AND) \
|
$(WM_SCHEDULER) $(WM_SCRIPTS)/wrap-lemon -d$(@D) -ecc $< $(AND) \
|
||||||
$(CC) $(c++FLAGS) -c $(@D)/$(<F).cc -o $@
|
$(CC) $(c++FLAGS) -c $(@D)/$(*F).cc -o $@
|
||||||
|
|||||||
@ -8,7 +8,7 @@ include $(GENERAL_RULES)/flex++
|
|||||||
## include $(GENERAL_RULES)/byacc
|
## include $(GENERAL_RULES)/byacc
|
||||||
## include $(GENERAL_RULES)/btyacc++
|
## include $(GENERAL_RULES)/btyacc++
|
||||||
include $(GENERAL_RULES)/bison
|
include $(GENERAL_RULES)/bison
|
||||||
## include $(GENERAL_RULES)/lemon
|
include $(GENERAL_RULES)/lemon
|
||||||
## include $(GENERAL_RULES)/ragel
|
## include $(GENERAL_RULES)/ragel
|
||||||
include $(GENERAL_RULES)/moc
|
include $(GENERAL_RULES)/moc
|
||||||
include $(GENERAL_RULES)/X
|
include $(GENERAL_RULES)/X
|
||||||
|
|||||||
102
wmake/scripts/makeParser
Executable file
102
wmake/scripts/makeParser
Executable file
@ -0,0 +1,102 @@
|
|||||||
|
#!/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
|
||||||
|
# makeParser
|
||||||
|
#
|
||||||
|
# Description
|
||||||
|
# Pregenerate ragel code and/or lemon parser headers
|
||||||
|
#
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
usage() {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
cat<<USAGE
|
||||||
|
|
||||||
|
Usage: ${0##*/} [options]
|
||||||
|
|
||||||
|
options:
|
||||||
|
-parser=FILE Generate lemon parser header
|
||||||
|
-scanner=FILE Generate ragel scanner code
|
||||||
|
-remove Remove generated code
|
||||||
|
-h, -help Print the usage
|
||||||
|
|
||||||
|
Pregenerate ragel code and/or lemon parser headers
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# Parse arguments and options
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
unset parser scanner optRemove
|
||||||
|
while [ "$#" -gt 0 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
(-h | -help*) usage ;;
|
||||||
|
|
||||||
|
(-parser=*) parser="${1#*=}" ;;
|
||||||
|
(-scanner=*) scanner="${1#*=}" ;;
|
||||||
|
(-remove) optRemove=true ;;
|
||||||
|
|
||||||
|
(*) break ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# Remove file, with feedback. $1 = file, $2 = message
|
||||||
|
removeFile() {
|
||||||
|
if test -f "$1" && rm -f "$1" 2>/dev/null
|
||||||
|
then
|
||||||
|
echo "Removed generated $2 file"
|
||||||
|
else
|
||||||
|
echo "No generated $2 file to remove"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
case "$scanner" in
|
||||||
|
(*.rl)
|
||||||
|
output="${scanner%.*}.cc"
|
||||||
|
|
||||||
|
if [ "$optRemove" = true ]
|
||||||
|
then
|
||||||
|
removeFile "$output" "ragel scanner"
|
||||||
|
elif command -v ragel >/dev/null
|
||||||
|
then
|
||||||
|
echo "Generating ragel scanner"
|
||||||
|
ragel -G2 -o "$output" "$scanner"
|
||||||
|
else
|
||||||
|
echo "No ragel, leaving scanner intact"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
case "$parser" in
|
||||||
|
(*.ly | *.lyy)
|
||||||
|
output="${parser%.*}.h"
|
||||||
|
|
||||||
|
if [ "$optRemove" = true ]
|
||||||
|
then
|
||||||
|
removeFile "$output" "lemon header"
|
||||||
|
else
|
||||||
|
echo "Generating lemon parser header"
|
||||||
|
"$WM_PROJECT_DIR/wmake/scripts/wrap-lemon" -header "$parser"
|
||||||
|
fi
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
@ -49,20 +49,20 @@ usage() {
|
|||||||
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
cat<<USAGE
|
cat<<USAGE
|
||||||
|
|
||||||
Usage: ${0##*/} -file=<name> [bison-options]
|
Usage: ${0##*/} [options] [bison args/options]
|
||||||
|
|
||||||
options:
|
options:
|
||||||
-input=NAME Perform the renaming actions
|
-input=NAME Perform the renaming actions
|
||||||
-output=NAME Perform the renaming actions
|
-output=NAME Perform the renaming actions
|
||||||
-h, -help Print the usage
|
-h, -help Print the usage
|
||||||
|
|
||||||
A bison wrapper to handle renaming of the skeleton files
|
A bison wrapper with renaming of skeleton files
|
||||||
|
|
||||||
USAGE
|
USAGE
|
||||||
exit 1
|
exit 1
|
||||||
}
|
}
|
||||||
|
|
||||||
# The file extensions used
|
# File extensions used
|
||||||
extCode="cc"
|
extCode="cc"
|
||||||
extHead="hh"
|
extHead="hh"
|
||||||
|
|
||||||
@ -70,15 +70,15 @@ extHead="hh"
|
|||||||
# Parse arguments and options
|
# Parse arguments and options
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
# bison -input=... -output=...
|
# wrap-bison -input=... -output=...
|
||||||
unset inputFile outputFile
|
unset inputFile outputFile
|
||||||
while [ "$#" -gt 0 ]
|
while [ "$#" -gt 0 ]
|
||||||
do
|
do
|
||||||
case "$1" in
|
case "$1" in
|
||||||
(-h | -help*) usage ;;
|
(-h | -help*) usage ;;
|
||||||
|
|
||||||
(-input=*) inputFile="${1#*=}" ;;
|
(-input=*) inputFile="${1#*=}" ;;
|
||||||
(-output=*) outputFile="${1#*=}" ;;
|
(-output=*) outputFile="${1#*=}" ;;
|
||||||
|
|
||||||
(*) break ;;
|
(*) break ;;
|
||||||
esac
|
esac
|
||||||
@ -112,7 +112,7 @@ then
|
|||||||
outputFile="$(dirname ${inputFile})/${baseName}.$extCode"
|
outputFile="$(dirname ${inputFile})/${baseName}.$extCode"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Run bison in temporary directory (keeps files together)
|
# Execute in a temporary directory (keeps files together)
|
||||||
cwd="$(pwd -L)"
|
cwd="$(pwd -L)"
|
||||||
tmpDir="Make/bisonWrapper-$baseName"
|
tmpDir="Make/bisonWrapper-$baseName"
|
||||||
rm -rf "$tmpDir" 2>/dev/null
|
rm -rf "$tmpDir" 2>/dev/null
|
||||||
@ -131,7 +131,7 @@ cd "../.." || exit 1
|
|||||||
|
|
||||||
if [ "$rc" -ne 0 ]
|
if [ "$rc" -ne 0 ]
|
||||||
then
|
then
|
||||||
rm -rf $tmpDir 2>/dev/null
|
rm -rf "$tmpDir" 2>/dev/null
|
||||||
exit "$rc" # Exit with bison return code
|
exit "$rc" # Exit with bison return code
|
||||||
fi
|
fi
|
||||||
|
|
||||||
@ -185,7 +185,7 @@ filterRename \
|
|||||||
"${outputFile}"
|
"${outputFile}"
|
||||||
|
|
||||||
|
|
||||||
rm -rf $tmpDir 2>/dev/null
|
rm -rf "$tmpDir" 2>/dev/null
|
||||||
exit "$rc" # Exit with bison return code
|
exit "$rc" # Exit with bison return code
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
@ -25,10 +25,81 @@
|
|||||||
binDir="${WMAKE_BIN:-$WM_PROJECT_DIR/wmake/platforms/$WM_ARCH$WM_COMPILER}"
|
binDir="${WMAKE_BIN:-$WM_PROJECT_DIR/wmake/platforms/$WM_ARCH$WM_COMPILER}"
|
||||||
etcDir="${WM_DIR:-$WM_PROJECT_DIR/wmake}/etc"
|
etcDir="${WM_DIR:-$WM_PROJECT_DIR/wmake}/etc"
|
||||||
|
|
||||||
# Or another location
|
# Executable and skeleton locations
|
||||||
"$binDir/lemon" "-T${etcDir}/lempar.c" $*
|
lemon="$binDir/lemon"
|
||||||
|
skel="-T${etcDir}/lempar.c"
|
||||||
|
|
||||||
|
usage() {
|
||||||
|
exec 1>&2
|
||||||
|
while [ "$#" -ge 1 ]; do echo "$1"; shift; done
|
||||||
|
cat<<USAGE
|
||||||
|
|
||||||
|
Usage: ${0##*/} [options] [lemon args/options]
|
||||||
|
|
||||||
|
options:
|
||||||
|
-header Generate header only, suppressing other output
|
||||||
|
-h, -help Print the usage
|
||||||
|
|
||||||
|
A lemon wrapper using predefined executable and skeleton locations
|
||||||
|
|
||||||
|
USAGE
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
# Parse arguments and options
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# wrap-lemon -header-only
|
||||||
|
unset optHeader
|
||||||
|
while [ "$#" -gt 0 ]
|
||||||
|
do
|
||||||
|
case "$1" in
|
||||||
|
(-h | -help*) usage ;;
|
||||||
|
|
||||||
|
(-header*) optHeader=true ;;
|
||||||
|
|
||||||
|
(*) break ;;
|
||||||
|
esac
|
||||||
|
shift
|
||||||
|
done
|
||||||
|
|
||||||
|
|
||||||
|
#------------------------------------------------------------------------------
|
||||||
|
|
||||||
|
# No special handling
|
||||||
|
if [ -z "$optHeader" ]
|
||||||
|
then
|
||||||
|
"$lemon" "$skel" $*
|
||||||
|
exit $?
|
||||||
|
fi
|
||||||
|
|
||||||
|
|
||||||
|
# Header only, which means we create a temp directory for the output
|
||||||
|
tmpDir="lemonWrapper-$$"
|
||||||
|
rm -rf "$tmpDir" 2>/dev/null
|
||||||
|
mkdir "$tmpDir" 2>/dev/null
|
||||||
|
|
||||||
|
# DO WE WANT THIS?
|
||||||
|
# trap 'rm -f $tmpDir 2>/dev/null; exit $rc' EXIT TERM INT
|
||||||
|
|
||||||
|
"$lemon" "$skel" "-d$tmpDir" $*
|
||||||
rc=$?
|
rc=$?
|
||||||
|
|
||||||
|
for src in "$tmpDir"/*.h
|
||||||
|
do
|
||||||
|
dst="${src##*/}"
|
||||||
|
if [ -f "$src" ]
|
||||||
|
then
|
||||||
|
if ! cmp "$src" "$dst" 2>/dev/null
|
||||||
|
then
|
||||||
|
mv "$src" "$dst"
|
||||||
|
echo "Updating $dst" 1>&2
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
done
|
||||||
|
|
||||||
|
rm -rf "$tmpDir" 2>/dev/null
|
||||||
exit "$rc" # Exit with lemon return code
|
exit "$rc" # Exit with lemon return code
|
||||||
|
|
||||||
#------------------------------------------------------------------------------
|
#------------------------------------------------------------------------------
|
||||||
|
|||||||
Reference in New Issue
Block a user