#!/bin/bash #------------------------------------------------------------------------------ # ========= | # \\ / F ield | OpenFOAM: The Open Source CFD Toolbox # \\ / O peration | # \\ / A nd | www.openfoam.com # \\/ M anipulation | #------------------------------------------------------------------------------- # Copyright (C) 2019-2021 OpenCFD Ltd. #------------------------------------------------------------------------------- # License # This file is part of OpenFOAM, distributed under GPL-3.0-or-later. # # Script # wrap-lemon # # Usage # wrap-lemon [options] [lemon options/args] # # Description # A wrapper to use lemon compiled with OpenFOAM with the appropriate # parser template. # # When called with m4 wrapping, it sets the m4 -I include to have # the following: # - the directory of the parser. # - include/ in the top-level source tree of the current target # (eg, src/finiteVolume/include/ when compiling libfiniteVolume) # - include/ from OpenFOAM # #------------------------------------------------------------------------------ binDir="${WMAKE_BIN:-$WM_PROJECT_DIR/platforms/tools/$WM_ARCH$WM_COMPILER}" etcDir="${WM_DIR:-$WM_PROJECT_DIR/wmake}/etc" # Executable and skeleton locations lemon="${binDir}/lemon" skel="-T${etcDir}/lempar.c" printHelp() { cat<&2 m4 $m4Flags "$parser"; exitCode=$? else echo "Nothing to do - not using m4" 2>/dev/null fi [ "$exitCode" -eq 0 ] || echo "m4 failed" 2>/dev/null exit "$exitCode" # Done fi #------------------------------------------------------------------------------ unset tmpFile tmpDir if [ -n "$optHeader" ] then ## echo "${0##*/} : generate header" 1>&2 # Drop last argument (the parser input file) set -- "${@:1:${#}-1}" # 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 trap 'rm -rf $tmpDir; exit $exitCode' EXIT TERM INT if [ "$usingM4" = true ] then # Using m4 - redirect to a temporary file tmpFile="$tmpDir/${parser##*/}" tmpFile="${tmpFile%.*}$extParser" # Eg, from .lyy-m4 -> .lyy if m4 $m4Flags "$parser" > "$tmpFile" && [ -f "$tmpFile" ] then parser="$tmpFile" else echo "m4 stage failed on $parser" 2>/dev/null exitCode=1 fi fi if [ "$exitCode" -eq 0 ] then "$lemon" "$skel" "-d$tmpDir" "$@" $parserFlags "$parser" exitCode=$? fi if [ "$exitCode" -eq 0 ] then 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 fi elif [ "$usingM4" = true ] then ## echo "${0##*/} : generate code (with m4 filtering)" 1>&2 # Drop last argument (the parser input file) set -- "${@:1:${#}-1}" # Filter via m4 if [ -n "$outputDir" ] then tmpFile="$outputDir/${parser##*/}" else tmpFile="${parser}" fi tmpFile="${tmpFile%.*}$extParser" # Eg, from .lyy-m4 -> .lyy if [ -n "$optRemoveTmp" ] then trap 'rm -f $tmpFile; exit $exitCode' EXIT TERM INT fi if m4 $m4Flags "$parser" > "$tmpFile" && [ -f "$tmpFile" ] then "$lemon" "$skel" "$@" $parserFlags "$tmpFile" exitCode=$? else echo "m4 stage failed on $parser" 2>/dev/null exitCode=1 fi if [ -z "$optRemoveTmp" ] then echo 2>/dev/null echo "Retaining intermediate: $tmpFile" 2>/dev/null fi else # No special handling ## echo "${0##*/} : generate code" 1>&2 "$lemon" "$skel" "$@" exitCode=$? fi exit "$exitCode" # Exit with lemon return code #------------------------------------------------------------------------------