+ifndef GOOS
+ GOOS := linux
+endif
+
PACKAGES := $(shell go list ./... | grep -v '/vendor/')
+BUILD_FLAGS := -ldflags "-X github.com/equity/compiler.GitCommit=`git rev-parse HEAD`"
+VERSION := $(shell awk -F= '/VersionMajor =/ {print $$2}' compiler/version.go | tr -d "\" ").$(shell awk -F= '/VersionMinor =/ {print $$2}' compiler/version.go | tr -d "\" ").$(shell awk -F= '/VersionPatch =/ {print $$2}' compiler/version.go | tr -d "\" ")
+EQUITY_RELEASE := equity-$(VERSION)-$(GOOS)
+
+all: test cmd equity
+
+cmd:
+ @echo "Building equitycmd to target/equitycmd"
+ @go build $(BUILD_FLAGS) -o target/equitycmd compiler/cmd/equitycmd/equitycmd.go
-all: test equitycmd
+equity:
+ @echo "Building equity to target/equity"
+ @go build $(BUILD_FLAGS) -o target/equity equity/main.go
-equitycmd:
- @echo "Building equitycmd to compiler/cmd/equitycmd/equitycmd"
- @go build -o compiler/cmd/equitycmd/equitycmd compiler/cmd/equitycmd/equitycmd.go
+ifeq ($(GOOS),windows)
+release: equity
+ cd target && cp -f equity $(EQUITY_RELEASE).exe
+ cd target && md5sum $(EQUITY_RELEASE).exe > $(EQUITY_RELEASE).md5
+ cd target && zip $(EQUITY_RELEASE).zip $(EQUITY_RELEASE).exe $(EQUITY_RELEASE).md5
+ cd target && rm -f $(EQUITY_RELEASE).exe $(EQUITY_RELEASE).md5
+else
+release: equity
+ cd target && cp -f equity $(EQUITY_RELEASE)
+ cd target && md5sum $(EQUITY_RELEASE) > $(EQUITY_RELEASE).md5
+ cd target && tar -czf $(EQUITY_RELEASE).tgz $(EQUITY_RELEASE) $(EQUITY_RELEASE).md5
+ cd target && rm -f $(EQUITY_RELEASE) $(EQUITY_RELEASE).md5
+endif
-tool:
- @echo "Building equity to equity/equity"
- @go build -o equity/equity equity/main.go
+release-all: clean
+ GOOS=linux make release
+ GOOS=windows make release
clean:
- @echo "Cleaning binaries built..."
- @rm -rf compiler/cmd/equitycmd/equitycmd
- @echo "Done."
+ @rm -rf target
+ @echo "Cleaning target binaries successfully."
test:
@echo "====> Running go test"
ci: test
-.PHONY: all clean test ci
+.PHONY: all clean test ci cmd equity
Build source code, the build target of the equity compiler commandline tool is `equity`.
```bash
-$ make tool
+$ make equity
```
-then change directory to `equity`, and you can find the tool `equity` :
+then change directory to `equity`, and you can find the commandline tool `equity` :
```bash
$ cd equity
```
--- /dev/null
+package compiler
+
+import "fmt"
+
+const (
+ // VersionMajor is the Major version component of the current release
+ VersionMajor = 0
+ // VersionMinor is the Minor version component of the current release
+ VersionMinor = 1
+ // VersionPatch is the Patch version component of the current release
+ VersionPatch = 1
+)
+
+// Git SHA1 commit hash of the release (set via linker flags)
+var GitCommit = ""
+
+// Version holds the textual version string.
+var Version = func() string {
+ return fmt.Sprintf("%d.%d.%d", VersionMajor, VersionMinor, VersionPatch)
+}()
+
+// VersionWithCommit holds the textual version and the first 8 character of git commit.
+func VersionWithCommit(gitCommit string) string {
+ version := Version
+ if len(gitCommit) >= 8 {
+ version += "+" + gitCommit[:8]
+ }
+ return version
+}
strShift string = "shift"
strInstance string = "instance"
strAst string = "ast"
+ strVersion string = "version"
)
var (
shift = false
instance = false
ast = false
+ version = false
)
func init() {
equityCmd.PersistentFlags().BoolVar(&shift, strShift, false, "Function shift of the contracts.")
equityCmd.PersistentFlags().BoolVar(&instance, strInstance, false, "Object of the Instantiated contracts.")
equityCmd.PersistentFlags().BoolVar(&ast, strAst, false, "AST of the contracts.")
+ equityCmd.PersistentFlags().BoolVar(&version, strVersion, false, "Version of equity compiler.")
}
func main() {
Use: "equity <input_file>",
Short: "equity commandline compiler",
Example: "equity contract_name [contract_args...] --bin --instance",
- Args: cobra.RangeArgs(1, 100),
+ Args: cobra.RangeArgs(0, 100),
Run: func(cmd *cobra.Command, args []string) {
+ if version {
+ version := compiler.VersionWithCommit(compiler.GitCommit)
+ fmt.Println("Version:", version)
+ os.Exit(0)
+ }
+
if len(args) < 1 {
cmd.Usage()
}