Debian Codegraph @

bin/genparser

raw
1 #!/bin/sh
2 #
3 # Copyright by The HDF Group.
4 # Copyright by the Board of Trustees of the University of Illinois.
5 # All rights reserved.
6 #
7 # This file is part of HDF. The full HDF copyright notice, including
8 # terms governing use, modification, and redistribution, is contained in
9 # the COPYING file, which can be found at the root of the source code
10 # distribution tree, or in https://support.hdfgroup.org/ftp/HDF/releases/.
11 # If you do not have access to either file, you may request a copy from
12 # [email protected].
13 #
14
15 # This script runs flex/lex and bison/yacc to generate parser code for
16 # the mfhdf code.
17 #
18 # NOTE CAREFULLY!
19 #
20 # There is NO dependency in either the autotools or CMake to regenerate
21 # the parser code. If you modify ncgen.l or ncgen.y, you will need to run
22 # this script manually on a system with a suitable lexer and parser generator.
23 #
24 # IMPORTANT OS X NOTE
25 #
26 # If you are using OS X, you will probably not have flex or bison
27 # installed. In addition, even if you do have bison installed, the bison
28 # version you have installed may also have a bug that makes it unable to
29 # process our input files.
30 #
31 # The easiest way to fix this is to install everything via Homebrew:
32 #
33 # http://brew.sh/
34 #
35 # After you install the base packages, install flex/bison.
36 #
37 # brew install flex
38 # brew install bison
39 #
40 # END IMPORTANT OS X NOTE
41 #
42 # If you want to use a particular version of flex or bison, the paths
43 # to each tool can be overridden using the following environment
44 # variables:
45 #
46 # HDF_FLEX
47 # HDF_BISON
48 #
49 # This script takes one option:
50 #
51 # -v
52 #
53 # This emits some extra information, mainly tool versions.
54
55 echo
56 echo "***************************************"
57 echo "* HDF4 NetCDF parser generator script *"
58 echo "***************************************"
59 echo
60
61 # Default is not verbose output
62 verbose=false
63
64 optspec=":hpv-"
65 while getopts "$optspec" optchar; do
66 case "${optchar}" in
67 h)
68 echo "usage: $0 [OPTIONS] /path/to/ncgen/directory"
69 echo
70 echo " -h Print this help message."
71 echo
72 echo " -v Show more verbose output."
73 echo
74 echo " NOTE: Each tool can be set via an environment variable."
75 echo " These are documented inside this script."
76 echo
77 exit 0
78 ;;
79 v)
80 echo "Setting verbosity: high"
81 echo
82 verbose=true
83 ;;
84 *)
85 if [ "$OPTERR" != 1 ] || [ "${optspec:0:1}" = ":" ]; then
86 echo "Non-option argument: '-${OPTARG}'" >&2
87 fi
88 ;;
89 esac
90 done
91
92 # Get the path to the ncgen directory
93 shift $(($OPTIND - 1))
94 path_to_ncgen_src=$1
95 if test -z ${path_to_ncgen_src}; then
96 echo "*** ERROR *** - Path to mfhdf/ncgen not set"
97 echo "Please add the path to the mfhdf/ncgen directory as a parameter"
98 echo "See $0 -h for more help."
99 echo
100 exit -1
101 fi
102
103 # If paths to autotools are not specified, use whatever the system
104 # has installed as the default. We use 'which <tool>' to
105 # show exactly what's being used.
106 if test -z ${HDF_BISON}; then
107 HDF_BISON="$(command -v bison)"
108 fi
109 if test -z ${HDF_FLEX}; then
110 HDF_FLEX="$(command -v flex)"
111 fi
112
113 # Make sure that these versions of the tools are in the path
114 BISON_DIR=`dirname ${HDF_BISON}`
115 FLEX_DIR=`dirname ${HDF_FLEX}`
116 PATH=${FLEX_DIR}:${BISON_DIR}:$PATH
117
118 # Run flex and bison
119 # automatically generates mfhdf/ncgen/ncgenyy.c and mfhdf/ncgen/ncgentab.c
120 # Note that, as of Xcode 6.1 (2015), the default bison version on OS X
121 # is old enough to have the circular dependency bug. You'll have
122 # to install a later version of bison. See the OS X note at the top
123 # of this script.
124 echo
125 echo "Generating ncgen parser code (requires yacc/bison):"
126 echo "Generate mfhdf/ncgen/ncgenyy.c from mfhdf/ncgen/ncgen.y"
127 # HDF_BISON is set via the environment or 'command -v bison', above
128 if test -z ${HDF_BISON}; then
129 echo
130 echo "*************************"
131 echo " ERROR - bison not found"
132 echo "*************************"
133 echo "bison is required to generate parser code in mfhdf/ncgen"
134 echo
135 exit 127
136 fi
137 if [ "$verbose" = true ] ; then
138 ${HDF_BISON} --version
139 fi
140 ${HDF_BISON} -o ${path_to_ncgen_src}/ncgentab.c -d ${path_to_ncgen_src}/ncgen.y
141
142 echo
143 echo "Generating ncgen lexer code (requires lex/flex):"
144 echo "Generate mfhdf/ncgen/ncgentab.c from mfhdf/ncgen/ncgen.l"
145 # HDF_FLEX is set via the environment or 'command -v flex', above
146 if test -z ${HDF_FLEX}; then
147 echo
148 echo "************************"
149 echo " ERROR - flex not found"
150 echo "************************"
151 echo "flex is required to generate lexer code in mfhdf/ncgen"
152 echo
153 exit 127
154 fi
155 if [ "$verbose" = true ] ; then
156 ${HDF_FLEX} --version
157 fi
158 ${HDF_FLEX} --nounistd -o ${path_to_ncgen_src}/ncgenyy.c ${path_to_ncgen_src}/ncgen.l
159
160 echo
161 exit 0
162