DCDBBASEPATH ?= $(realpath $(dir $(lastword $(MAKEFILE_LIST)))/..) DCDBDEPSPATH ?= $(DCDBBASEPATH)/deps DCDBDEPLOYPATH ?= $(DCDBBASEPATH)/install FETCH = wget -c --no-check-certificate -O MD5 = $(if $(shell which md5 2>/dev/null),md5,$(if $(shell md5sum --tag Makefile 2&> /dev/null || true),md5sum --tag,openssl md5)) MAKETHREADS ?= $(if $(findstring $(shell uname),Darwin),$(shell sysctl machdep.cpu.thread_count | cut -b 27-),\ $(if $(findstring $(shell uname),Linux),$(shell cat /proc/cpuinfo | grep processor | wc -l),4)) DISTFILESNAMES = $(foreach f,$(DISTFILES),$(shell echo "$(f)" | sed 's/;.*//')) DISTFILESPATHS = $(foreach f,$(DISTFILES),$(shell echo "$(f)" | sed 's/.tar.gz;.*//' | sed 's/.zip;.*//' )) # If cross-compiling for ARM, adjust the build settings ifeq ("$(ARCH)", "arm") ifeq ("$(CROSS_COMPILE)", "") $(error "If you want to cross compile for ARM, you must set the CROSS_COMPILE variable with your cross compiler prefix") endif CROSS_COMPILE_STRP = $(CROSS_COMPILE:-=) CC = "$(CROSS_COMPILE)gcc" CXX = "$(CROSS_COMPILE)g++" CMAKE_CROSS_FLAGS = -DCMAKE_C_COMPILER=$(CC) \ -DCMAKE_CXX_COMPILER=$(CXX) \ -DCMAKE_FIND_ROOT_PATH=/usr/$(CROSS_COMPILE_STRP) \ -DCMAKE_LIBRARY_PATH=$(DCDBDEPLOYPATH)/lib \ -DCMAKE_INCLUDE_PATH=$(DCDBDEPLOYPATH)/include AUTOCONF_CROSS_FLAGS = --host=$(CROSS_COMPILE_STRP) else LRT = $(if $(findstring $(shell uname),Darwin),"","-lrt") CMAKE_CROSS_FLAGS = "" AUTOCONF_CROSS_FLAGS = "" endif CFLAGS += -I$(DCDBDEPLOYPATH)/include -O2 -g CXX11FLAGS = --std=c++11 -Wno-c99-extensions -Wno-missing-field-initializers -DBOOST_DATE_TIME_POSIX_TIME_STD_CONFIG -Wno-unused-local-typedef LDFLAGS += -L$(DCDBDEPLOYPATH)/lib -O2 -g .PHONY: all info .PRECIOUS: $(DCDBDEPSPATH)/distfiles/% $(DCDBDEPSPATH)/%/.extracted $(DCDBDEPSPATH)/%/.patched .SECONDEXPANSION: getarchive = $(filter $1%,$(DISTFILESNAMES)) gethash = $(subst $(1)|,,$(filter $(1)%,$(subst ;, ,$(DISTFILES_HASHES)))) all: $(TARGET) $(DCDBDEPSPATH): @mkdir -p $(DCDBDEPSPATH) $(DCDBDEPSPATH)/distfiles: $(DCDBDEPSPATH) @mkdir -p $(DCDBDEPSPATH)/distfiles $(DCDBDEPLOYPATH): @mkdir -p $(DCDBDEPLOYPATH) $(DCDBDEPSPATH)/distfiles/%: $(DCDBDEPSPATH)/distfiles @echo "Download $(*)" $(eval U := $(shell echo "$(DISTFILES)" | sed 's/.*$(*);//' | sed 's/ .*//')) @if [ -e $(@) ]; then \ if [ `$(MD5) $(@)|sed -e 's/.*\ //'` = $(call gethash,$(*)) ]; then \ touch $(@); \ else \ rm $(@); \ fi; \ fi @if [ ! -e $(@) ]; then \ $(FETCH) $(@) $(U); \ fi $(DCDBDEPSPATH)/%/.extracted: $(DCDBDEPSPATH)/distfiles/$$(call getarchive,%) $(eval F := $(notdir $(<))) @if [ ! -e $(@) ]; then \ printf "Verifying checksum: $(F) "; \ if [ `$(MD5) $(<)|sed -e 's/.*\ //'` = $(call gethash,$(F)) ]; then \ echo " => OK!"; \ else \ echo " => FAIL!"; \ exit 2; \ fi; \ echo Extracting: $(F); \ if [ "$(suffix $(F))" = ".gz" ]; then \ cd $(DCDBDEPSPATH) && tar xzf distfiles/$(F); \ else \ cd $(DCDBDEPSPATH) && unzip distfiles/$(F) > /dev/null; \ fi; \ fi @touch $@ $(DCDBDEPSPATH)/%/.patched: $(DCDBDEPSPATH)/%/.extracted $(eval P := $(realpath patches)) @if [ ! -e $(@) && -e $(P)/$(*).patch ]; then \ echo Patching: $(*); \ cd $(@D) && (patch -N -p1 < $(P)/$(*).patch || true); \ fi @touch $@ cleandeps: @$(foreach f,$(DISTFILESPATHS),echo "Cleaning $(f)..." && rm -rf $(DCDBDEPSPATH)/$(f) $(DCDBDEPSPATH)/$(f)_build && echo;)