github.com/dshekhar95/sub_dgraph@v0.0.0-20230424164411-6be28e40bbf1/dgraph/Makefile (about) 1 # 2 # Copyright 2022 Dgraph Labs, Inc. and Contributors 3 # 4 # Licensed under the Apache License, Version 2.0 (the "License"); 5 # you may not use this file except in compliance with the License. 6 # You may obtain a copy of the License at 7 # 8 # http://www.apache.org/licenses/LICENSE-2.0 9 # 10 # Unless required by applicable law or agreed to in writing, software 11 # distributed under the License is distributed on an "AS IS" BASIS, 12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 # See the License for the specific language governing permissions and 14 # limitations under the License. 15 # 16 17 USER_ID = $(shell id -u) 18 BIN = dgraph 19 BUILD ?= $(shell git rev-parse --short HEAD) 20 BUILD_CODENAME ?= dgraph 21 BUILD_DATE ?= $(shell git log -1 --format=%ci) 22 BUILD_BRANCH ?= $(shell git rev-parse --abbrev-ref HEAD) 23 24 ifeq ($(DGRAPH_VERSION),) 25 BUILD_VERSION ?= local 26 else 27 # remove arch suffix from DGRAPH_VERSION for CD steps only 28 BUILD_VERSION := $(shell echo ${DGRAPH_VERSION} | cut -d "-" -f 1) 29 endif 30 31 GOOS ?= $(shell go env GOOS) 32 # Only build with jemalloc on Linux, mac 33 ifeq ($(GOOS),$(filter $(GOOS),linux darwin)) 34 BUILD_TAGS ?= jemalloc 35 endif 36 GOPATH ?= $(shell go env GOPATH) 37 38 # Build-time Go variables 39 dgraphVersion = github.com/dgraph-io/dgraph/x.dgraphVersion 40 dgraphCodename = github.com/dgraph-io/dgraph/x.dgraphCodename 41 gitBranch = github.com/dgraph-io/dgraph/x.gitBranch 42 lastCommitSHA = github.com/dgraph-io/dgraph/x.lastCommitSHA 43 lastCommitTime = github.com/dgraph-io/dgraph/x.lastCommitTime 44 45 BUILD_FLAGS ?= -ldflags '-X ${lastCommitSHA}=${BUILD} -X "${lastCommitTime}=${BUILD_DATE}" -X "${dgraphVersion}=${BUILD_VERSION}" -X "${dgraphCodename}=${BUILD_CODENAME}" -X ${gitBranch}=${BUILD_BRANCH}' 46 47 # Insert build tags if specified 48 ifneq ($(strip $(BUILD_TAGS)),) 49 BUILD_FLAGS += -tags '$(BUILD_TAGS)' 50 ifneq (,$(findstring oss,$(BUILD_TAGS))) 51 BUILD_VERSION := $(BUILD_VERSION)-oss 52 endif 53 endif 54 55 # Build with compiler optimizations disabled, which will help debugging with dlv. 56 ifneq ($(strip $(BUILD_DEBUG)),) 57 BUILD_FLAGS += -gcflags="all=-N -l" 58 endif 59 60 # Build with race detector enabled. 61 ifneq ($(strip $(BUILD_RACE)),) 62 BUILD_FLAGS += -race 63 endif 64 65 # jemalloc stuff 66 HAS_JEMALLOC = $(shell test -f /usr/local/lib/libjemalloc.a && echo "jemalloc") 67 JEMALLOC_URL = "https://github.com/jemalloc/jemalloc/releases/download/5.2.1/jemalloc-5.2.1.tar.bz2" 68 69 # go install variables 70 HAS_SHA256SUM = $(shell which sha256sum) 71 INSTALL_TARGET = $(GOPATH)/bin/$(BIN) 72 ifneq ($(strip $(shell go env GOBIN)),) 73 INSTALL_TARGET = $(shell go env GOBIN)/$(BIN) 74 endif 75 76 .PHONY: all $(BIN) 77 all: $(BIN) 78 79 $(BIN): clean jemalloc 80 @go build $(BUILD_FLAGS) -o $(BIN) 81 82 test-coverage-binary: clean jemalloc 83 @go test -c -covermode=atomic -coverpkg ../... $(BUILD_FLAGS) -o $(BIN) 84 85 clean: 86 @rm -f $(BIN) 87 88 uninstall: 89 @go clean -i -x 90 91 install: jemalloc 92 @echo "Commit SHA256: `git rev-parse HEAD`" 93 @if [ "$(HAS_SHA256SUM)" ] ; then \ 94 echo "Old SHA256:" `sha256sum $(INSTALL_TARGET) 2>/dev/null | cut -c-64` ; \ 95 fi 96 @go install $(BUILD_FLAGS) 97 @echo "Installed $(BIN) to $(INSTALL_TARGET)" 98 @if [ "$(HAS_SHA256SUM)" ] ; then \ 99 echo "New SHA256:" `sha256sum $(INSTALL_TARGET) 2>/dev/null | cut -c-64` ; \ 100 fi 101 102 jemalloc: 103 @if [ -z "$(HAS_JEMALLOC)" ] ; then \ 104 mkdir -p /tmp/jemalloc-temp && cd /tmp/jemalloc-temp ; \ 105 echo "Downloading jemalloc" ; \ 106 curl -s -L ${JEMALLOC_URL} -o jemalloc.tar.bz2 ; \ 107 tar xjf ./jemalloc.tar.bz2 ; \ 108 cd jemalloc-5.2.1 ; \ 109 ./configure --with-jemalloc-prefix='je_' --with-malloc-conf='background_thread:true,metadata_thp:auto'; \ 110 make ; \ 111 if [ "$(USER_ID)" = "0" ]; then \ 112 make install ; \ 113 else \ 114 echo "==== Need sudo access to install jemalloc" ; \ 115 sudo make install ; \ 116 fi \ 117 fi 118