Skip to content

Commit

Permalink
Simplify Makefile. Update README with updated information about build…
Browse files Browse the repository at this point in the history
…ing.
  • Loading branch information
lopezator committed Oct 17, 2018
1 parent cde7bcd commit d656a42
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 83 deletions.
69 changes: 2 additions & 67 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,73 +1,8 @@
# MAINTAINER: David López <[email protected]>

APP = sqlfmt
OS = amd64-linux-gnu amd64-darwin amd64-windows
SHELL := /bin/bash

# Overridable by CI
COMMIT_SHORT ?= $(shell git rev-parse --verify --short HEAD)
VERSION ?= $(COMMIT_SHORT)
VERSION_NOPREFIX ?= $(shell echo $(VERSION) | sed -e 's/^[[v]]*//')

# Build vars
CGO_ENABLED = 1
GOOS :=
GOARCH :=
CMAKE_SYSTEM_NAME :=
CC :=
CMAKE_C_COMPILER :=
CXX :=
CMAKE_CXX_COMPILER :=
LDFLAGS :=
EXTRA_CMAKE_FLAGS :=
SUFFIX :=
EXT :=

#
# Common methodology based targets
#
.PHONY: build
build:
@for app in $(APP) ; do \
for os in $(OS) ; do \
if [ "$$os" == "amd64-linux-gnu" ]; then \
GOOS=linux; \
GOARCH=amd64; \
CMAKE_SYSTEM_NAME=Linux; \
CC=x86_64-unknown-linux-gnu-cc; \
CXX=x86_64-unknown-linux-gnu-c++; \
LDFLAGS="-static-libgcc -static-libstdc++"; \
SUFFIX=-linux-2.6.32-gnu-amd64; \
fi; \
if [ "$$os" == "amd64-darwin" ]; then \
GOOS=darwin; \
GOARCH=amd64; \
CMAKE_SYSTEM_NAME=Darwin; \
CC=x86_64-apple-darwin13-cc; \
CXX=x86_64-apple-darwin13-c++; \
EXTRA_CMAKE_FLAGS=-DCMAKE_INSTALL_NAME_TOOL=x86_64-apple-darwin13-install_name_tool; \
SUFFIX=-darwin-10.9-amd64; \
fi; \
if [ "$$os" == "amd64-windows" ]; then \
EXT=".exe"; \
GOOS=windows; \
GOARCH=amd64; \
CMAKE_SYSTEM_NAME=Windows; \
CC=x86_64-w64-mingw32-cc; \
CXX=x86_64-w64-mingw32-c++; \
LDFLAGS=-static; \
SUFFIX=-windows-6.2-amd64; \
fi; \
CGO_ENABLED=$(CGO_ENABLED) GOOS=$$GOOS GOARCH=$$GOARCH CMAKE_SYSTEM_NAME=$$CMAKE_SYSTEM_NAME \
CMAKE_C_COMPILER=$CC CC=$$CC CMAKE_CXX_COMPILER=$CXX CXX=$$CXX EXTRA_CMAKE_FLAGS=$$EXTRA_CMAKE_FLAGS SUFFIX=$$SUFFIX \
go build \
-a -x -v -ldflags "$(LDFLAGS) \
-X main.Version=$(VERSION_NOPREFIX) \
-X main.GitRev=$(COMMIT_SHORT) \
" \
-o ./bin/$$app-$(VERSION_NOPREFIX)-$$os$$EXT \
./cmd/$$app; \
done; \
done;

.PHONY: sql-fmt
sql-fmt:
@echo "Running sql-fmt..."
Expand Down
24 changes: 8 additions & 16 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -122,22 +122,14 @@ Each release comes with pre-compiled binaries for several platforms:
https://github.com/lopezator/sqlfmt/releases
Anyway, if you want to cross-compile from source, you can do it using docker in a handy way:
Anyway, if you want to compile your binaries from source, now, thanks to cockroachdb folks effort, sqlfmt is CGO free and compiling is easy as:
1. Build container:
```
$> docker run --rm -t -d --name="sqlfmt-builder" -v="$PWD:/go/src/github.com/lopezator/sqlfmt" --workdir="/go/src/github.com/lopezator/sqlfmt" --entrypoint="cat" cockroachdb/builder:20180813-101406
```
2. Build binaries inside the container:
```
$> docker exec -it sqlfmt-builder make build
```
```
$> GOOS=<GOOS> GOARCH=<GOARCH> go build cmd/sqlfmt/main.go
```
3. Stop container:
Example:
```
$> docker container stop sqlfmt-builder
```
```
$> GOOS=linux GOARCH=amd64 go build cmd/sqlfmt/main.go
```

0 comments on commit d656a42

Please sign in to comment.