|
2 | 2 | # disable _this_ implicit rule |
3 | 3 | %.c: %.y |
4 | 4 |
|
5 | | -%.cc: %.y |
6 | | - mkdir -p bisontmp ; \ |
7 | | - rm -f bisontmp/* ; \ |
8 | | - cd bisontmp ; \ |
9 | | - x=`$(YACC) $(YFLAGS) -o $(notdir $@) ../$< 2>&1` ; \ |
10 | | - if [[ "$<" == "src/parser.y" ]]; then \ |
11 | | - # patch parser.y file, if older version of bison is used. Since 3.3.2, synatx changed. \ |
12 | | - if [[ "$$x" =~ "error: %define variable 'api.parser.class' is not used" ]]; then \ |
13 | | - # push and pop is necessary, as GNU patch does not accept ../ as file paths \ |
14 | | - pushd . && cd ../ && patch $< < src/parser.y_apiparserclass.patch && popd; \ |
15 | | - x=`$(YACC) $(YFLAGS) -o $(notdir $@) ../$< 2>&1` ; \ |
16 | | - fi; \ |
17 | | - fi; \ |
18 | | - r=$$? ; \ |
19 | | - printf "$$x\n" ; \ |
20 | | - if [ "$$r" != 0 ]; then \ |
21 | | - echo Bison exit status: $$r ; \ |
22 | | - cd ..; \ |
23 | | - rm -rf bisontmp; \ |
24 | | - exit 1;\ |
25 | | - fi ; \ |
26 | | - y=`echo $$x | grep -v conflict` ; \ |
27 | | - r=$$? ; \ |
28 | | - if [ "$$r" != 0 ]; then \ |
29 | | - cd ..; rm -rf bisontmp; exit 2; fi ; \ |
30 | | - for i in *; do cmp $$i ../$(dir $@)/$$i; if [ "$$?" != 0 ]; then echo copying $$i; cp $$i ../$(dir $@)$$i; fi; done ; \ |
31 | | - touch ../$@; \ |
32 | | - cd ..; \ |
33 | | - rm -rf bisontmp; |
34 | | - |
35 | 5 | %.c: %.l |
36 | 6 |
|
37 | 7 | %.cc: %.l |
38 | 8 | $(LEX) -o $@ $(LFAGS) $< |
| 9 | + |
| 10 | +%.cc: %.y |
| 11 | + $(call bold,>>> Creating parser via bison ...) |
| 12 | + # create a new temporary directory |
| 13 | + $(eval tmpdir := $(shell mktemp -d 2>/dev/null || mktemp -d -t 'gapc_XXXXXXXX')) |
| 14 | + # copy input file into temporary directory |
| 15 | + cp $< $(tmpdir)/ |
| 16 | + # use bison to generate parser source files |
| 17 | + # we have a breaking change since Bison 3.3.2, which only effects src/parser.y |
| 18 | + # if first bison attempt fails, we will try to apply a patch to the input in the tmpdir and rerun the code generation |
| 19 | + $(YACC) $(YFLAGS) -o $(tmpdir)/$(notdir $@) $(tmpdir)/$(notdir $<) 2>&1 \ |
| 20 | + || (echo "failed to generate parser, trying to patch input .y file..." && (patch $(tmpdir)/$(notdir $<) < $<_apiparserclass.patch && $(YACC) $(YFLAGS) -o $(tmpdir)/$(notdir $@) $(tmpdir)/$(notdir $<) 2>&1)) \ |
| 21 | + || (echo "failed to generate parser, trying another patch on input .y file..." && (patch $(tmpdir)/$(notdir $<) < $<_osx.patch && $(YACC) $(YFLAGS) -o $(tmpdir)/$(notdir $@) $(tmpdir)/$(notdir $<) 2>&1)) |
| 22 | + # remove source file from temporary directiry |
| 23 | + rm $(tmpdir)/$(notdir $<) |
| 24 | + # copy all generated files into working directory |
| 25 | + cp $(tmpdir)/* $(dir $@) |
0 commit comments