cmake/Utilities/Scripts/regenerate-lexers.bash

58 lines
1.8 KiB
Bash
Raw Normal View History

2018-01-26 17:06:56 +01:00
#!/usr/bin/env bash
set -e
2018-08-09 18:06:22 +02:00
forced=1
if [[ "${1}" = "make" ]]; then
forced=0
fi
2018-01-26 17:06:56 +01:00
pushd "${BASH_SOURCE%/*}/../../Source/LexerParser" > /dev/null
2021-09-14 00:13:48 +02:00
extra_args_CommandArgument="--never-interactive --batch"
2018-01-26 17:06:56 +01:00
for lexer in \
CommandArgument \
2020-02-01 23:06:01 +01:00
CTestResourceGroups \
2018-01-26 17:06:56 +01:00
DependsJava \
Expr \
2020-08-30 11:54:41 +02:00
Fortran \
GccDepfile
2018-01-26 17:06:56 +01:00
do
2018-08-09 18:06:22 +02:00
cxx_file=cm${lexer}Lexer.cxx
h_file=cm${lexer}Lexer.h
in_file=cm${lexer}Lexer.in.l
if [[ (${in_file} -nt ${cxx_file}) || (${in_file} -nt ${h_file}) || (${forced} -gt 0) ]]; then
2021-09-14 00:13:48 +02:00
extra_args=`eval echo \\${extra_args_\${lexer}}`
2018-01-26 17:06:56 +01:00
echo "Generating Lexer ${lexer}"
2021-09-14 00:13:48 +02:00
flex --nounistd ${extra_args} -DFLEXINT_H --noline --header-file=${h_file} -o${cxx_file} ${in_file}
2018-08-09 18:06:22 +02:00
sed -i 's/\s*$//' ${h_file} ${cxx_file} # remove trailing whitespaces
sed -i '${/^$/d;}' ${h_file} ${cxx_file} # remove blank line at the end
sed -i '1i#include "cmStandardLexer.h"' ${cxx_file} # add cmStandardLexer.h include
else
echo "Skipped generating Lexer ${lexer}"
fi
2018-01-26 17:06:56 +01:00
done
# these lexers (at the moment only the ListFileLexer) are compiled as C and do not generate a header
for lexer in ListFile
do
2018-08-09 18:06:22 +02:00
c_file=cm${lexer}Lexer.c
in_file=cm${lexer}Lexer.in.l
if [[ (${in_file} -nt ${c_file}) || (${forced} -gt 0) ]]; then
echo "Generating Lexer ${lexer}"
flex --nounistd -DFLEXINT_H --noline -o${c_file} ${in_file}
sed -i 's/\s*$//' ${c_file} # remove trailing whitespaces
sed -i '${/^$/d;}' ${c_file} # remove blank line at the end
sed -i '1i#include "cmStandardLexer.h"' ${c_file} # add cmStandardLexer.h include
else
echo "Skipped generating Lexer ${lexer}"
fi
2018-01-26 17:06:56 +01:00
done
popd > /dev/null