File: Makefile

package info (click to toggle)
grok 1.20110708.1-4.3
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 2,460 kB
  • sloc: ansic: 3,469; ruby: 987; makefile: 276; sh: 124; yacc: 106
file content (291 lines) | stat: -rw-r--r-- 8,122 bytes parent folder | download | duplicates (2)
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
52
53
54
55
56
57
58
59
60
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
PACKAGE=grok

PLATFORM=$(shell (uname -o || uname -s) | tr -d "/" 2> /dev/null)
FLEX?=flex

FORCE_FLEX?=0

ifeq ($(PLATFORM), FreeBSD)
PREFIX?=/usr/local
else
PREFIX?=/usr
endif

ifeq ($(PLATFORM), Darwin)
LIBSUFFIX=dylib
else
LIBSUFFIX=so
endif

# On FreeBSD, you may want to set GPERF=/usr/local/bin/gperf since
# the base system gperf is too old.
ifeq ($(PLATFORM), FreeBSD)
GPERF?=/usr/local/bin/gperf
else
GPERF?=/usr/bin/gperf
endif

# For linux, we need libdl for dlopen()
# On FreeBSD, comment this line out.
ifeq ($(PLATFORM), GNULinux)
LDFLAGS+=-ldl
endif

# For GNU/kFreeBSD, we also need libdl
ifeq ($(PLATFORM), GNUkFreeBSD)
LDFLAGS+=-ldl
endif

# For GNU/Hurd, we need libdl for dlopen()
ifeq ($(PLATFORM), GNU)
LDFLAGS+=-ldl
endif

# #############################################
# You probably don't need to make changes below

BASE?=.
MAJOR=$(shell sh $(BASE)/version.sh --major)
VERSION=$(shell sh $(BASE)/version.sh)

#CFLAGS+=-g
#LDFLAGS+=-g

CFLAGS+=-pipe -fPIC -I. -O2
LDFLAGS+=-lpcre -levent -rdynamic -ltokyocabinet

LIBSUFFIX=$(shell sh $(BASE)/platform.sh libsuffix)
VERLIBSUFFIX=$(shell sh $(BASE)/platform.sh libsuffix $(MAJOR))
DYNLIBFLAG=$(shell sh $(BASE)/platform.sh dynlibflag)
LIBNAMEFLAG=$(shell sh $(BASE)/platform.sh libnameflag $(MAJOR) $(INSTALLLIB))

# Sane includes
CFLAGS+=-I/usr/local/include
LDFLAGS+=-L/usr/local/lib

# Platform so we know what to dlopen
CFLAGS+=-DPLATFORM_$(PLATFORM)
# Uncomment to totally disable logging features
#CFLAGS+=-DNOLOGGING

EXTRA_CFLAGS?=
EXTRA_LDFLAGS?=
CFLAGS+=$(EXTRA_CFLAGS)
LDFLAGS+=$(EXTRA_LDFLAGS)

### End of user-servicable configuration

CLEANGEN=filters.c grok_matchconf_macro.c *.yy.c *.tab.c *.tab.h
CLEANOBJ=*.o *_xdr.[ch]
CLEANBIN=main grokre grok conftest grok_program
CLEANVER=VERSION grok_version.h grok.spec

GROKOBJ=grok.o grokre.o grok_capture.o grok_pattern.o stringhelper.o \
        predicates.o grok_capture_xdr.o grok_match.o grok_logging.o \
        grok_program.o grok_input.o grok_matchconf.o libc_helper.o \
        grok_matchconf_macro.o filters.o grok_discover.o
GROKPROGOBJ=grok_input.o grok_program.o grok_matchconf.o $(GROKOBJ)

GROKHEADER=grok.h grok_pattern.h grok_capture.h grok_capture_xdr.h \
           grok_match.h grok_logging.h grok_discover.h

# grok_version.h is generated by make.
GROKHEADER+=grok_version.h

.PHONY: all
all: grok discogrok libgrok.$(LIBSUFFIX) libgrok.$(VERLIBSUFFIX)

.PHONY: package create-package test-package update-version
package: 
	$(MAKE) $(MAKEFLAGS) create-package 
	$(MAKE) $(MAKEFLAGS) test-package 

install: libgrok.$(LIBSUFFIX) grok discogrok $(GROKHEADER)
	install -d $(DESTDIR)$(PREFIX)/bin
	install -d $(DESTDIR)$(PREFIX)/lib
	install -d $(DESTDIR)$(PREFIX)/include
	install -m 755 grok $(DESTDIR)$(PREFIX)/bin
	install -m 755 discogrok $(DESTDIR)$(PREFIX)/bin
	install -m 644 libgrok.$(LIBSUFFIX) $(DESTDIR)$(PREFIX)/lib
	for header in $(GROKHEADER); do \
		install -m 644 $$header $(DESTDIR)$(PREFIX)/include; \
	done 
	install -d $(DESTDIR)$(PREFIX)/share/grok
	install -d $(DESTDIR)$(PREFIX)/share/grok/patterns
	install patterns/base $(DESTDIR)$(PREFIX)/share/grok/patterns/

uninstall:
	rm -f $(DESTDIR)$(PREFIX)/bin/grok
	rm -f $(DESTDIR)$(PREFIX)/bin/discogrok
	rm -f $(DESTDIR)$(PREFIX)/lib/libgrok.$(LIBSUFFIX)
	for header in $(GROKHEADER); do \
		rm -f $(DESTDIR)$(PREFIX)/include/$$header; \
	done 
	rm -f $(DESTDIR)$(PREFIX)/share/grok/patterns/*

pre-create-package:
	rm -f VERSION grok_version.h

create-package: pre-create-package 
	$(MAKE) VERSION grok_version.h grok.spec
	PACKAGE=$(PACKAGE) sh package.sh $(VERSION)

test-package:
	PKGVER=$(PACKAGE)-$(VERSION); \
	tar -C /tmp -zxf $${PKGVER}.tar.gz; \
	echo "Running C tests..." && $(MAKE) -C /tmp/$${PKGVER}/test test-c

.PHONY: clean 
clean: cleanobj cleanbin

# reallyreallyclean also purges generated files
# we don't clean generated files in 'clean' target
# because some systems don't have the tools to regenerate
# the data, such as FreeBSD which has the wrong flavor
# of flex (not gnu flex)
.PHONY: reallyreallyclean
reallyreallyclean: reallyclean cleangen

.PHONY: reallyclean
reallyclean: clean cleanver

.PHONY: cleanobj
cleanobj:
	rm -f $(CLEANOBJ)

.PHONY: cleanbin
cleanbin:
	rm -f $(CLEANBIN)

.PHONY: cleangen
cleangen:
	rm -f $(CLEANGEN)

.PHONY: cleanver
cleanver:
	rm -f $(CLEANVER)

#.PHONY: test
#test:
	#$(MAKE) -C test test

# Binary creation
grok: LDFLAGS+=-levent
grok: $(GROKOBJ) conf.tab.o conf.yy.o main.o grok_config.o
	$(CC) $(LDFLAGS) $^ -o $@

discogrok: $(GROKOBJ) discover_main.o
	$(CC) $(LDFLAGS) $^ -o $@

libgrok.$(LIBSUFFIX): 
libgrok.$(LIBSUFFIX): $(GROKOBJ) 
	$(CC) $(LDFLAGS) -fPIC $(DYNLIBFLAG) $(LIBNAMEFLAG) $^ -o $@

libgrok.$(VERLIBSUFFIX): libgrok.$(LIBSUFFIX);
	ln -s $< $@

# File dependencies
# generated with: 
# for i in *.c; do grep '#include "' $i | fex '"2' | xargs | sed -e "s/^/$i: /"; done    
grok.h: grok_version.h
grok.c: grok.h
grok_capture.c: grok.h grok_capture.h grok_capture_xdr.h
grok_capture_xdr.c: grok_capture.h
grok_config.c: grok_input.h grok_config.h grok_matchconf.h grok_logging.h
grok_input.c: grok.h grok_program.h grok_input.h grok_matchconf.h grok_logging.h libc_helper.h
grok_logging.c: grok.h
grok_match.c: grok.h
grok_matchconf.c: grok.h grok_matchconf.h grok_matchconf_macro.h grok_logging.h libc_helper.h filters.h stringhelper.h
grok_pattern.c: grok.h grok_pattern.h
grok_program.c: grok.h grok_program.h grok_input.h grok_matchconf.h
grokre.c: grok.h predicates.h stringhelper.h grok_version.h
libc_helper.c: libc_helper.h
main.c: grok.h grok_program.h grok_config.h conf.tab.h
predicates.c: grok_logging.h predicates.h
stringhelper.c: stringhelper.h
filters.h: grok.h
grok.h: grok_logging.h grok_pattern.h grok_capture.h grok_match.h
grok_capture.h: grok_capture_xdr.h
grok_config.h: grok_program.h
grok_input.h: grok_program.h
grok_match.h: grok_capture_xdr.h
grok_matchconf.h: grok.h grok_input.h grok_program.h
predicates.h: grok.h


# Output generation
grok_capture_xdr.o: grok_capture_xdr.c grok_capture_xdr.h
grok_capture_xdr.c: grok_capture.x
	[ -f $@ ] && rm $@ || true
	rpcgen -c $< -o $@
grok_capture_xdr.h: grok_capture.x
	[ -f $@ ] && rm $@ || true
	rpcgen -h $< -o $@

%.c: %.gperf
	@if $(GPERF) --version | head -1 | egrep -v '3\.(0\.[3-9]+|[1-9]+)' ; then \
		echo "We require gperf version >= 3.0.3" ; \
		exit 1; \
	fi
	$(GPERF) $< > $@

conf.tab.c conf.tab.h: conf.y
	bison -d $<

conf.yy.c: conf.lex conf.tab.h
	@if $(FLEX) --version | grep '^flex version' ; then \
		if [ "$(FORCE_FLEX)" -eq 1 ] ; then \
			echo "Bad version of flex detected, but FORCE_FLEX is set, trying anyway."; \
			exit 0; \
		fi; \
		echo "Fatal - cannot build"; \
		echo "You need GNU flex. You seem to have BSD flex?"; \
		strings `which flex` | grep Regents; \
		echo "If you want to try your flex, anyway, set FORCE_FLEX=1"; \
		exit 1; \
	fi
	$(FLEX) -o $@ $<

.c.o:
	$(CC) -c $(CFLAGS) $< -o $@

%.1: %.pod
	pod2man -c "" -r "" $< $@

grok_version.h:
	sh $(BASE)/version.sh --header > $@

VERSION:
	sh $(BASE)/version.sh --shell > $@

grok.spec: grok.spec.template VERSION
	. ./VERSION;
	sed -e "s/^Version: .*/Version: $(VERSION)/" grok.spec.template > grok.spec


.PHONY: docs
docs:
	doxygen

.PHONY: package-debian
package-debian: debian
	CFLAGS="$(CFLAGS)" debuild -uc -us

package-debian-clean:
	rm -r debian || true

debian:
	dh_make -s -n -c bsd -e $$USER -p grok_$(VERSION) < /dev/null
	sed -i -e "s/Build-Depends:.*/&, bison, ctags, flex, gperf, libevent-dev, libpcre3-dev, libtokyocabinet-dev/" debian/control
	sed -i -e "s/Depends:.*/&, libevent-1.4-2 (>= 1.3), libtokyocabinet8 (>= 1.4.9), libpcre3 (>= 7.6)/" debian/control
	sed -i -e "s/^Description:.*/Description: A powerful pattern-matching and reacting tool./" debian/control
	sed -i -e "/^Description/,$$ { /^ *$$/d }" debian/control
	echo '#!/bin/sh' > debian/postinst
	echo '[ "$$1" = "configure" ] && ldconfig' >> debian/postinst
	echo 'exit 0' >> debian/postinst
	echo '#!/bin/sh' > debian/postrm
	echo '[ "$$1" = "remove" ] && ldconfig' >> debian/postrm
	echo 'exit 0' >> debian/postrm
	chmod 755 debian/postinst debian/postrm