Permalink
Browse files

use go tool for compilation where possible

Only a single Makefile in the project root has been left.

"make prepare" (resp. all) now bootstraps the peg
command and creates all parsers defined within the
tree.

"make clean" deletes files created by "make prepare"

make prepare needs not necessarily be called, as
dependencies defined in Make.inc would automatically
build peg and leg commands. If another package wants
to use e.g. cmd/leg to generate an LE parser, it could
set up a small Makefile containing the lines:

include $(shell go list -f '{{.Dir}}' github.com/knieriem/peg)/Make.inc
%.leg.go: %.leg $(LEG)
	$(LEG) -switch $<

--HG--
rename : calculator/main.go => cmd/calculator/main.go
rename : leg/leg.peg => cmd/leg/leg.peg
rename : leg/main.go => cmd/leg/main.go
rename : leg/calc.leg => cmd/legcalc/calc.leg
rename : leg/leg.leg => cmd/legleg/leg.leg
rename : main.go => cmd/peg/main.go
rename : peg.peg => cmd/peg/peg.peg
  • Loading branch information...
1 parent 91672c5 commit ee0a62ab8a4c4cff5b24f666c898b7e23b45292a @knieriem committed Apr 20, 2012
View
@@ -1,10 +0,0 @@
-# Copyright 2010 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include $(GOROOT)/src/Make.inc
-GC := $(GC)
-LD := $(LD) -L $(PKGROOT)
-
-%.$(O): %.go
- $(GC) -I $(PKGROOT) $(filter %.go,$^)
View
@@ -0,0 +1,19 @@
+ifeq ($(PEGDIR),)
+PEGDIR := $(subst /Make.inc,,$(lastword $(MAKEFILE_LIST)))
+endif
+PEG=$(PEGDIR)/cmd/peg/peg
+LEG=$(PEGDIR)/cmd/leg/leg
+BOOTSTRAP=$(PEGDIR)/cmd/peg/bootstrap.go
+
+$(PEG): $(BOOTSTRAP)
+ cd $(@D) && GOARCH= GOOS= go build
+
+$(LEG): $(PEGDIR)/cmd/leg/leg.peg.go
+ cd $(@D) && GOARCH= GOOS= go build
+
+$(BOOTSTRAP):
+ cd $(PEGDIR) && GOARCH= GOOS= go install
+ cd $(@D) && go run ../../bootstrap/main.go
+
+%.peg.go: %.peg $(PEG)
+ $(PEG) -switch -inline $<
View
@@ -1,42 +1,30 @@
-# Copyright 2010 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
+PEGDIR=.
-PKGROOT = .
-include Make.common
+PARSERGOFILES=\
+ ./calculator/calculator.peg.go\
+ ./cmd/leg/leg.peg.go\
+ \
+ ./cmd/legleg/leg.leg.go\
+ ./cmd/legcalc/calc.leg.go\
-.PHONY: all
-all: peg
+all: prepare
-peg: main.$(O)
- $(LD) -o peg main.$(O)
+include Make.inc
+include cmd/leg/Make.inc
-PKGFILES=\
- peg.go\
- template.go\
+prepare: $(PEG) $(PARSERGOFILES)
-CMDFILES=\
- main.go\
- bootstrap.go\
-
-peg.$(O):\
- $(PKGFILES)\
-
-main.$(O):\
- peg.$(O)\
- $(CMDFILES)\
-
-bootstrap.go: bootstrap/main.go
- $(MAKE) -C bootstrap/ bootstrap
- ./bootstrap/bootstrap
-
-.PHONY: clean
clean:
- $(MAKE) -C bootstrap/ clean
- $(MAKE) -C leg/ clean
- rm -f *.6 *.8 bootstrap.go peg
-
-.PHONY: test
-test: peg
- ./peg -inline -switch peg.peg
- cmp peg.peg.go bootstrap.go
+# go clean ./...
+ rm -f $(BOOTSTRAP)
+ rm -f $(PARSERGOFILES)
+
+# compared files must be equal
+test: ./cmd/peg/peg.peg.go
+ diff $(<D)/bootstrap.go $<
+ rm -f $<
+
+.PHONY:\
+ all\
+ prepare\
+ clean\
View
@@ -1,13 +0,0 @@
-# Copyright 2010 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-PKGROOT = ..
-include ../Make.common
-
-bootstrap: main.$(O)
- $(LD) -o bootstrap main.$(O)
-
-.PHONY: clean
-clean:
- rm -f *.6 *.8 bootstrap
View
@@ -5,7 +5,7 @@
package main
import (
- "peg"
+ "github.com/knieriem/peg"
"runtime"
)
View
@@ -1,20 +0,0 @@
-# Copyright 2010 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-include ../Make.common
-
-calculator: main.$(O)
- $(LD) -o calculator main.$(O)
-
-main.$(O): calculator.$(O)
-
-calculator.$(O): calculator.go calculator.peg.go
- $(GC) -o calculator.$(O) calculator.go calculator.peg.go
-
-calculator.peg.go: calculator.peg
- ../peg -switch=true -inline=true calculator.peg
-
-.PHONY: clean
-clean:
- rm -f *.6 *.8 calculator calculator.peg.go
View
@@ -5,7 +5,7 @@
package calculator
import (
- "big"
+ "math/big"
)
type Type uint8
@@ -5,8 +5,8 @@
package main
import (
- "calculator"
"fmt"
+ "github.com/knieriem/peg/calculator"
"os"
)
@@ -21,6 +21,6 @@ func main() {
calc := &calculator.Calculator{Buffer: expression}
calc.Init()
calc.Expression.Init(expression)
- if !calc.Parse() {calc.PrintError(); return}
+ if !calc.Parse(0) {calc.PrintError(); return}
fmt.Printf("= %v\n", calc.Evaluate())
}
View
@@ -0,0 +1,4 @@
+# to be included after ../../Make.inc
+
+%.leg.go: %.leg $(LEG)
+ $(LEG) -switch $<
File renamed without changes.
@@ -5,7 +5,7 @@
package main
import (
- "peg"
+ "github.com/knieriem/peg"
"fmt"
"io/ioutil"
"runtime"
File renamed without changes.
File renamed without changes.
@@ -5,7 +5,7 @@
package main
import (
- "peg"
+ "github.com/knieriem/peg"
"fmt"
"io/ioutil"
"runtime"
File renamed without changes.
View
@@ -1,40 +0,0 @@
-# Copyright 2010 The Go Authors. All rights reserved.
-# Use of this source code is governed by a BSD-style
-# license that can be found in the LICENSE file.
-
-PKGROOT = ..
-include ../Make.common
-
-.PHONY: all
-all: leg
-
-
-# pe-leg: LEG parser generator created from a PE grammar
-
-pe-leg: main.$(O)
- $(LD) -o pe-leg main.$(O)
-
-main.$(O): ../peg.$(O) leg.peg.go
-
-%.peg.go: %.peg ../peg
- ../peg -inline -switch $<
-
-
-# leg: LEG parser generator created from an LE grammar by pe-leg
-leg: leg.leg.$(O)
- $(LD) -o $@ $<
-
-%.leg.go: %.leg ./pe-leg
- ./pe-leg -inline -switch $<
-
-leg.leg.$(O): ../peg.$(O)
-
-
-.PHONY: clean
-clean:
- rm -f *.6 *.8 leg *.peg.go pe-leg *leg.go calc
-
-%: %.leg leg
- ./leg -switch $<
- $(GC) $<.go
- $(LD) -o $@ $<.$(O)
View
@@ -13,7 +13,7 @@ package {{.}}
import (
"fmt"
- "peg"
+ "github.com/knieriem/peg"
)
{{end}}
const (\

0 comments on commit ee0a62a

Please sign in to comment.