-
Notifications
You must be signed in to change notification settings - Fork 3
/
Makefile
87 lines (67 loc) · 2.41 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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
MAKE ?= make
GO ?= go
APP_NAME := dagtools
APP_VERSION ?= 1.6.0
APP_RELEASE ?= 1
APP_PACKAGE ?= github.com/iij/dagtools
# amd64, 386
ARCH_TYPE ?= amd64
BUILD_DIR ?= build
BUILD_BIN_DIR := $(BUILD_DIR)/$(OS_TYPE)_$(ARCH_TYPE)
ifneq ($(wildcard $(WINDOWS)/system32/krnl32.dll),)
LOCAL_OS_TYPE := windows
endif
ifneq ($(wildcard /sbin/bsdlabel),)
LOCAL_OS_TYPE := freebsd
endif
ifneq ($(wildcard /System/Library/Extensions/AppleFileSystemDriver.kext),)
LOCAL_OS_TYPE := darwin
endif
ifneq ($(wildcard /sbin/modprobe),)
LOCAL_OS_TYPE := linux
endif
# windows, linux, darwin, freebsd, netbsd, dragonfly solaris, plan9
OS_TYPE ?= $(LOCAL_OS_TYPE)
BUILD_FILE_NAME := $(APP_NAME)
BUILD_BIN := $(BUILD_BIN_DIR)/$(APP_NAME)
BUILD_BIN_SUFFIX :=
ifeq ($(OS_TYPE),windows)
BUILD_BIN_SUFFIX := .exe
BUILD_FILE_NAME := $(APP_NAME)$(BUILD_BIN_SUFFIX)
BUILD_BIN := $(BUILD_DIR)/$(OS_TYPE)_$(ARCH_TYPE)/$(BUILD_FILE_NAME)
endif
PACKAGE_NAME := $(APP_NAME)-$(OS_TYPE)-$(ARCH_TYPE)-$(APP_VERSION)
ARCHIVE_TYPE := tar.gz
ifeq ($(OS_TYPE),windows)
ARCHIVE_TYPE := zip
endif
all: prepare $(BUILD_DIR)/$(PACKAGE_NAME).$(ARCHIVE_TYPE)
rpm: all rpmbuild
prepare: core/version.go
core/version.go:
sed -e "s,__VERSION__,$(APP_VERSION),g" env/version.go.in > env/version.go
$(BUILD_DIR)/$(PACKAGE_NAME).tar.gz: $(BUILD_DIR)/$(PACKAGE_NAME)
tar -zcf $(BUILD_DIR)/$(PACKAGE_NAME).tar.gz -C $(BUILD_DIR) $(PACKAGE_NAME)
$(BUILD_DIR)/$(PACKAGE_NAME).zip: $(BUILD_DIR)/$(PACKAGE_NAME)
cd $(BUILD_DIR); zip -r $(PACKAGE_NAME).zip $(PACKAGE_NAME)
$(BUILD_DIR)/$(PACKAGE_NAME): $(BUILD_BIN)
mkdir -p $@
install -m 755 $< $@/
install -m 644 ./dagtools.ini.sample $@/
install -m 644 ./README.rst $@/
install -m 644 ./CHANGELOG.rst $@/
install -m 644 ./LICENSE.txt $@/
$(BUILD_BIN):
mkdir -p $(dir $@)
GOOS=$(OS_TYPE) GOARCH=$(ARCH_TYPE) $(GO) build -x -ldflags '-s -w' -o $@ $(APP_PACKAGE)
rpmbuild: $(BUILD_DIR)/$(APP_NAME)-linux-amd64-$(APP_VERSION)/$(APP_NAME)
mkdir -p $(BUILD_DIR)/rpm/{SOURCES,RPMS,SRPMS,BUILD,BUILDROOT,SPECS,INSTALL}
sed -e "s,__VERSION__,$(APP_VERSION),g" -e "s,__RELEASE__,$(APP_RELEASE),g" -e "s,__PACKAGE_NAME__,$(PACKAGE_NAME),g" $(APP_NAME).spec.in > $(BUILD_DIR)/$(APP_NAME).spec
rpmbuild -bb --nodeps -D "_sourcedir $(PWD)/$(BUILD_DIR)" -D "_topdir $(PWD)/$(BUILD_DIR)/rpm" $(BUILD_DIR)/$(APP_NAME).spec
clean:
rm -fr build/*
rm -f core/version.go
install: prepare
$(GO) install $(APP_PACKAGE)
test:
$(GO) test $(APP_PACKAGE)/...