-
Notifications
You must be signed in to change notification settings - Fork 6
/
Makefile
48 lines (37 loc) · 1.57 KB
/
Makefile
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
PKG_NAME := $(shell cat PKG_NAME)
PACKAGE_NAME := $(if $(PKG_NAME),$(PKG_NAME),$(error No package name, please create PKG_NAME))
PACKAGE_NAME := $(if $(DEV),$(PACKAGE_NAME)-dev,$(PACKAGE_NAME))
ifneq ($(wildcard SHORT_VERSION),)
VERSION := $(shell cat SHORT_VERSION || true)
BUILD_NUMBER := $(shell git describe --tags --match 'v[0-9]*.[0-9]*' --long|cut -d- -f2 || echo 1)
VERSION_STRING := $(if $(VERSION),$(VERSION).$(BUILD_NUMBER),$(error No version supplied, please add it as 'VERSION=x.y'))
else
VERSION := $(shell cat VERSION || true)
VERSION_STRING := $(if $(VERSION),$(VERSION),$(error No version supplied, please add it as 'VERSION=x.y.z'))
endif
OUTPUT_NAME := $(PACKAGE_NAME)_$(VERSION_STRING)
OUTPUT_DIR := pkg/$(OUTPUT_NAME)
PKG_COPY := $(wildcard *.md) $(shell cat PKG_COPY || true)
SED_FILES := $(shell find . -iname '*.json' -type f \! -path './pkg/*') \
$(shell find . -iname '*.lua' -type f \! -path './pkg/*')
OUT_FILES := $(SED_FILES:%=$(OUTPUT_DIR)/%)
SED_EXPRS := -e 's/{{MOD_NAME}}/$(PACKAGE_NAME)/g'
SED_EXPRS += -e 's/{{VERSION}}/$(VERSION_STRING)/g'
all: package
package-copy: $(PKG_DIRS) $(PKG_FILES)
mkdir -p $(OUTPUT_DIR)
ifneq ($(PKG_COPY),)
cp -r $(PKG_COPY) pkg/$(OUTPUT_NAME)
endif
$(OUTPUT_DIR)/%.lua: %.lua
mkdir -p $(@D)
sed -e 's/{{__FILE__}}/'"$(strip $(subst /,\/, $(subst ./,,$*)))"'.lua/g' $(SED_EXPRS) $< > $@
luac -p $@
$(OUTPUT_DIR)/%: %
mkdir -p $(@D)
sed $(SED_EXPRS) $< > $@
package-dir: package-copy $(OUT_FILES)
package: package-dir
cd pkg && zip -r $(OUTPUT_NAME).zip $(OUTPUT_NAME)
clean:
rm -rf pkg/$(OUTPUT_NAME)