Makefile 3.97 KB
Newer Older
1
2
3
include ../config.mk

# C++ Compiler Flags (use fPIC for our dynamic library)
4
CXXFLAGS = -O0 -g -Wall -Werror -Wno-unused-local-typedefs -Wno-unknown-warning-option\
5
6
	-fPIC --std=c++11 -I$(DCDBDEPLOYPATH)/include -I./include -I./include_internal\
	-I$(DCDBBASEPATH)/include/ -fmessage-length=0
7
8
9

# List of object files to build and the derived list of corresponding source files
OBJS = src/sensordatastore.o \
10
		src/cassandraBackend.o \
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
        cassandra/Cassandra.o \
        cassandra/cassandra_constants.o \
        cassandra/cassandra_types.o
SRC = $(patsubst cassandra/%,,$(OBJS:.o=.cpp))

# List of public header files necessary to use this libray
PUBHEADERS = $(shell find include -type f -iname "*.h")

# External libraries to link against
LIBS = -L$(DCDBDEPLOYPATH)/lib -lthrift -lssl -lcrypto -lpthread -lboost_system -lboost_thread

# Dynamic library building differs between Linux/BSD and MacOS
OS = $(shell uname)
ifeq ($(OS),Darwin)
	TARGET = libdcdb.dylib
	DLFLAGS = -dynamiclib
else
	TARGET = libdcdb.so
29
	DLFLAGS = -shared -Wl,-soname,$(TARGET) -Wl,--no-undefined
30
31
endif

32
33
34
# Determine the expanded path to which the library will be installed
P =	$(shell cd $(DCDBDEPLOYPATH)/lib/ && pwd) 

35
36
37
38
39
40
41
42
43
# List of Phony Targets
.PHONY : check-thrift-env all clean clean-cassandra-headers install

# Main Library Target
$(TARGET): $(SRC)
	$(MAKE) cassandra/Cassandra.h
	$(MAKE) $(OBJS)
	@if [ "$(OS)" = "Darwin" ]; then \
		echo "Linking library in Mac OS style: $(TARGET)"; \
44
		$(CXX) $(CXXFLAGS) $(DLFLAGS) -o $(TARGET) $(OBJS) $(LIBS); \
45
46
	else \
		echo "Linking library in Linux style: $(TARGET)"; \
47
		$(CXX) $(CXXFLAGS) $(DLFLAGS) -o $(TARGET) $(OBJS) $(LIBS); \
48
49
50
51
52
53
	fi

all: $(TARGET)

# Alert the user to put the necessary paths into LD_LIBRARY_PATH (or similar on other platforms)
check-thrift-env:
54
	@if [ "$(OS)" = "Darwin" ]; then \
55
56
57
58
59
	R=`echo $$DYLD_LIBRARY_PATH | grep $P`; \
	if [ "$$R" = "" ]; then \
	printf "\n******************************************\nPlease type the following line before running:\n  export DYLD_LIBRARY_PATH=$$DYLD_LIBRARY_PATH:$P\n******************************************\n"; \
	fi; \
	fi
60
	@if [ "$(OS)" = "Linux" ]; 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
	R=`echo $$LD_LIBRARY_PATH | grep $P`; \
	if [ "$$R" = "" ]; then \
	printf "\n******************************************\nPlease type the following line before running:\n  export LD_LIBRARY_PATH=$$LD_LIBRARY_PATH:$P\n******************************************\n"; \
	fi; \
	fi

# Build the Cassandra Thrift headers
cassandra/Cassandra.h:
	@if [ ! -e cassandra ]; then \
	printf "Building Thrift interface headers... "; \
	$(DCDBDEPLOYPATH)/bin/thrift --gen cpp $(DCDBDEPLOYPATH)/cassandra/interface/cassandra.thrift; \
	mv gen-cpp cassandra; \
	echo "Done."; \
	fi
	@if [ "$U" = "Linux" ]; then \
	echo "Fixing Thrift includes... "; \
	grep stdint cassandra/cassandra_types.h > /dev/null; \
	if [ "$$?" -eq "1" ]; then sed -i '1i#include <stdint.h>' cassandra/cassandra_types.h; fi;\
	grep stdint cassandra/Cassandra.h > /dev/null; \
	if [ "$$?" -eq "1" ]; then sed -i '1i#include <stdint.h>' cassandra/Cassandra.h; fi;\
	fi
	@# This is a really bad way of adding a line of text from a Makefile, but the differences between sed on Mac OS and Linux leave me with no options...
	@sed -e 's/#include "cassandra_types.h"/#include "cassandra_types.h"$$#undef VERSION/' cassandra/cassandra_constants.h > cassandra/cassandra_constants.h_newline
	@cat cassandra/cassandra_constants.h_newline | tr $$ '\n' > cassandra/cassandra_constants.h
	@rm cassandra/cassandra_constants.h_newline

87
88
89
90
91
# Build the documentation
docs:
	@echo "Creating documentation..."
	doxygen

92
# Clean everything
93
clean: clean-cassandra-headers clean-docs
94
95
96
97
98
	rm -f $(OBJS) $(TARGET)

# Clean the Cassandra headers only
clean-cassandra-headers:
	rm -rf cassandra
99
100
101
102
	
# Clean the documentation
clean-docs:
	rm -rf docs
103
104
105
106
107
108
109

# Install to deploy path
install: $(TARGET) check-thrift-env
	mkdir -p $(DCDBDEPLOYPATH)/lib
	mkdir -p $(DCDBDEPLOYPATH)/include/dcdb
	install $(TARGET) $(DCDBDEPLOYPATH)/lib/
	install $(PUBHEADERS) $(DCDBDEPLOYPATH)/include/dcdb/