1export 2PLATFORM := $(shell uname) 3ARCH := $(shell uname -m) 4ifeq ("$(wildcard /etc/centos-release)", "") 5 LIBSTDCPP_HACK = 1 6else 7 LIBSTDCPP_HACK = 0 8endif 9 10TOPDIR := $(shell pwd) 11 12ifeq ($(ARCH),x86_64) 13 ARCH := x64 14else 15 $(error Not prepared to compile on $(ARCH)) 16endif 17 18MONO := $(shell which mono) 19ifeq ($(MONO),) 20 MONO := /usr/bin/mono 21endif 22 23MCS := $(shell which mcs) 24ifeq ($(MCS),) 25 MCS := $(shell which dmcs) 26endif 27ifeq ($(MCS),) 28 MCS := /usr/bin/mcs 29endif 30 31CFLAGS := -Werror -Wno-error=format -fPIC -DNO_INTELLISENSE -fvisibility=hidden -DNDEBUG=1 -Wreturn-type -fno-omit-frame-pointer 32ifeq ($(RELEASE),true) 33 CFLAGS += -DFDB_CLEAN_BUILD 34endif 35ifeq ($(NIGHTLY),true) 36 CFLAGS += -DFDB_CLEAN_BUILD 37endif 38 39BOOST_BASENAME ?= boost_1_67_0 40ifeq ($(PLATFORM),Linux) 41 PLATFORM := linux 42 43 CC ?= gcc 44 CXX ?= g++ 45 46 CXXFLAGS += -std=c++0x 47 48 BOOST_BASEDIR ?= /opt 49 TLS_LIBDIR ?= /usr/local/lib 50 DLEXT := so 51 java_DLEXT := so 52 TARGET_LIBC_VERSION ?= 2.11 53else ifeq ($(PLATFORM),Darwin) 54 PLATFORM := osx 55 56 CC := /usr/bin/clang 57 CXX := /usr/bin/clang 58 59 CFLAGS += -mmacosx-version-min=10.7 -stdlib=libc++ 60 CXXFLAGS += -mmacosx-version-min=10.7 -std=c++11 -stdlib=libc++ -msse4.2 -Wno-undefined-var-template -Wno-unknown-warning-option 61 62 .LIBPATTERNS := lib%.dylib lib%.a 63 64 BOOST_BASEDIR ?= ${HOME} 65 TLS_LIBDIR ?= /usr/local/lib 66 DLEXT := dylib 67 java_DLEXT := jnilib 68else 69 $(error Not prepared to compile on platform $(PLATFORM)) 70endif 71BOOSTDIR ?= ${BOOST_BASEDIR}/${BOOST_BASENAME} 72 73CCACHE := $(shell which ccache) 74ifneq ($(CCACHE),) 75 CCACHE_CC := $(CCACHE) $(CC) 76 CCACHE_CXX := $(CCACHE) $(CXX) 77else 78 CCACHE_CC := $(CC) 79 CCACHE_CXX := $(CXX) 80endif 81 82# Default variables don't get pushed into the environment, but scripts in build/ 83# rely on the existence of CC in the environment. 84ifeq ($(origin CC), default) 85 CC := $(CC) 86endif 87 88ACTORCOMPILER := bin/actorcompiler.exe 89 90# UNSTRIPPED := 1 91 92# Normal optimization level 93CFLAGS += -O2 94 95# Or turn off optimization entirely 96# CFLAGS += -O0 97 98# Debugging symbols are a good thing (and harmless, since we keep them 99# in external debug files) 100CFLAGS += -g 101 102# valgrind-compatibile builds are enabled by uncommenting lines in valgind.mk 103 104# Define the TLS compilation and link variables 105ifdef TLS_DISABLED 106CFLAGS += -DTLS_DISABLED 107FDB_TLS_LIB := 108TLS_LIBS := 109else 110FDB_TLS_LIB := lib/libFDBLibTLS.a 111TLS_LIBS += $(addprefix $(TLS_LIBDIR)/,libtls.a libssl.a libcrypto.a) 112endif 113 114CXXFLAGS += -Wno-deprecated -DBOOST_ERROR_CODE_HEADER_ONLY -DBOOST_SYSTEM_NO_DEPRECATED 115LDFLAGS := 116LIBS := 117STATIC_LIBS := 118 119# Add library search paths (that aren't -Llib) to the VPATH 120VPATH += $(addprefix :,$(filter-out lib,$(patsubst -L%,%,$(filter -L%,$(LDFLAGS))))) 121 122CS_PROJECTS := flow/actorcompiler flow/coveragetool fdbclient/vexillographer 123CPP_PROJECTS := flow fdbrpc fdbclient fdbbackup fdbserver fdbcli bindings/c bindings/java fdbmonitor bindings/flow/tester bindings/flow 124ifndef TLS_DISABLED 125CPP_PROJECTS += FDBLibTLS 126endif 127OTHER_PROJECTS := bindings/python bindings/ruby bindings/go 128 129CS_MK_GENERATED := $(CS_PROJECTS:=/generated.mk) 130CPP_MK_GENERATED := $(CPP_PROJECTS:=/generated.mk) 131 132MK_GENERATED := $(CS_MK_GENERATED) $(CPP_MK_GENERATED) 133 134# build/valgrind.mk needs to be included before any _MK_GENERATED (which in turn includes local.mk) 135MK_INCLUDE := build/scver.mk build/valgrind.mk $(CS_MK_GENERATED) $(CPP_MK_GENERATED) $(OTHER_PROJECTS:=/include.mk) build/packages.mk 136 137ALL_MAKEFILES := Makefile $(MK_INCLUDE) $(patsubst %/generated.mk,%/local.mk,$(MK_GENERATED)) 138 139TARGETS = 140 141.PHONY: clean all Makefiles 142 143default: fdbserver fdbbackup fdbcli fdb_c fdb_python fdb_python_sdist 144 145all: $(CS_PROJECTS) $(CPP_PROJECTS) $(OTHER_PROJECTS) 146 147# These are always defined and ready to use. Any target that uses them and needs them up to date 148# should depend on versions.target 149VERSION := $(shell cat versions.target | grep '<Version>' | sed -e 's,^[^>]*>,,' -e 's,<.*,,') 150PACKAGE_NAME := $(shell cat versions.target | grep '<PackageName>' | sed -e 's,^[^>]*>,,' -e 's,<.*,,') 151 152versions.h: Makefile versions.target 153 @rm -f $@ 154ifeq ($(RELEASE),true) 155 @echo "#define FDB_VT_VERSION \"$(VERSION)\"" >> $@ 156else 157 @echo "#define FDB_VT_VERSION \"$(VERSION)-PRERELEASE\"" >> $@ 158endif 159 @echo "#define FDB_VT_PACKAGE_NAME \"$(PACKAGE_NAME)\"" >> $@ 160 161bindings: fdb_c fdb_python fdb_ruby fdb_java fdb_flow fdb_flow_tester fdb_go fdb_go_tester fdb_c_tests 162 163Makefiles: $(MK_GENERATED) 164 165$(CS_MK_GENERATED): build/csprojtom4.py build/csproj.mk Makefile 166 @echo "Creating $@" 167 @python build/csprojtom4.py $(@D)/*.csproj | m4 -DGENDIR="$(@D)" -DGENNAME=`basename $(@D)/*.csproj .csproj` - build/csproj.mk > $(@D)/generated.mk 168 169$(CPP_MK_GENERATED): build/vcxprojtom4.py build/vcxproj.mk Makefile 170 @echo "Creating $@" 171 @python build/vcxprojtom4.py $(@D)/*.vcxproj | m4 -DGENDIR="$(@D)" -DGENNAME=`basename $(@D)/*.vcxproj .vcxproj` - build/vcxproj.mk > $(@D)/generated.mk 172 173DEPSDIR := .deps 174OBJDIR := .objs 175CMDDIR := .cmds 176 177COMPILE_COMMANDS_JSONS := $(addprefix $(CMDDIR)/,$(addsuffix /compile_commands.json,${CPP_PROJECTS})) 178compile_commands.json: build/concatinate_jsons.py ${COMPILE_COMMANDS_JSONS} 179 @build/concatinate_jsons.py ${COMPILE_COMMANDS_JSONS} 180 181include $(MK_INCLUDE) 182 183clean: $(CLEAN_TARGETS) docpreview_clean 184 @echo "Cleaning toplevel" 185 @rm -rf $(OBJDIR) 186 @rm -rf $(DEPSDIR) 187 @rm -rf lib/ 188 @rm -rf bin/coverage.*.xml 189 @rm -rf $(CMDDIR) compile_commands.json 190 @find . -name "*.g.cpp" -exec rm -f {} \; -or -name "*.g.h" -exec rm -f {} \; 191 192targets: 193 @echo "Available targets:" 194 @for i in $(sort $(TARGETS)); do echo " $$i" ; done 195 @echo "Append _clean to clean specific target." 196 197lib/libstdc++.a: $(shell $(CC) -print-file-name=libstdc++_pic.a) 198 @echo "Frobnicating $@" 199 @mkdir -p lib 200 @rm -rf .libstdc++ 201 @mkdir .libstdc++ 202 @(cd .libstdc++ && ar x $<) 203 @for i in .libstdc++/*.o ; do \ 204 nm $$i | grep -q \@ || continue ; \ 205 nm $$i | awk '$$3 ~ /@@/ { COPY = $$3; sub(/@@.*/, "", COPY); print $$3, COPY; }' > .libstdc++/replacements ; \ 206 objcopy --redefine-syms=.libstdc++/replacements $$i $$i.new && mv $$i.new $$i ; \ 207 rm .libstdc++/replacements ; \ 208 nm $$i | awk '$$3 ~ /@/ { print $$3; }' > .libstdc++/deletes ; \ 209 objcopy --strip-symbols=.libstdc++/deletes $$i $$i.new && mv $$i.new $$i ; \ 210 rm .libstdc++/deletes ; \ 211 done 212 @ar rcs $@ .libstdc++/*.o 213 @rm -r .libstdc++ 214 215 216docpreview: javadoc 217 @echo "Generating docpreview" 218 @TARGETS= $(MAKE) -C documentation docpreview 219 220docpreview_clean: 221 @echo "Cleaning docpreview" 222 @CLEAN_TARGETS= $(MAKE) -C documentation -s --no-print-directory docpreview_clean 223 224packages/foundationdb-docs-$(VERSION).tar.gz: FORCE javadoc 225 @echo "Packaging documentation" 226 @TARGETS= $(MAKE) -C documentation docpackage 227 @mkdir -p packages 228 @rm -f packages/foundationdb-docs-$(VERSION).tar.gz 229 @cp documentation/sphinx/.dist/foundationdb-docs-$(VERSION).tar.gz packages/foundationdb-docs-$(VERSION).tar.gz 230 231docpackage: packages/foundationdb-docs-$(VERSION).tar.gz 232 233FORCE: 234 235.SECONDEXPANSION: 236 237bin/coverage.%.xml: bin/coveragetool.exe $$(%_ALL_SOURCES) 238 @echo "Creating $@" 239 @$(MONO) bin/coveragetool.exe $@ $(filter-out $<,$^) >/dev/null 240 241$(CPP_MK_GENERATED): $$(@D)/*.vcxproj 242 243$(CS_MK_GENERATED): $$(@D)/*.csproj 244