1#! /bin/bash
2#
3#
4# Copyright (c) 2010 Apple Inc. All rights reserved.
5#
6# @APPLE_LICENSE_HEADER_START@
7#
8# Redistribution and use in source and binary forms, with or without
9# modification, are permitted provided that the following conditions
10# are met:
11#
12# 1.  Redistributions of source code must retain the above copyright
13#     notice, this list of conditions and the following disclaimer.
14# 2.  Redistributions in binary form must reproduce the above copyright
15#     notice, this list of conditions and the following disclaimer in the
16#     documentation and/or other materials provided with the distribution.
17# 3.  Neither the name of Apple Inc. ("Apple") nor the names of its
18#     contributors may be used to endorse or promote products derived from
19#     this software without specific prior written permission.
20#
21# THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
22# EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
23# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
24# DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
25# DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
26# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
27# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
28# ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
29# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
30# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31#
32# @APPLE_LICENSE_HEADER_END@
33#
34#
35
36set -e
37
38# Turn foo.[ly] into foo.h
39outfile_name()
40{
41    local input=$(basename "$1")
42    local extension="$2"
43    echo ${input%.[ly]}.${extension}
44}
45
46# Turn fool.y into fooyy
47parser_prefix()
48{
49    local input=$(basename "$1")
50    echo ${input%[ly].[ly]}yy
51}
52
53run()
54{
55    local status
56
57    echo "$@"
58    xcrun "$@"
59}
60
61OUTDIR="$(dirname ${SCRIPT_OUTPUT_FILE_0})"
62
63LEXER="$(basename ${SCRIPT_INPUT_FILE_0})"
64PARSER="$(basename ${SCRIPT_INPUT_FILE_1})"
65PREFIX="$(parser_prefix ${PARSER})"
66
67mkdir -p "$OUTDIR"
68cd "$OUTDIR"
69
70run flex -P${PREFIX} -o $(outfile_name ${LEXER} c) ${SCRIPT_INPUT_FILE_0}
71run bison -v -d -p ${PREFIX} -o $(outfile_name ${PARSER} c) ${SCRIPT_INPUT_FILE_1}
72
73echo $LEXER \-\> $(outfile_name ${LEXER} c) $(outfile_name ${LEXER} h)
74echo $PARSER \-\> $(outfile_name ${PARSER} c) $(outfile_name ${PARSER} h)
75