/
Makefile
71 lines (55 loc) · 1.69 KB
/
Makefile
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
# All generated files go into the BUILD directory
BUILD = build
# Apache module name
MODNAME = usdt
# DTrace provider name
PROVIDER = httpd
# Uncomment for 64-bit build
#CARCHFLAGS += -m64
CC = gcc
CSTYLE = cstyle
CFLAGS += -Wall -Werror -fPIC $(CARCHFLAGS)
CPPFLAGS += -I$(BUILD)
AP_CPPFLAGS := $(shell apxs -q CPPFLAGS) \
-I$(shell apxs -q INCLUDEDIR) -I$(shell apr-1-config --includedir)
SOLDFLAGS = -shared -fPIC
# Source layout
CSRCS = src/$(MODNAME).c
CSSRCS = $(CSRCS) src/$(PROVIDER)_provider_impl.h
CSSRCS += src/$(PROVIDER)_provider.d src/$(PROVIDER).d
SOFILE = $(BUILD)/mod_$(MODNAME).so
OBJFILES = $(CSRCS:src/%.c=$(BUILD)/%.o)
EXTRAOBJFILES = $(BUILD)/$(PROVIDER)_provider.o
all: $(SOFILE)
clean:
-rm -rf $(BUILD)
check: $(CSSRCS:%=%.cstyle)
@echo check okay
$(BUILD):
mkdir -p $(BUILD)
#
# The shared object combines the object files generated from C sources with the
# one generated by DTrace.
#
$(SOFILE): $(OBJFILES) $(EXTRAOBJFILES)
$(CC) $(SOLDFLAGS) $(LDFLAGS) -o $@ $^
#
# Object files are generated either by building the corresponding source file
# or by running "dtrace -G" on the provider file using the other object files.
#
$(BUILD)/%.o: src/%.c | $(BUILD)
$(CC) $(CFLAGS) $(CPPFLAGS) $(AP_CPPFLAGS) -c -o $@ $<
$(BUILD)/$(MODNAME).o: $(BUILD)/$(PROVIDER)_provider.h
$(BUILD)/$(PROVIDER)_provider.o: src/$(PROVIDER)_provider.d $(OBJFILES) | $(BUILD)
dtrace -xnolibs -G -o $@ -s $< $(OBJFILES)
#
# The provider header file is generated directly by "dtrace -h".
#
$(BUILD)/$(PROVIDER)_provider.h: src/$(PROVIDER)_provider.d | $(BUILD)
dtrace -xnolibs -h -o $@ -s $<
%.c.cstyle: %.c
$(CSTYLE) $<
%.h.cstyle: %.h
$(CSTYLE) $<
%.d.cstyle: %.d
$(CSTYLE) $<