9 MAKEFLAGS
+= --no-print-directory
12 # Makefiles suck: This macro sets a default value of $(2) for the
13 # variable named by $(1), unless the variable has been set by
14 # environment or command line. This is necessary for CC and AR
15 # because make sets default values, so the simpler ?= approach
16 # won't work as expected.
18 $(if
$(or
$(findstring environment
,$(origin $(1))),\
19 $(findstring command line
,$(origin $(1)))),,\
23 # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
24 $(call allow-override
,CC
,$(CROSS_COMPILE
)gcc
)
25 $(call allow-override
,AR
,$(CROSS_COMPILE
)ar)
26 $(call allow-override
,NM
,$(CROSS_COMPILE
)nm
)
31 # Use DESTDIR for installing into a different root directory.
32 # This is useful for building a package. The program will be
33 # installed in this directory as if it was the root directory.
34 # Then the build tool can move it later.
36 DESTDIR_SQ
= '$(subst ','\'',$(DESTDIR
))'
38 LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
40 libdir_relative = lib64
46 libdir = $(prefix)/$(libdir_relative)
47 man_dir = $(prefix)/share/man
48 man_dir_SQ = '$(subst ','\'',$(man_dir))'
50 export man_dir man_dir_SQ INSTALL
51 export DESTDIR DESTDIR_SQ
55 # Set plugin_dir to preffered global plugin location
56 # If we install under $HOME directory we go under
57 # $(HOME)/.traceevent/plugins
59 # We dont set PLUGIN_DIR in case we install under $HOME
60 # directory, because by default the code looks under:
61 # $(HOME)/.traceevent/plugins by default.
64 ifeq ($(prefix),$(HOME
))
65 override plugin_dir
= $(HOME
)/.traceevent
/plugins
68 override plugin_dir
= $(libdir)/traceevent
/plugins
72 ifeq ($(set_plugin_dir
),1)
73 PLUGIN_DIR
= -DPLUGIN_DIR
="$(plugin_dir)"
74 PLUGIN_DIR_SQ
= '$(subst ','\'',$(PLUGIN_DIR
))'
77 include ../../scripts/Makefile.include
79 # copy a bit from Linux kbuild
81 ifeq ("$(origin V)", "command line")
89 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
90 srctree := $(patsubst %/,%,$(dir $(srctree)))
91 srctree := $(patsubst %/,%,$(dir $(srctree)))
92 #$(info Determined 'srctree
' to be $(srctree))
95 export prefix libdir src obj
98 libdir_SQ = $(subst ','\'',$(libdir))
99 libdir_relative_SQ
= $(subst ','\'',$(libdir_relative))
100 plugin_dir_SQ = $(subst ','\'',$(plugin_dir
))
106 VERSION
= $(EP_VERSION
)
107 PATCHLEVEL
= $(EP_PATCHLEVEL
)
108 EXTRAVERSION
= $(EP_EXTRAVERSION
)
113 EVENT_PARSE_VERSION
= $(EP_VERSION
).
$(EP_PATCHLEVEL
).
$(EP_EXTRAVERSION
)
115 LIB_TARGET
= libtraceevent.a libtraceevent.so.
$(EVENT_PARSE_VERSION
)
116 LIB_INSTALL
= libtraceevent.a libtraceevent.so
*
118 INCLUDES
= -I.
-I
$(srctree
)/tools
/include $(CONFIG_INCLUDES
)
120 # Set compile option CFLAGS
122 CFLAGS
:= $(EXTRA_CFLAGS
)
127 # Append required CFLAGS
128 override CFLAGS
+= -fPIC
129 override CFLAGS
+= $(CONFIG_FLAGS
) $(INCLUDES
) $(PLUGIN_DIR_SQ
)
130 override CFLAGS
+= $(udis86-flags
) -D_GNU_SOURCE
138 # Disable command line variables (CFLAGS) overide from top
139 # level Makefile (perf), otherwise build Makefile will get
140 # the same command line setup.
143 export srctree OUTPUT CC LD CFLAGS V
144 build
:= -f
$(srctree
)/tools
/build
/Makefile.build
dir=. obj
146 PLUGINS
= plugin_jbd2.so
147 PLUGINS
+= plugin_hrtimer.so
148 PLUGINS
+= plugin_kmem.so
149 PLUGINS
+= plugin_kvm.so
150 PLUGINS
+= plugin_mac80211.so
151 PLUGINS
+= plugin_sched_switch.so
152 PLUGINS
+= plugin_function.so
153 PLUGINS
+= plugin_xen.so
154 PLUGINS
+= plugin_scsi.so
155 PLUGINS
+= plugin_cfg80211.so
157 PLUGINS
:= $(addprefix $(OUTPUT
),$(PLUGINS
))
158 PLUGINS_IN
:= $(PLUGINS
:.so
=-in.o
)
160 TE_IN
:= $(OUTPUT
)libtraceevent-in.o
161 LIB_TARGET
:= $(addprefix $(OUTPUT
),$(LIB_TARGET
))
162 DYNAMIC_LIST_FILE
:= $(OUTPUT
)libtraceevent-dynamic-list
164 CMD_TARGETS
= $(LIB_TARGET
) $(PLUGINS
) $(DYNAMIC_LIST_FILE
)
166 TARGETS
= $(CMD_TARGETS
)
170 all_cmd
: $(CMD_TARGETS
)
173 $(Q
)$(MAKE
) $(build
)=libtraceevent
175 $(OUTPUT
)libtraceevent.so.
$(EVENT_PARSE_VERSION
): $(TE_IN
)
176 $(QUIET_LINK
)$(CC
) --shared
$^
-Wl
,-soname
,libtraceevent.so.
$(EP_VERSION
) -o
$@
177 @ln
-sf
$(@F
) $(OUTPUT
)libtraceevent.so
178 @ln
-sf
$(@F
) $(OUTPUT
)libtraceevent.so.
$(EP_VERSION
)
180 $(OUTPUT
)libtraceevent.a
: $(TE_IN
)
181 $(QUIET_LINK
)$(RM
) $@
; $(AR
) rcs
$@
$^
183 $(OUTPUT
)libtraceevent-dynamic-list
: $(PLUGINS
)
184 $(QUIET_GEN
)$(call do_generate_dynamic_list_file
, $(PLUGINS
), $@
)
188 __plugin_obj
= $(notdir $@
)
189 plugin_obj
= $(__plugin_obj
:-in.o
=)
192 $(Q
)$(MAKE
) $(build
)=$(plugin_obj
)
194 $(OUTPUT
)%.so
: $(OUTPUT
)%-in.o
195 $(QUIET_LINK
)$(CC
) $(CFLAGS
) -shared
-nostartfiles
-o
$@
$^
197 define make_version.h
198 (echo
'/* This file is automatically generated. Do not modify. */'; \
199 echo \
#define VERSION_CODE $(shell \
200 expr
$(VERSION
) \
* 256 + $(PATCHLEVEL
)); \
201 echo
'#define EXTRAVERSION ' $(EXTRAVERSION
); \
202 echo
'#define VERSION_STRING "'$(VERSION
).
$(PATCHLEVEL
).
$(EXTRAVERSION
)'"'; \
203 echo
'#define FILE_VERSION '$(FILE_VERSION
); \
207 define update_version.h
208 ($(call make_version.h
, $@.tmp
); \
209 if
[ -r
$@
] && cmp
-s
$@
$@.tmp
; then \
218 $(Q
)$(N
)$(call update_version.h
)
220 VERSION_FILES
= ep_version.h
224 if
[ -r
$@
] && cmp
-s
$@
$@.tmp
; then \
234 find .
-name
'*.[ch]' | xargs ctags
--extra
=+f
--c-kinds
=+px \
235 --regex-c
++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
239 find .
-name
'*.[ch]' | xargs etags \
240 --regex
='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
242 define do_install_mkdir
243 if
[ ! -d
'$(DESTDIR_SQ)$1' ]; then \
244 $(INSTALL
) -d
-m
755 '$(DESTDIR_SQ)$1'; \
249 $(call do_install_mkdir
,$2); \
250 $(INSTALL
) $(if
$3,-m
$3,) $1 '$(DESTDIR_SQ)$2'
253 define do_install_plugins
254 for plugin in
$1; do \
255 $(call do_install
,$$plugin,$(plugin_dir_SQ
)); \
259 define do_generate_dynamic_list_file
261 $(NM
) -u
-D
$1 | awk
'NF>1 {print "\t"$$2";"}' |
sort -u
; \
266 install_lib
: all_cmd install_plugins
267 $(call QUIET_INSTALL
, $(LIB_TARGET
)) \
268 $(call do_install_mkdir
,$(libdir_SQ
)); \
269 cp
-fpR
$(LIB_INSTALL
) $(DESTDIR
)$(libdir_SQ
)
271 install_plugins
: $(PLUGINS
)
272 $(call QUIET_INSTALL
, trace_plugins
) \
273 $(call do_install_plugins
, $(PLUGINS
))
276 $(call QUIET_INSTALL
, headers
) \
277 $(call do_install
,event-parse.h
,$(prefix)/include/traceevent
,644); \
278 $(call do_install
,event-utils.h
,$(prefix)/include/traceevent
,644); \
279 $(call do_install
,kbuffer.h
,$(prefix)/include/traceevent
,644)
284 $(call QUIET_CLEAN
, libtraceevent
) \
285 $(RM
) *.o
*~
$(TARGETS
) *.a
*.so
$(VERSION_FILES
) .
*.d .
*.cmd \
286 $(RM
) TRACEEVENT-CFLAGS
tags TAGS
288 PHONY
+= force plugins
291 # Declare the contents of the .PHONY variable as phony. We keep that
292 # information in a variable so we can use it in if_changed and friends.