Put the objects before the libraries when building
[nmdb.git] / nmdb / Makefile
blob4f7f870021a34932f41fa7619a8b9fa0d6c9a464
2 # Protocols to enable
3 ENABLE_TCP = 1
4 ENABLE_UDP = 1
5 ENABLE_TIPC := $(shell if echo "\#include <linux/tipc.h>" | \
6 $(CPP) - > /dev/null 2>&1; then echo 1; else echo 0; fi)
7 ENABLE_SCTP := $(shell if echo "\#include <netinet/sctp.h>" | \
8 $(CPP) - > /dev/null 2>&1; then echo 1; else echo 0; fi)
10 # Backends to enable
11 BE_ENABLE_QDBM := $(shell if `pkg-config --exists qdbm`; \
12 then echo 1; else echo 0; fi)
13 BE_ENABLE_BDB := $(shell if echo "\#include <db.h>" | \
14 $(CPP) - > /dev/null 2>&1; then echo 1; else echo 0; fi)
15 BE_ENABLE_TC := $(shell if `pkg-config --exists tokyocabinet`; \
16 then echo 1; else echo 0; fi)
17 BE_ENABLE_TDB := $(shell if `pkg-config --exists tdb`; \
18 then echo 1; else echo 0; fi)
19 BE_ENABLE_NULL := 1
22 CFLAGS += -std=c99 -pedantic -Wall -O3
23 ALL_CFLAGS = -D_XOPEN_SOURCE=600 $(CFLAGS)
24 ALL_CFLAGS += -DENABLE_TIPC=$(ENABLE_TIPC) \
25 -DENABLE_TCP=$(ENABLE_TCP) \
26 -DENABLE_UDP=$(ENABLE_UDP) \
27 -DENABLE_SCTP=$(ENABLE_SCTP) \
28 -DBE_ENABLE_QDBM=$(BE_ENABLE_QDBM) \
29 -DBE_ENABLE_BDB=$(BE_ENABLE_BDB) \
30 -DBE_ENABLE_TC=$(BE_ENABLE_TC) \
31 -DBE_ENABLE_TDB=$(BE_ENABLE_TDB) \
32 -DBE_ENABLE_NULL=$(BE_ENABLE_NULL) \
35 ifdef DEBUG
36 ALL_CFLAGS += -g
37 endif
39 ifdef PROFILE
40 ALL_CFLAGS += -g -pg -ftest-coverage -fprofile-generate
41 endif
43 ifdef PROFILE_USE
44 ALL_CFLAGS += -fprofile-use
45 endif
48 # prefix for installing the binaries
49 PREFIX=/usr/local
52 OBJS = cache.o dbloop.o queue.o log.o net.o netutils.o parse.o stats.o main.o \
53 be.o be-bdb.o be-null.o be-qdbm.o be-tc.o be-tdb.o
54 LIBS = -levent -lpthread -lrt
57 ifeq ($(ENABLE_TIPC), 1)
58 OBJS += tipc.o
59 else
60 OBJS += tipc-stub.o
61 endif
63 ifeq ($(ENABLE_TCP), 1)
64 OBJS += tcp.o
65 else
66 OBJS += tcp-stub.o
67 endif
69 ifeq ($(ENABLE_UDP), 1)
70 OBJS += udp.o
71 else
72 OBJS += udp-stub.o
73 endif
75 ifeq ($(ENABLE_SCTP), 1)
76 OBJS += sctp.o
77 else
78 OBJS += sctp-stub.o
79 endif
82 ifeq ($(BE_ENABLE_QDBM), 1)
83 ALL_CFLAGS += `pkg-config qdbm --cflags`
84 LIBS += `pkg-config qdbm --libs-only-L` -lqdbm
85 endif
86 ifeq ($(BE_ENABLE_BDB), 1)
87 LIBS += -ldb
88 endif
89 ifeq ($(BE_ENABLE_TC), 1)
90 ALL_CFLAGS += `pkg-config tokyocabinet --cflags`
91 LIBS += `pkg-config tokyocabinet --libs`
92 endif
93 ifeq ($(BE_ENABLE_TDB), 1)
94 ALL_CFLAGS += `pkg-config tdb --cflags`
95 LIBS += `pkg-config tdb --libs`
96 endif
97 ifeq ($(BE_ENABLE_NULL), 1)
98 endif
101 ifneq ($(V), 1)
102 NICE_CC = @echo " CC $@"; $(CC)
103 else
104 NICE_CC = $(CC)
105 endif
108 default: all
110 all: nmdb
112 nmdb: $(OBJS)
113 $(NICE_CC) $(ALL_CFLAGS) $(OBJS) $(LIBS) -o nmdb
115 .c.o:
116 $(NICE_CC) $(ALL_CFLAGS) -c $< -o $@
118 install-bin: nmdb
119 install -d $(PREFIX)/bin
120 install -m 0755 nmdb $(PREFIX)/bin
122 install-man:
123 install -d $(PREFIX)/man/man1
124 install -m 0644 nmdb.1 $(PREFIX)/man/man1/
126 install: install-bin install-man
128 clean: clean-build clean-prof
130 clean-build:
131 rm -f $(OBJS) nmdb
133 clean-prof:
134 rm -f *.bb *.bbg *.da *.gcov *.gcda *.gcno gmon.out
136 .PHONY: default all \
137 install-bin install-man install \
138 clean-build clean-prof clean