Skip to content

Commit

Permalink
Add build and packaging tools (#4)
Browse files Browse the repository at this point in the history
- Add Makefile
- Add PKGBUILD for Archlinux
- Add notice about PNG supporting only
  • Loading branch information
alersrt committed May 4, 2023
1 parent 76f7d03 commit ae746f5
Show file tree
Hide file tree
Showing 5 changed files with 219 additions and 1 deletion.
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.idea
.go
vendor
vendor
build/bin
29 changes: 29 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
Contribution Guide
==================

## Requirements

- If you don't use docker-wrapped commands, make sure that tools you use have the same version as in docker-wrapped
commands. It's latest version, mainly.

## Operations

Take a look at [`Makefile`][1] for commands usage details.

### Dependencies

To preload project dependencies use docker-wrapped command from [`Makefile`][1]:

```bash
make deps
```

### Building

To build/rebuild binaries use command from [`Makefile`][1]:

```bash
make build
```

[1]: Makefile
143 changes: 143 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,143 @@
#!/usr/bin/env make

env.file ?=

ifdef env.file
include $(env.file)
export $(shell sed 's/=.*//' $(env.file))
endif

###############################
# Common defaults/definitions #
###############################

comma := ,

# Checks two given strings for equality.
eq = $(if $(or $(1),$(2)),$(and $(findstring $(1),$(2)),\
$(findstring $(2),$(1))),1)




###############
# Git Section #
###############

MAINLINE_BRANCH := dev
CURRENT_BRANCH := $(shell git branch | grep \* | cut -d ' ' -f2)

# Squash changes of the current Git branch onto another Git branch.
#
# WARNING: You must merge `onto` branch in the current branch before squash!
#
# Usage:
# make squash [onto=] [del=(no|yes)]

onto ?= $(MAINLINE_BRANCH)
del ?= no
upstream ?= origin

squash:
ifeq ($(CURRENT_BRANCH),$(onto))
@echo "--> Current branch is '$(onto)' already" && false
endif
git checkout $(onto)
git branch -m $(CURRENT_BRANCH) orig-$(CURRENT_BRANCH)
git checkout -b $(CURRENT_BRANCH)
git branch --set-upstream-to $(upstream)/$(CURRENT_BRANCH)
git merge --squash orig-$(CURRENT_BRANCH)
ifeq ($(del),yes)
git branch -d orig-$(CURRENT_BRANCH)
endif




###########
# Aliases #
###########

build:
@make go.build

clean: go.clean

# Resolve all project dependencies.
#
# Usage:
# make deps

deps: go.deps



###############
# Go commands #
###############

pkgname = blurhash-cli
pkgver ?= 1.0.0
builddir ?= ./build/bin
mainpath ?= ./cmd/cli/main.go

go.build:
mkdir -p ${builddir}
export CGO_CPPFLAGS="${CPPFLAGS}"
export CGO_CFLAGS="${CFLAGS}"
export CGO_CXXFLAGS="${CXXFLAGS}"
export CGO_LDFLAGS="${LDFLAGS}"
export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"
GOARCH=amd64 GOOS=darwin go build -o ${builddir}/${pkgname}-${pkgver}-darwin ${mainpath}
GOARCH=amd64 GOOS=linux go build -o ${builddir}/${pkgname}-${pkgver}-linux ${mainpath}
GOARCH=amd64 GOOS=windows go build -o ${builddir}/${pkgname}-${pkgver}-windows ${mainpath}

go.clean:
go clean
rm -rf ${builddir}

go.deps:
go mod download




###################
# Docker commands #
###################

# Execute docker command with needed params.
#
# Usage:
docker.run:

# Stop project in Docker Compose development environment
# and remove all related containers.
#
# Usage:
# make docker.down

docker.down:
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose down --rmi=local -v

# Run Docker Compose development environment.
#
# Usage:
# make docker.up [rebuild=(yes|no)]
# [background=(no|yes)]

rebuild ?= yes
background ?= no

docker.up:
CURRENT_UID=$(shell id -u):$(shell id -g) docker compose up \
$(if $(call eq,$(rebuild),no),,--build) \
$(if $(call eq,$(background),yes),-d,--abort-on-container-exit)




.PHONY: squash \
go.clean go.build go.deps \
clean deps build up down \
docker.up docker.down
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,16 @@ So as a result we will get the PNG [image](assets/output.png).
![Output image](assets/output.png)



---
## Note

Only PNG format is supported now.

---



[1]: https://blurha.sh/

[2]: https://github.com/bbrks/go-blurhash
35 changes: 35 additions & 0 deletions build/packages/arch/PKGBUILD
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
pkgname=blurhash-cli
pkgver=v1.0.0
pkgrel=1
pkgdesc='BlurHash CLI tool'
arch=('x86_64')
url="https://github.com/alersrt/go-blurhash-cli/archive/refs/tags"
license=('MIT')
makedepends=('go')
source=("$url/$pkgname-$pkgver.tar.gz")
# sha256sums=('...')

prepare(){
cd "$pkgname-$pkgver"
mkdir -p build/
}

build() {
cd "$pkgname-$pkgver"
export CGO_CPPFLAGS="${CPPFLAGS}"
export CGO_CFLAGS="${CFLAGS}"
export CGO_CXXFLAGS="${CXXFLAGS}"
export CGO_LDFLAGS="${LDFLAGS}"
export GOFLAGS="-buildmode=pie -trimpath -ldflags=-linkmode=external -mod=readonly -modcacherw"
go build -o build/bin/$pkgname ./cmd/cli/main.go
}

check() {
cd "$pkgname-$pkgver"
go test ./...
}

package() {
cd "$pkgname-$pkgver"
install -Dm755 build/bin/$pkgname "$pkgdir"/usr/bin/$pkgname
}

0 comments on commit ae746f5

Please sign in to comment.