2020-06-22 23:51:57 +00:00
|
|
|
IS_WIN =
|
|
|
|
ifeq (${SHELL}, sh.exe)
|
|
|
|
IS_WIN = true
|
|
|
|
endif
|
|
|
|
ifeq (${SHELL}, cmd)
|
|
|
|
IS_WIN = true
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifdef IS_WIN
|
2019-07-28 03:19:54 +00:00
|
|
|
SEPARATOR := &&
|
|
|
|
SET := set
|
2020-06-22 23:51:57 +00:00
|
|
|
else
|
|
|
|
SEPARATOR := ;
|
|
|
|
SET := export
|
2019-07-28 03:19:54 +00:00
|
|
|
endif
|
|
|
|
|
2020-06-29 04:44:21 +00:00
|
|
|
# set LDFLAGS environment variable to any extra ldflags required
|
|
|
|
# set OUTPUT to generate a specific binary name
|
|
|
|
|
|
|
|
LDFLAGS := $(LDFLAGS)
|
|
|
|
ifdef OUTPUT
|
|
|
|
OUTPUT := -o $(OUTPUT)
|
|
|
|
endif
|
|
|
|
|
2021-05-16 09:19:56 +00:00
|
|
|
export CGO_ENABLED = 1
|
|
|
|
export GO111MODULE = on
|
|
|
|
|
2020-06-29 04:44:21 +00:00
|
|
|
.PHONY: release pre-build install clean
|
|
|
|
|
|
|
|
release: generate ui build-release
|
2019-12-28 17:53:16 +00:00
|
|
|
|
2020-06-22 23:51:57 +00:00
|
|
|
pre-build:
|
2020-06-29 04:44:21 +00:00
|
|
|
ifndef BUILD_DATE
|
|
|
|
$(eval BUILD_DATE := $(shell go run -mod=vendor scripts/getDate.go))
|
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef GITHASH
|
2019-10-16 22:46:16 +00:00
|
|
|
$(eval GITHASH := $(shell git rev-parse --short HEAD))
|
2020-06-29 04:44:21 +00:00
|
|
|
endif
|
|
|
|
|
|
|
|
ifndef STASH_VERSION
|
2020-02-06 19:39:08 +00:00
|
|
|
$(eval STASH_VERSION := $(shell git describe --tags --exclude latest_develop))
|
2020-06-29 04:44:21 +00:00
|
|
|
endif
|
2020-06-22 23:51:57 +00:00
|
|
|
|
|
|
|
build: pre-build
|
2020-06-29 04:44:21 +00:00
|
|
|
$(eval LDFLAGS := $(LDFLAGS) -X 'github.com/stashapp/stash/pkg/api.version=$(STASH_VERSION)' -X 'github.com/stashapp/stash/pkg/api.buildstamp=$(BUILD_DATE)' -X 'github.com/stashapp/stash/pkg/api.githash=$(GITHASH)')
|
2021-05-16 09:19:56 +00:00
|
|
|
go build $(OUTPUT) -mod=vendor -v -tags "sqlite_omit_load_extension osusergo netgo" -ldflags "$(LDFLAGS) $(EXTRA_LDFLAGS)"
|
2020-06-29 04:44:21 +00:00
|
|
|
|
|
|
|
# strips debug symbols from the release build
|
|
|
|
# consider -trimpath in go build if we move to go 1.13+
|
|
|
|
build-release: EXTRA_LDFLAGS := -s -w
|
|
|
|
build-release: build
|
2019-02-10 12:16:29 +00:00
|
|
|
|
2020-09-14 01:12:36 +00:00
|
|
|
build-release-static: EXTRA_LDFLAGS := -extldflags=-static -s -w
|
|
|
|
build-release-static: build
|
|
|
|
|
2021-05-16 09:19:56 +00:00
|
|
|
# cross-compile- targets should be run within the compiler docker container
|
|
|
|
cross-compile-windows: export GOOS := windows
|
|
|
|
cross-compile-windows: export GOARCH := amd64
|
|
|
|
cross-compile-windows: export CC := x86_64-w64-mingw32-gcc
|
|
|
|
cross-compile-windows: export CXX := x86_64-w64-mingw32-g++
|
|
|
|
cross-compile-windows: OUTPUT := -o dist/stash-win.exe
|
|
|
|
cross-compile-windows: build-release-static
|
|
|
|
|
|
|
|
cross-compile-osx: export GOOS := darwin
|
|
|
|
cross-compile-osx: export GOARCH := amd64
|
|
|
|
cross-compile-osx: export CC := o64-clang
|
|
|
|
cross-compile-osx: export CXX := o64-clang++
|
|
|
|
cross-compile-osx: OUTPUT := -o dist/stash-osx
|
|
|
|
# can't use static build for OSX
|
|
|
|
cross-compile-osx: build-release
|
|
|
|
|
|
|
|
cross-compile-linux: export GOOS := linux
|
|
|
|
cross-compile-linux: export GOARCH := amd64
|
|
|
|
cross-compile-linux: OUTPUT := -o dist/stash-linux
|
|
|
|
cross-compile-linux: build-release-static
|
|
|
|
|
|
|
|
cross-compile-linux-arm64v8: export GOOS := linux
|
|
|
|
cross-compile-linux-arm64v8: export GOARCH := arm64
|
|
|
|
cross-compile-linux-arm64v8: export CC := aarch64-linux-gnu-gcc
|
|
|
|
cross-compile-linux-arm64v8: OUTPUT := -o dist/stash-linux-arm64v8
|
|
|
|
cross-compile-linux-arm64v8: build-release-static
|
|
|
|
|
|
|
|
cross-compile-linux-arm32v7: export GOOS := linux
|
|
|
|
cross-compile-linux-arm32v7: export GOARCH := arm
|
|
|
|
cross-compile-linux-arm32v7: export GOARM := 7
|
|
|
|
cross-compile-linux-arm32v7: export CC := arm-linux-gnueabihf-gcc
|
|
|
|
cross-compile-linux-arm32v7: OUTPUT := -o dist/stash-linux-arm32v7
|
|
|
|
cross-compile-linux-arm32v7: build-release-static
|
|
|
|
|
|
|
|
cross-compile-pi: export GOOS := linux
|
|
|
|
cross-compile-pi: export GOARCH := arm
|
|
|
|
cross-compile-pi: export GOARM := 6
|
|
|
|
cross-compile-pi: export CC := arm-linux-gnueabi-gcc
|
|
|
|
cross-compile-pi: OUTPUT := -o dist/stash-pi
|
|
|
|
cross-compile-pi: build-release-static
|
|
|
|
|
|
|
|
cross-compile-all: cross-compile-windows cross-compile-osx cross-compile-linux cross-compile-linux-arm64v8 cross-compile-linux-arm32v7 cross-compile-pi
|
|
|
|
|
2019-02-10 12:16:29 +00:00
|
|
|
install:
|
|
|
|
packr2 install
|
|
|
|
|
2019-07-27 19:49:35 +00:00
|
|
|
clean:
|
|
|
|
packr2 clean
|
|
|
|
|
2019-02-14 20:06:37 +00:00
|
|
|
# Regenerates GraphQL files
|
2019-07-11 16:57:50 +00:00
|
|
|
.PHONY: generate
|
|
|
|
generate:
|
2019-11-16 16:03:28 +00:00
|
|
|
go generate -mod=vendor
|
2020-04-02 21:46:23 +00:00
|
|
|
cd ui/v2.5 && yarn run gqlgen
|
2019-02-14 20:06:37 +00:00
|
|
|
|
2020-09-17 09:57:18 +00:00
|
|
|
# Regenerates stash-box client files
|
|
|
|
.PHONY: generate-stash-box-client
|
|
|
|
generate-stash-box-client:
|
|
|
|
go run -mod=vendor github.com/Yamashou/gqlgenc
|
|
|
|
|
2019-02-14 20:06:37 +00:00
|
|
|
# Runs gofmt -w on the project's source code, modifying any files that do not match its style.
|
|
|
|
.PHONY: fmt
|
|
|
|
fmt:
|
2019-07-28 03:54:27 +00:00
|
|
|
go fmt ./...
|
2019-02-14 20:06:37 +00:00
|
|
|
|
2020-04-29 02:13:08 +00:00
|
|
|
# Ensures that changed files have had gofmt run on them
|
|
|
|
.PHONY: fmt-check
|
|
|
|
fmt-check:
|
|
|
|
sh ./scripts/check-gofmt.sh
|
|
|
|
|
2019-02-14 20:06:37 +00:00
|
|
|
# Runs go vet on the project's source code.
|
|
|
|
.PHONY: vet
|
|
|
|
vet:
|
2019-11-16 16:03:28 +00:00
|
|
|
go vet -mod=vendor ./...
|
2019-02-14 20:06:37 +00:00
|
|
|
|
|
|
|
.PHONY: lint
|
|
|
|
lint:
|
2019-02-14 22:53:32 +00:00
|
|
|
revive -config revive.toml -exclude ./vendor/... ./...
|
2019-07-28 03:19:54 +00:00
|
|
|
|
2019-11-25 02:10:16 +00:00
|
|
|
# runs unit tests - excluding integration tests
|
|
|
|
.PHONY: test
|
|
|
|
test:
|
|
|
|
go test -mod=vendor ./...
|
|
|
|
|
|
|
|
# runs all tests - including integration tests
|
|
|
|
.PHONY: it
|
|
|
|
it:
|
|
|
|
go test -mod=vendor -tags=integration ./...
|
|
|
|
|
2020-09-15 07:28:53 +00:00
|
|
|
# generates test mocks
|
|
|
|
.PHONY: generate-test-mocks
|
|
|
|
generate-test-mocks:
|
|
|
|
go run -mod=vendor github.com/vektra/mockery/v2 --dir ./pkg/models --name '.*ReaderWriter' --outpkg mocks --output ./pkg/models/mocks
|
|
|
|
|
2020-04-29 02:13:08 +00:00
|
|
|
# installs UI dependencies. Run when first cloning repository, or if UI
|
|
|
|
# dependencies have changed
|
|
|
|
.PHONY: pre-ui
|
|
|
|
pre-ui:
|
|
|
|
cd ui/v2.5 && yarn install --frozen-lockfile
|
|
|
|
|
2020-06-24 05:46:37 +00:00
|
|
|
.PHONY: ui-only
|
|
|
|
ui-only: pre-build
|
2020-06-29 04:44:21 +00:00
|
|
|
$(SET) REACT_APP_DATE="$(BUILD_DATE)" $(SEPARATOR) \
|
2020-06-22 23:51:57 +00:00
|
|
|
$(SET) REACT_APP_GITHASH=$(GITHASH) $(SEPARATOR) \
|
|
|
|
$(SET) REACT_APP_STASH_VERSION=$(STASH_VERSION) $(SEPARATOR) \
|
2020-04-02 21:46:23 +00:00
|
|
|
cd ui/v2.5 && yarn build
|
2020-06-24 05:46:37 +00:00
|
|
|
|
|
|
|
.PHONY: ui
|
|
|
|
ui: ui-only
|
2019-08-21 04:07:25 +00:00
|
|
|
packr2
|
2020-04-29 02:13:08 +00:00
|
|
|
|
2020-06-24 05:46:37 +00:00
|
|
|
.PHONY: ui-start
|
2020-06-22 23:51:57 +00:00
|
|
|
ui-start: pre-build
|
2020-06-29 04:44:21 +00:00
|
|
|
$(SET) REACT_APP_DATE="$(BUILD_DATE)" $(SEPARATOR) \
|
2020-06-22 23:51:57 +00:00
|
|
|
$(SET) REACT_APP_GITHASH=$(GITHASH) $(SEPARATOR) \
|
|
|
|
$(SET) REACT_APP_STASH_VERSION=$(STASH_VERSION) $(SEPARATOR) \
|
|
|
|
cd ui/v2.5 && yarn start
|
|
|
|
|
2020-06-24 05:46:37 +00:00
|
|
|
.PHONY: fmt-ui
|
2020-04-29 02:13:08 +00:00
|
|
|
fmt-ui:
|
|
|
|
cd ui/v2.5 && yarn format
|
|
|
|
|
|
|
|
# runs tests and checks on the UI and builds it
|
|
|
|
.PHONY: ui-validate
|
|
|
|
ui-validate:
|
|
|
|
cd ui/v2.5 && yarn run validate
|
|
|
|
|
|
|
|
# just repacks the packr files - use when updating migrations and packed files without
|
|
|
|
# rebuilding the UI
|
|
|
|
.PHONY: packr
|
|
|
|
packr:
|
|
|
|
packr2
|
|
|
|
|
|
|
|
# runs all of the tests and checks required for a PR to be accepted
|
|
|
|
.PHONY: validate
|
|
|
|
validate: ui-validate fmt-check vet lint it
|