Makefile 2.9 KB
Newer Older
1
ISULAD_KIT_BIN=./isulad-img
O
overweight 已提交
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
BUILT=$(shell echo `date +'%Y%m%d-%H:%M:%S'`)

ifeq ($(shell uname),Darwin)
PREFIX ?= ${DESTDIR}/usr/local
DARWIN_BUILD_TAG=containers_image_ostree_stub
# On macOS, (brew install gpgme) installs it within /usr/local, but /usr/local/include is not in the default search path.
# Rather than hard-code this directory, use gpgme-config. Sadly that must be done at the top-level user
# instead of locally in the gpgme subpackage, because cgo supports only pkg-config, not general shell scripts,
# and gpgme does not install a pkg-config file.
# If gpgme is not installed or gpgme-config cant be found for other reasons, the error is silently ignored
# (and the user will probably find out because the cgo compilation will fail).
GPGME_ENV := CGO_CFLAGS="$(shell gpgme-config --cflags 2>/dev/null)" CGO_LDFLAGS="$(shell gpgme-config --libs 2>/dev/null)"
else
PREFIX ?= ${DESTDIR}/usr
endif

INSTALLDIR=${PREFIX}/bin
CONTAINERSSYSCONFIGDIR=${DESTDIR}/etc/containers

ifeq ($(shell go env GOOS), linux)
  GO_DYN_FLAGS="-buildmode=pie"
endif

export GOPATH := $(CURDIR)

BTRFS_BUILD_TAG = $(shell hack/btrfs_tag.sh)
LIBDM_BUILD_TAG = $(shell hack/libdm_tag.sh)
LOCAL_BUILD_TAGS = $(BTRFS_BUILD_TAG) $(LIBDM_BUILD_TAG) $(DARWIN_BUILD_TAG)
BUILDTAGS += $(LOCAL_BUILD_TAGS)
GIT_COMMIT := $(shell git rev-parse HEAD 2> /dev/null || true)
GO_LDFLAGS="-s -w -extldflags -static -X main.gitCommit=${GIT_COMMIT} -X main.built=${BUILT}"
33
GOTMPDIR=/tmp/isulad-img
O
overweight 已提交
34 35

# ifeq ($(DISABLE_CGO), 1)
W
WangFengTu 已提交
36
		override BUILDTAGS = containers_image_ostree_stub exclude_graphdriver_btrfs containers_image_openpgp
O
overweight 已提交
37 38
# endif

39
.PHONY: all isulad_img static  clean
O
overweight 已提交
40

41
all: isulad_img
O
overweight 已提交
42

43
isulad_img: link
O
overweight 已提交
44 45
	echo $(GOPATH)
	echo $(CURDIR)
D
dogsheng 已提交
46 47 48
	rm -rf $(CURDIR)/src/isula-image/isula
	mkdir -p $(CURDIR)/src/isula-image/
	cp -rf isula $(CURDIR)/src/isula-image/
O
overweight 已提交
49
	mkdir -p ${GOTMPDIR}
50
	$(GPGME_ENV) go build ${GO_DYN_FLAGS} -ldflags "-extldflags -zrelro -extldflags -znow -tmpdir ${GOTMPDIR} -X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o isulad-img ./cmd/isulad_img
O
overweight 已提交
51
	rm -rf ${GOTMPDIR}
D
dogsheng 已提交
52
	rm -rf $(CURDIR)/src/isula-image/isula
O
overweight 已提交
53 54 55 56

static: link
	echo $(GOPATH)
	echo $(CURDIR)
D
dogsheng 已提交
57 58 59
	rm -rf $(CURDIR)/src/isula-image/isula
	mkdir -p $(CURDIR)/src/isula-image/
	cp -rf isula $(CURDIR)/src/isula-image/
O
overweight 已提交
60
	mkdir -p ${GOTMPDIR}
61
	$(GPGME_ENV) go build -ldflags "-tmpdir ${GOTMPDIR} -extldflags \"-static\" -X main.gitCommit=${GIT_COMMIT}" -gcflags "$(GOGCFLAGS)" -tags "$(BUILDTAGS)" -o isulad-img ./cmd/isulad_img
O
overweight 已提交
62
	rm -rf ${GOTMPDIR}
D
dogsheng 已提交
63 64 65 66
	rm -rf $(CURDIR)/src/isula-image/isula

proto:
	protoc --go_out=plugins=grpc:. ./isula/isula_image.proto
O
overweight 已提交
67 68 69 70 71 72

clean:
	rm -rf ${ISULAD_KIT_BIN}

install:
	install -d -m 755 ${INSTALLDIR}
73
	install -m 755 ${ISULAD_KIT_BIN} ${INSTALLDIR}/isulad-img
O
overweight 已提交
74 75 76 77 78
	install -d -m 755 ${CONTAINERSSYSCONFIGDIR}
	install -m 644 default-policy.json ${CONTAINERSSYSCONFIGDIR}/policy.json

link:
	ln -sfn $(CURDIR)/vendor $(CURDIR)/src