1# 2# scver.mk 3# 4# This source file is part of the FoundationDB open source project 5# 6# Copyright 2013-2018 Apple Inc. and the FoundationDB project authors 7# 8# Licensed under the Apache License, Version 2.0 (the "License"); 9# you may not use this file except in compliance with the License. 10# You may obtain a copy of the License at 11# 12# http://www.apache.org/licenses/LICENSE-2.0 13# 14# Unless required by applicable law or agreed to in writing, software 15# distributed under the License is distributed on an "AS IS" BASIS, 16# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 17# See the License for the specific language governing permissions and 18# limitations under the License. 19# 20 21######################################################################### 22# 23# This makefile will define the make variables related to source control 24# variables, values, and settings 25# 26# 27# Author: Alvin Moore 28# Created: 15-08-01 29######################################################################### 30 31 32# Retrieves the major version number from a version string 33# Param: 34# 1. String to parse in form 'major[.minor][.build]'. 35MAJORVERFUNC = $(firstword $(subst ., ,$1)) 36 37# Retrieves the major version number from a version string 38# If there is no minor part in the string, returns the second argument 39# (if specified). 40# Param: 41# 1. String to parse in form 'major[.minor][.build]'. 42# 2. (optional) Fallback value. 43MINORVERFUNC = $(or $(word 2,$(subst ., ,$1)),$(value 2)) 44 45# Ensures that the specified directory is created 46# Displays a creation message, if the directory does not exists 47# Param: 48# 1. Path to the directory to create 49# 2. (optional) Display name of the directory. 50CREATEDIRFUNC = if [ ! -d "$1" ]; then echo "`date +%F_%H-%M-%S` Creating $2 directory: $1"; mkdir -p "$1"; fi 51 52 53# Make Environment Settings 54# 55ARCH := $(shell uname -m) 56MAKEDIR := $(shell dirname $(realpath $(lastword $(MAKEFILE_LIST)))) 57FDBDIR := $(abspath $(MAKEDIR)/..) 58FDBPARENTDIR := $(abspath $(FDBDIR)/..) 59FDBDIRBASE := $(shell basename $(FDBDIR)) 60USERID := $(shell id -u) 61USER := $(shell whoami) 62PROCESSID := $(shell echo "$$$$") 63 64ifeq ($(PLATFORM),osx) 65 MD5SUM=md5 66else 67 MD5SUM=md5sum 68endif 69 70 71# 72# Define the Java Variables 73# 74 75# Determine the Java compiler, if not defined 76ifndef JAVAC 77 JAVAC := $(shell which javac) 78 ifeq ($(JAVAC),) 79$(warning JAVA compiler is not installed on $(PLATFORM) $(ARCH)) 80 endif 81endif 82 83# Define the Java Flags based on Java version 84ifdef JAVAC 85 JAVAVER := $(shell bash -c 'javac -version 2>&1 | cut -d\ -f2-') 86 JAVAVERMAJOR := $(call MAJORVERFUNC,$(JAVAVER)) 87 JAVAVERMINOR := $(call MINORVERFUNC,$(JAVAVER)) 88 ifneq ($(JAVAVERMAJOR),1) 89$(warning Unable to compile source using Java version: $(JAVAVER) with compiler: $(JAVAC) on $(PLATFORM) $(ARCH)) 90 else 91 JAVAFLAGS := -Xlint -source 1.8 -target 1.8 92 endif 93endif 94 95 96# Determine active Version Control 97# 98GITPRESENT := $(wildcard $(FDBDIR)/.git) 99HGPRESENT := $(wildcard $(FDBDIR)/.hg) 100 101# Do not override version IDs if already set 102ifneq ($(VERSION_ID),) 103# Noop 104 105# Use Git, if not missing 106else ifneq ($(GITPRESENT),) 107 SCVER := $(shell cd "$(FDBDIR)" && git --version 2>/dev/null) 108 ifneq ($(SCVER),) 109 VERSION_ID := $(shell cd "$(FDBDIR)" && git rev-parse --verify HEAD) 110 SOURCE_CONTROL := GIT 111 SCBRANCH := $(shell cd "$(FDBDIR)" && git rev-parse --abbrev-ref HEAD) 112 else 113$(error Missing git executable on $(PLATFORM) ) 114 endif 115 116# Otherwise, use Mercurial 117else ifneq ($(HGPRESENT),) 118 SCVER := $(shell cd "$(FDBDIR)" && hg --version 2>/dev/null) 119 ifdef SCVER 120 VERSION_ID := $(shell cd "$(FDBDIR)" && hg id -n) 121 SOURCE_CONTROL := MERCURIAL 122 SCBRANCH := $(shell cd "$(FDBDIR)" && hg branch) 123 else 124$(error Missing hg executable on $(PLATFORM)) 125 endif 126 127# No version control system 128else 129 FDBFILES := $(shell ls -la $(FDBDIR)) 130$(error Missing source control information for source on $(PLATFORM) in directory: $(FDBDIR) with files: $(FDBFILES)) 131endif 132 133# Set the RELEASE variable based on the KVRELEASE variable. 134ifeq ($(KVRELEASE),1) 135 RELEASE := true 136endif 137 138# Define the Package Release and the File Version 139ifeq ($(RELEASE),true) 140 PKGRELEASE := 1 141else ifeq ($(PRERELEASE),true) 142 PKGRELEASE := 0.$(VERSION_ID).PRERELEASE 143else 144 PKGRELEASE := 0INTERNAL 145endif 146 147 148info: 149 @echo "Displaying Make Information" 150 @echo "Version: $(VERSION)" 151 @echo "Package: $(PACKAGE_NAME)" 152 @echo "Version ID: $(VERSION_ID)" 153 @echo "Package ID: $(PKGRELEASE)" 154 @echo "SC Branch: $(SCBRANCH)" 155 @echo "Git Dir: $(GITPRESENT)" 156 @echo "Make Dir: $(MAKEDIR)" 157 @echo "Foundation Dir: $(FDBDIR)" 158 @echo "Fdb Dir Base: $(FDBDIRBASE)" 159 @echo "User: ($(USERID)) $(USER)" 160 @echo "Java Version: ($(JAVAVERMAJOR).$(JAVAVERMINOR)) $(JAVAVER)" 161 @echo "Platform: $(PLATFORM)" 162ifdef TLS_DISABLED 163 @echo "TLS: Disabled" 164else 165 @echo "TLS: Enabled" 166endif 167 @echo "" 168