How to do autoconf check to check if it is possible to pass -R to flex?

Obviously gnuflex on MacOS and Linux requires the -R or %option reentrant generate a re-scanner, but on FreeBSD it by default creates a reentrant scanner and throws an error if -R or %option reentrant , I would like autoconf automatically checked if gnuflex the -R option and, if so, provide it. I don’t understand how I can do an autoconf test for this. I suppose I should run gnuflex in a null file with -R and check the result code and set some kind of variable and then add it to the FLEX options, but I'm not sure. Any ideas?

+4
source share
2 answers

I assume that you installed $FLEX , perhaps with a combination of AC_ARG_VAR and AC_PATH_PROG .

 AC_CACHE_CHECK([whether $FLEX supports -R], [my_cv_prog_flex_dash_r], [mv_cv_prog_flex_dash_r=no echo '%%' | "$FLEX" -R && my_cv_prog_flex_dash_r=yes rm -f lex.yy.c]) AS_IF([test $my_cv_prog_flex_dash_r = yes], [FLEX="$FLEX -R"]) 
+2
source

Here is what I ended up doing. It is more readable than @Jack Kelly, and it does not create a side variable ...

 ## Determine if we can use flex -R if eval "echo %% | $FLEX -R -t > /dev/null 2>&1" then AC_MSG_NOTICE([$FLEX supports -R]) else AC_MSG_ERROR([$FLEX does not support -R. Please get a modern version of gnu flex]) fi 
+1
source

All Articles