github.com/unigraph-dev/dgraph@v1.1.1-0.20200923154953-8b52b426f765/dgraph/Makefile (about)

     1  #
     2  # Copyright 2018 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  BIN            = dgraph
    18  BUILD         ?= $(shell git rev-parse --short HEAD)
    19  BUILD_DATE    ?= $(shell git log -1 --format=%ci)
    20  BUILD_BRANCH  ?= $(shell git rev-parse --abbrev-ref HEAD)
    21  BUILD_VERSION ?= $(shell git describe --always --tags)
    22  BUILD_TAGS    ?=
    23  GOPATH        ?= $(shell go env GOPATH)
    24  
    25  # Build-time Go variables
    26  dgraphVersion  = github.com/dgraph-io/dgraph/x.dgraphVersion
    27  gitBranch      = github.com/dgraph-io/dgraph/x.gitBranch
    28  lastCommitSHA  = github.com/dgraph-io/dgraph/x.lastCommitSHA
    29  lastCommitTime = github.com/dgraph-io/dgraph/x.lastCommitTime
    30  
    31  BUILD_FLAGS   ?= -ldflags '-X ${lastCommitSHA}=${BUILD} -X "${lastCommitTime}=${BUILD_DATE}" -X "${dgraphVersion}=${BUILD_VERSION}" -X ${gitBranch}=${BUILD_BRANCH}'
    32  
    33  # Insert build tags if specified
    34  ifneq ($(strip $(BUILD_TAGS)),)
    35  	BUILD_FLAGS += -tags '$(BUILD_TAGS)'
    36  	ifneq (,$(findstring oss,$(BUILD_TAGS)))
    37  		BUILD_VERSION := $(BUILD_VERSION)-oss
    38  	endif
    39  endif
    40  
    41  # Build with compiler optimizations disabled, which will help debugging with dlv.
    42  ifneq ($(strip $(BUILD_DEBUG)),)
    43  	BUILD_FLAGS += -gcflags="all=-N -l"
    44  endif
    45  
    46  # Build with race detector enabled.
    47  ifneq ($(strip $(BUILD_RACE)),)
    48  	BUILD_FLAGS += -race
    49  endif
    50  
    51  .PHONY: all $(BIN)
    52  all: $(BIN)
    53  
    54  $(BIN): clean
    55  	@go build $(BUILD_FLAGS) -o $(BIN)
    56  
    57  clean:
    58  	@rm -f $(BIN)
    59  
    60  uninstall:
    61  	@go clean -i -x
    62  
    63  install:
    64  	@echo "Commit SHA256: `git rev-parse HEAD`"
    65  	@echo "Old SHA256:" `sha256sum $(GOPATH)/bin/$(BIN) 2>/dev/null | cut -c-64`
    66  	@go install $(BUILD_FLAGS)
    67  	@echo "New SHA256:" `sha256sum $(GOPATH)/bin/$(BIN) 2>/dev/null | cut -c-64`