Makefile 3.73 KB
Newer Older
Julian Ospald's avatar
Julian Ospald committed
1
2
3
### toolchain
#
CC ?= gcc
Olivier Mehani's avatar
Olivier Mehani committed
4

Julian Ospald's avatar
Julian Ospald committed
5
6
7
PKG_CONFIG ?= pkg-config
XML2_CONFIG ?= xml2-config
LIBGCRYPT_CONFIG ?= libgcrypt-config
Olivier Mehani's avatar
Olivier Mehani committed
8

Julian Ospald's avatar
Julian Ospald committed
9
10
11
12
13
14
15
16
MKDIR = mkdir
MKDIR_P = mkdir -p
INSTALL = install
INSTALL_LIB = $(INSTALL) -m 755
INSTALL_DIR = $(INSTALL) -d -m 755
RM = rm
RM_RF = $(RM) -rf
CMAKE ?= cmake
17
CMAKE_FLAGS = -DCMAKE_BUILD_TYPE=Debug -DCMAKE_C_FLAGS=-fPIC
Julian Ospald's avatar
Julian Ospald committed
18
19
20

### flags
#
21
22
23
GLIB_CFLAGS ?= $(shell $(PKG_CONFIG) --cflags glib-2.0)
GLIB_LDFLAGS ?= $(shell $(PKG_CONFIG) --libs glib-2.0)

Olivier Mehani's avatar
Olivier Mehani committed
24
25
26
LIBPURPLE_CFLAGS=$(shell $(PKG_CONFIG) --cflags purple)
LIBPURPLE_LDFLAGS=$(shell $(PKG_CONFIG) --cflags purple) \
		    -L$(shell $(PKG_CONFIG) --variable=plugindir purple)
27
28
29
30
31
		    
XML2_CFLAGS ?= $(shell $(XML2_CONFIG) --cflags)
XML2_LDFLAGS ?= $(shell $(XML2_CONFIG) --libs)

LIBGCRYPT_LDFLAGS ?= $(shell $(LIBGCRYPT_CONFIG) --libs)
Olivier Mehani's avatar
Olivier Mehani committed
32
33
34
35
36

PKGCFG_C=$(GLIB_CFLAGS) \
	 $(LIBPURPLE_CFLAGS) \
	 $(XML2_CFLAGS)

37
38
39

PKGCFG_L=$(shell $(PKG_CONFIG) --libs sqlite3 mxml) \
 	$(GLIB_LDFLAGS) \
Olivier Mehani's avatar
Olivier Mehani committed
40
41
42
43
	 $(LIBPURPLE_LDFLAGS) \
	 $(XML2_LDFLAGS) \
	 $(LIBGCRYPT_LDFLAGS)

44
ifneq ("$(wildcard /etc/redhat-release)","")
Olivier Mehani's avatar
Olivier Mehani committed
45
	LJABBER= -lxmpp
46
47
48
else
ifneq ("$(wildcard /etc/SuSE-release)","")
	LJABBER= -lxmpp
49
50
51
else
	LJABBER= -ljabber
endif
52
endif
Julian Ospald's avatar
Julian Ospald committed
53
54
55

HEADERS=-I$(HDIR)/jabber -I$(LOMEMO_SRC) -I$(AXC_SRC) -I$(AX_DIR)/src
CFLAGS += -std=c11 -Wall -g -Wstrict-overflow $(PKGCFG_C) $(HEADERS)
56
PLUGIN_CPPFLAGS=-DPURPLE_PLUGINS
57
58
# -D_BSD_SOURCE can be removed once nobody uses glibc <= 2.18 any more
CPPFLAGS += -D_XOPEN_SOURCE=700 -D_BSD_SOURCE -D_DEFAULT_SOURCE
59
LDFLAGS += -ldl -lm $(PKGCFG_L) $(LJABBER) -Wl,-rpath,$(PURPLE_PLUGIN_DIR)
Julian Ospald's avatar
Julian Ospald committed
60
61
62
63
64
65


### directories
#
PURPLE_HOME_PLUGIN_DIR=$(HOME)/.purple/plugins
PURPLE_PLUGIN_DIR = $(shell $(PKG_CONFIG) --variable=plugindir purple)
Richard Bayerle's avatar
Richard Bayerle committed
66
67

LDIR=./lib
68
69
70
BDIR=./build
SDIR=./src
HDIR=./headers
Richard Bayerle's avatar
Richard Bayerle committed
71

72
73
74
TARBALL_DIR_NAME=tarball
TARBALL_FILE_NAME=lurch-0.0.0-src.tar.gz

Richard Bayerle's avatar
Richard Bayerle committed
75
76
77
LOMEMO_DIR=$(LDIR)/libomemo
LOMEMO_SRC=$(LOMEMO_DIR)/src
LOMEMO_BUILD=$(LOMEMO_DIR)/build
78
LOMEMO_PATH=$(LOMEMO_BUILD)/libomemo-conversations.a
Richard Bayerle's avatar
Richard Bayerle committed
79
80
81
82

AXC_DIR=$(LDIR)/axc
AXC_SRC=$(AXC_DIR)/src
AXC_BUILD=$(AXC_DIR)/build
Richard Bayerle's avatar
Richard Bayerle committed
83
AXC_PATH=$(AXC_BUILD)/libaxc-nt.a
84

85
86
AX_DIR=$(AXC_DIR)/lib/libsignal-protocol-c
AX_PATH=$(AX_DIR)/build/src/libsignal-protocol-c.a
87

88
VENDOR_LIBS=$(LOMEMO_PATH) $(AXC_PATH) $(AX_PATH)
Richard Bayerle's avatar
Richard Bayerle committed
89

90

Julian Ospald's avatar
Julian Ospald committed
91
92
### make rules
#
93
all: $(BDIR)/lurch.so
Richard Bayerle's avatar
Richard Bayerle committed
94

95
$(BDIR):
Julian Ospald's avatar
Julian Ospald committed
96
97
	$(MKDIR_P) build

98
$(AX_PATH):
99
	cd $(AX_DIR)/ && \
Julian Ospald's avatar
Julian Ospald committed
100
101
102
103
104
	   $(MKDIR_P) build && \
	   cd build && \
	   $(CMAKE) $(CMAKE_FLAGS) .. \
	   && $(MAKE)

105
$(AXC_PATH):
Julian Ospald's avatar
Julian Ospald committed
106
107
	$(MAKE) -C "$(AXC_DIR)" build/libaxc-nt.a

108
$(LOMEMO_PATH):
Julian Ospald's avatar
Julian Ospald committed
109
110
	$(MAKE) -C "$(LOMEMO_DIR)" build/libomemo-conversations.a

111
$(BDIR)/%.o: $(SDIR)/%.c | $(BDIR)
112
	$(CC) -fPIC $(CFLAGS) $(CPPFLAGS) $(PLUGIN_CPPFLAGS) -c $(SDIR)/$*.c -o $@
Olivier Mehani's avatar
Olivier Mehani committed
113

114
115
116
$(BDIR)/lurch.so: $(BDIR)/lurch.o $(VENDOR_LIBS)
	$(CC) -fPIC -shared $(CFLAGS) $(CPPFLAGS) $(PLUGIN_CPPFLAGS) \
		"$(BDIR)/lurch.o" $(VENDOR_LIBS) \
Julian Ospald's avatar
Julian Ospald committed
117
		-o $@ $(LDFLAGS)
118
$(BDIR)/lurch.a: $(BDIR)/lurch.o $(VENDOR_LIBS)
Olivier Mehani's avatar
Olivier Mehani committed
119
	$(AR) rcs $@ $^
Julian Ospald's avatar
Julian Ospald committed
120

121
install: $(BDIR)/lurch.so
Julian Ospald's avatar
Julian Ospald committed
122
123
124
125
126
127
128
129
	[ -e "$(DESTDIR)/$(PURPLE_PLUGIN_DIR)" ] || \
		$(INSTALL_DIR) "$(DESTDIR)/$(PURPLE_PLUGIN_DIR)"
	$(INSTALL_LIB) "$(BDIR)/lurch.so" "$(DESTDIR)/$(PURPLE_PLUGIN_DIR)/lurch.so"

install-home: $(BDIR)/lurch.so
	[ -e "$(PURPLE_HOME_PLUGIN_DIR)" ] || \
		$(INSTALL_DIR) "$(PURPLE_HOME_PLUGIN_DIR)"
	$(INSTALL_LIB) "$(BDIR)/lurch.so" "$(PURPLE_HOME_PLUGIN_DIR)/lurch.so"
Richard Bayerle's avatar
Richard Bayerle committed
130

131
132
133
134
135
136
137
138
tarball: clean-all
	$(MAKE) -C "$(AXC_DIR)" clean-all
	$(MKDIR) tarball
	-cp -r . tarball/
	#rsync -av --progress . tarball/ --exclude tarball/
	-find tarball/ -name "*.git*" -exec rm -rf "{}" \;
	cd $(TARBALL_DIR_NAME)/ && tar czf ../$(TARBALL_FILE_NAME) * --exclude $(TARBALL_DIR_NAME) && cd .. && mv $(TARBALL_FILE_NAME) $(TARBALL_DIR_NAME)/

Richard Bayerle's avatar
Richard Bayerle committed
139
clean:
Julian Ospald's avatar
Julian Ospald committed
140
	$(RM_RF) "$(BDIR)"
141
	$(RM_RF) "./$(TARBALL_DIR_NAME)"
Julian Ospald's avatar
Julian Ospald committed
142
143
144

clean-all: clean
	$(MAKE) -C "$(LOMEMO_DIR)" clean
145
	$(MAKE) -C "$(AXC_DIR)" clean-all
Julian Ospald's avatar
Julian Ospald committed
146

147
.PHONY: clean clean-all install install-home tarball
Julian Ospald's avatar
Julian Ospald committed
148