mirror of
https://github.com/hrfee/jfa-go.git
synced 2026-01-18 16:47:42 +01:00
Makefile: share $(DATA) on internal/external, keep record of build flags
This means you could make precompile, then make INTERNAL=on then make INTERNAL=off and each time it would re-generate the go files only since the flags have changed.
This commit is contained in:
20
Makefile
20
Makefile
@@ -33,7 +33,7 @@ E2EE ?= on
|
|||||||
TAGS := -tags "
|
TAGS := -tags "
|
||||||
|
|
||||||
ifeq ($(INTERNAL), on)
|
ifeq ($(INTERNAL), on)
|
||||||
DATA := data
|
DATA := build/data
|
||||||
COMPDEPS := $(BUILDDEPS)
|
COMPDEPS := $(BUILDDEPS)
|
||||||
else
|
else
|
||||||
DATA := build/data
|
DATA := build/data
|
||||||
@@ -102,6 +102,13 @@ else
|
|||||||
SWAGINSTALL :=
|
SWAGINSTALL :=
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
# FLAG HASHING: To rebuild on flag change.
|
||||||
|
# credit for idea to https://bnikolic.co.uk/blog/sh/make/unix/2021/07/08/makefile.html
|
||||||
|
rebuildFlags := GOESBUILD GOBINARY VERSION COMMIT UPDATER INTERNAL TRAY E2EE TAGS DEBUG RACE
|
||||||
|
rebuildVals := $(foreach v,$(rebuildFlags),$(v)=$($(v)))
|
||||||
|
rebuildHash := $(strip $(shell echo $(rebuildVals) | sha256sum | cut -d " " -f1))
|
||||||
|
rebuildHashFile := $(DATA)/buildhash-$(rebuildHash).txt
|
||||||
|
|
||||||
CONFIG_BASE = config/config-base.yaml
|
CONFIG_BASE = config/config-base.yaml
|
||||||
|
|
||||||
# CONFIG_DESCRIPTION = $(DATA)/config-base.json
|
# CONFIG_DESCRIPTION = $(DATA)/config-base.json
|
||||||
@@ -219,11 +226,16 @@ $(COPY_TARGET): $(INLINE_TARGET) $(STATIC_SRC) $(LANG_SRC) $(CONFIG_BASE)
|
|||||||
BUILDDEPS := $(DATA) $(CONFIG_DEFAULT) $(EMAIL_TARGET) $(COPY_TARGET) $(SWAGGER_TARGET) $(INLINE_TARGET) $(CSS_FULLTARGET) $(TYPESCRIPT_TARGET)
|
BUILDDEPS := $(DATA) $(CONFIG_DEFAULT) $(EMAIL_TARGET) $(COPY_TARGET) $(SWAGGER_TARGET) $(INLINE_TARGET) $(CSS_FULLTARGET) $(TYPESCRIPT_TARGET)
|
||||||
precompile: $(BUILDDEPS)
|
precompile: $(BUILDDEPS)
|
||||||
|
|
||||||
COMPDEPS =
|
COMPDEPS = $(rebuildHashFile)
|
||||||
ifeq ($(INTERNAL), on)
|
ifeq ($(INTERNAL), on)
|
||||||
COMPDEPS = $(BUILDDEPS)
|
COMPDEPS = $(BUILDDEPS) $(rebuildHashFile)
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
$(rebuildHashFile):
|
||||||
|
$(info recording new flags $(rebuildVals))
|
||||||
|
rm -f $(DATA)/buildhash-*.txt
|
||||||
|
touch $(rebuildHashFile)
|
||||||
|
|
||||||
GO_SRC = $(shell find ./ -name "*.go")
|
GO_SRC = $(shell find ./ -name "*.go")
|
||||||
GO_TARGET = build/jfa-go
|
GO_TARGET = build/jfa-go
|
||||||
$(GO_TARGET): $(COMPDEPS) $(SWAGGER_TARGET) $(GO_SRC) go.mod go.sum
|
$(GO_TARGET): $(COMPDEPS) $(SWAGGER_TARGET) $(GO_SRC) go.mod go.sum
|
||||||
@@ -236,7 +248,7 @@ $(GO_TARGET): $(COMPDEPS) $(SWAGGER_TARGET) $(GO_SRC) go.mod go.sum
|
|||||||
test: $(BUILDDEPS) $(COMPDEPS) $(SWAGGER_TARGET) $(GO_SRC) go.mod go.sum
|
test: $(BUILDDEPS) $(COMPDEPS) $(SWAGGER_TARGET) $(GO_SRC) go.mod go.sum
|
||||||
$(GOBINARY) test -ldflags="$(LDFLAGS)" $(TAGS) -p 1
|
$(GOBINARY) test -ldflags="$(LDFLAGS)" $(TAGS) -p 1
|
||||||
|
|
||||||
all: $(BUILDDEPS) $(GO_TARGET)
|
all: $(BUILDDEPS) $(GO_TARGET) $(rebuildHashFile)
|
||||||
|
|
||||||
compress:
|
compress:
|
||||||
upx --lzma $(GO_TARGET)
|
upx --lzma $(GO_TARGET)
|
||||||
|
|||||||
@@ -14,7 +14,7 @@ const binaryType = "internal"
|
|||||||
|
|
||||||
func BuildTagsExternal() {}
|
func BuildTagsExternal() {}
|
||||||
|
|
||||||
//go:embed data data/html data/web data/web/css data/web/js
|
//go:embed build/data build/data/html build/data/web build/data/web/css build/data/web/js
|
||||||
var loFS embed.FS
|
var loFS embed.FS
|
||||||
|
|
||||||
//go:embed lang/common lang/admin lang/email lang/form lang/setup lang/pwreset lang/telegram
|
//go:embed lang/common lang/admin lang/email lang/form lang/setup lang/pwreset lang/telegram
|
||||||
@@ -38,6 +38,6 @@ func FSJoin(elem ...string) string {
|
|||||||
|
|
||||||
func loadFilesystems(rootDir string, logger *logger.Logger) {
|
func loadFilesystems(rootDir string, logger *logger.Logger) {
|
||||||
langFS = rewriteFS{laFS, "lang/"}
|
langFS = rewriteFS{laFS, "lang/"}
|
||||||
localFS = rewriteFS{loFS, "data/"}
|
localFS = rewriteFS{loFS, "build/data/"}
|
||||||
logger.Println("Using internal storage")
|
logger.Println("Using internal storage")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user