common.mk 3.45 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
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):
52
53
54
	@mkdir -p $(DCDBDEPLOYPATH)/bin
	@mkdir -p $(DCDBDEPLOYPATH)/include
	@mkdir -p $(DCDBDEPLOYPATH)/lib
55
56

$(DCDBDEPSPATH)/distfiles/%: $(DCDBDEPSPATH)/distfiles
57
	@echo "Check for $(*)"
58
59
	$(eval U := $(shell echo "$(DISTFILES)" | sed 's/.*$(*);//' | sed 's/ .*//'))
	@if [ -e $(@) ]; then \
60
		if [ `$(MD5) $(@)|sed -e 's/.*\ //'` != $(call gethash,$(*)) ]; then \
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
			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;)