-
Notifications
You must be signed in to change notification settings - Fork 11
/
Makefile
98 lines (81 loc) · 2.98 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
88
89
90
91
92
93
94
95
96
97
# Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
# SPDX-License-Identifier: Apache-2.0
SPECFILE_NAME := xks-proxy.spec
SPECFILE := rpmspec/$(SPECFILE_NAME)
NAME := $(shell rpmspec -q --queryformat "%{name}" $(SPECFILE))
VERSION := $(shell rpmspec -q --queryformat "%{version}" $(SPECFILE))
RELEASE := $(shell rpmspec -q --queryformat "%{release}" $(SPECFILE))
TOPDIR := $(shell rpm --eval "%{_topdir}" )
RPMDIR := $(shell rpm --eval "%{_rpmdir}" )
SPECDIR := $(shell rpm --eval "%{_specdir}" )
SOURCESDIR := $(shell rpm --eval "%{_sourcedir}")
BUILDROOT := $(shell rpm --eval %{_buildrootdir})
SOURCE_BUNDLE := $(NAME)-$(VERSION)-$(RELEASE).tar.xz
PROJECT_DIR := xks-axum
PROJECT_ROOTDIR := $(shell basename $(CURDIR))
APP_FROM_DIR := $(PROJECT_DIR)/target/release
RPMBUILDDIR_APP := $(BUILDROOT)/usr/sbin
RPMBUILD_APP := $(RPMBUILDDIR_APP)/$(NAME)
RPMBUILDIR_SERVICE_UNIT := $(BUILDROOT)/etc/systemd/system
RPMBUILD_SERVICE_UNIT := $(RPMBUILDIR_SERVICE_UNIT)/$(NAME).service
RPMBUILD_SPECFILE := $(SPECDIR)/$(SPECFILE_NAME)
RPMBUILD_SOURCEFILE := $(SOURCESDIR)/$(SOURCE_BUNDLE)
RPM := $(RPMDIR)/x86_64/$(NAME)-$(VERSION)-$(RELEASE).x86_64.rpm
DEB := $(NAME)-$(VERSION)-$(RELEASE).deb
ifneq (, $(shell git rev-parse --is-inside-work-tree 2>/dev/null))
export GIT_HASH := $(shell git rev-parse --short HEAD)
endif
.PHONY: release
release: $(RPM)
$(RPM): $(RPMBUILD_SPECFILE) $(RPMBUILD_SOURCEFILE) $(RPMBUILD_APP) $(RPMBUILD_SERVICE_UNIT)
rpmbuild -ba --noclean $(RPMBUILD_SPECFILE) --buildroot=$(BUILDROOT)
# Symlink to the rpm so we can use a "constant" name by CodeBuild in buildspec.yml
# and CodeDeploy in appspec.yml
ln -s $(RPM) $(APP_FROM_DIR)/aws-kms-xks-proxy.rpm
ifeq (, $(shell which alien 2>/dev/null))
@echo "INFO: No command alien found"
else
ifeq (, $(shell which sudo))
alien $(RPM)
else
sudo alien $(RPM)
endif
endif
$(RPMBUILD_SPECFILE):
for dir in BUILD RPMS SOURCES SPECS SRPMS; do \
mkdir -p ~/rpmbuild/$$dir; \
done
cp $(SPECFILE) $@
$(RPMBUILD_SOURCEFILE):
cargo clean --manifest-path=$(PROJECT_DIR)/Cargo.toml && \
cd .. && \
tar cJfh $@ \
--exclude=$(PROJECT_ROOTDIR)/.git \
--exclude=$(PROJECT_ROOTDIR)/.gitignore \
--exclude=$(PROJECT_ROOTDIR)/Config \
$(PROJECT_ROOTDIR)
$(RPMBUILD_APP): $(APP_FROM_DIR)/$(NAME)
mkdir -p $(RPMBUILDDIR_APP)
cp scripts/* $(RPMBUILDDIR_APP)/
cp $(APP_FROM_DIR)/$(NAME) $@
$(APP_FROM_DIR)/$(NAME):
ifeq (, $(shell git rev-parse --is-inside-work-tree 2>/dev/null))
@echo "INFO: Not a git repository"
endif
cargo build --release --manifest-path=$(PROJECT_DIR)/Cargo.toml
$(RPMBUILD_SERVICE_UNIT):
mkdir -p $(RPMBUILDIR_SERVICE_UNIT)
cp systemd/* $(RPMBUILDIR_SERVICE_UNIT)/
# A convenient target to install all the necessary rpm build tools
.PHONY: install_rpm_tools
install_rpm_tools:
sudo yum install -y rpmdevtools rpm-build rpm-devel rpmlint
@touch $@
.PHONY: clean
clean:
rm -f $(RPM)
rm -rf $(APP_FROM_DIR)
.PHONY: distclean
distclean: clean
rm -rf $(TOPDIR)
rm -f install_rpm_tools