1/*
2 * NAME
3 *      yacc_many - how to use yacc several times in the same directory
4 *
5 * DESCRIPTION
6 *      This cookbook describes how to use yacc.
7 *      The difference with the "yacc" cookbook is that this cookbook
8 *      allows you to have more that one yacc generated parser in the same
9 *      program, by using the classic sed(1) hack of the output.
10 *
11 *      You will have to add "-d" to the [yacc_flags] variable
12 *      if you want %.h files generated.
13 *
14 *      If a y.output file is constructed, it will be moved to %.list
15 *
16 * RECIPES
17 *      %.c %.h: %.y    applied if -d in [yacc_flags]
18 *      %.c: %.y        applied if -d not in [yacc_flags]
19 *
20 * VARIABLES
21 *      yacc_src        Yacc source files in the current directory.
22 *      dot_src         Source files constructable in the current directory
23 *                      (unioned with existing setting, if necessary).
24 *      dot_obj         Object files constructable in the current directory
25 *                      (unioned with existing setting, if necessary).
26 *      dot_clean       Files which may be removed from the current directory
27 *                      in a clean target.
28 *      dot_lint_obj    Lint object files constructable in the current directory
29 *                      (unioned with existing setting, if necessary).
30 * Copyright (C) 2007 Peter Miller
31 */
32
33#pragma once
34
35#include "c"
36
37if [not [defined yacc]] then
38        yacc = yacc;
39if [not [defined yacc_flags]] then
40        yacc_flags = ;
41yacc_src = [glob *.y];
42cc_src = [stringset [cc_src] - [fromto %.y %.c [yacc_src]]];
43dot_src =
44        [stringset
45                [dot_src] [yacc_src]
46        -
47                [fromto %.y %.c [yacc_src]] [fromto %.y %.s [yacc_src]]
48        ];
49dot_obj = [stringset [dot_obj] [fromto %.y %.o [yacc_src]]];
50dot_clean =
51        [stringset
52                [dot_clean]
53                [fromto %.y %.o [yacc_src]]
54                [fromto %.y %.c [yacc_src]]
55                [fromto %.y %.list [yacc_src]]
56                [fromto %.y %.ln [yacc_src]]
57                [fromto %.y %.s [yacc_src]]
58                y.tab.c y.tab.h y.output
59        ];
60dot_lint_obj = [stringset [dot_lint_obj] [fromto %.y %.ln [yacc_src]]];
61
62
63%.c %.h: %.y
64        if [in -d [yacc_flags]]
65        single-thread y.tab.c y.tab.h y.output
66{
67        if [exists %.list] then
68                rm -f %.list
69                        set clearstat;
70        if [exists y.output] then
71                rm -f y.output
72                        set clearstat;
73        [yacc] [yacc_flags] %.y;
74        sed -e \'s/\[yY\]\[yY\]/%_/g\' y.tab.c > %.c;
75        rm -f y.tab.c;
76        sed -e \'s/\[yY\]\[yY\]/%_/g\' y.tab.h > %.h;
77        rm -f y.tab.h;
78        if [exists y.output] then
79                mv y.output %.list
80                        set clearstat;
81}
82
83%.c: %.y
84        if [not [in -d [yacc_flags]]]
85        single-thread y.tab.c y.output
86{
87        if [exists %.list] then
88                rm -f %.list
89                        set clearstat;
90        if [exists y.output] then
91                rm -f y.output
92                        set clearstat;
93        [yacc] [yacc_flags] %.y;
94        sed -e \'s/\[yY\]\[yY\]/%_/g\' y.tab.c > %.c;
95        rm -f y.tab.c;
96        if [exists y.output] then
97                mv y.output %.list
98                        set clearstat;
99}
100