Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 1 | # trace-cmd version |
| 2 | EP_VERSION = 1 |
| 3 | EP_PATCHLEVEL = 1 |
| 4 | EP_EXTRAVERSION = 0 |
| 5 | |
| 6 | # file format version |
| 7 | FILE_VERSION = 6 |
| 8 | |
| 9 | MAKEFLAGS += --no-print-directory |
| 10 | |
| 11 | |
| 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. |
| 17 | define allow-override |
| 18 | $(if $(or $(findstring environment,$(origin $(1))),\ |
| 19 | $(findstring command line,$(origin $(1)))),,\ |
| 20 | $(eval $(1) = $(2))) |
| 21 | endef |
| 22 | |
| 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) |
He Kuang | e3d09ec | 2015-05-28 13:28:54 +0000 | [diff] [blame] | 26 | $(call allow-override,NM,$(CROSS_COMPILE)nm) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 27 | |
| 28 | EXT = -std=gnu99 |
| 29 | INSTALL = install |
| 30 | |
| 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. |
| 35 | DESTDIR ?= |
| 36 | DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' |
| 37 | |
Wang Nan | bb53e17 | 2015-05-17 10:56:28 +0000 | [diff] [blame] | 38 | LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) |
| 39 | ifeq ($(LP64), 1) |
| 40 | libdir_relative = lib64 |
| 41 | else |
| 42 | libdir_relative = lib |
| 43 | endif |
| 44 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 45 | prefix ?= /usr/local |
Wang Nan | bb53e17 | 2015-05-17 10:56:28 +0000 | [diff] [blame] | 46 | libdir = $(prefix)/$(libdir_relative) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 47 | man_dir = $(prefix)/share/man |
| 48 | man_dir_SQ = '$(subst ','\'',$(man_dir))' |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 49 | |
Namhyung Kim | 9f1efa8 | 2013-06-04 14:20:16 +0900 | [diff] [blame] | 50 | export man_dir man_dir_SQ INSTALL |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 51 | export DESTDIR DESTDIR_SQ |
| 52 | |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 53 | set_plugin_dir := 1 |
| 54 | |
| 55 | # Set plugin_dir to preffered global plugin location |
| 56 | # If we install under $HOME directory we go under |
| 57 | # $(HOME)/.traceevent/plugins |
| 58 | # |
| 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. |
| 62 | # |
| 63 | ifeq ($(plugin_dir),) |
| 64 | ifeq ($(prefix),$(HOME)) |
| 65 | override plugin_dir = $(HOME)/.traceevent/plugins |
| 66 | set_plugin_dir := 0 |
| 67 | else |
Wang Nan | bb53e17 | 2015-05-17 10:56:28 +0000 | [diff] [blame] | 68 | override plugin_dir = $(libdir)/traceevent/plugins |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 69 | endif |
| 70 | endif |
| 71 | |
| 72 | ifeq ($(set_plugin_dir),1) |
Josh Boyer | b935a58 | 2014-01-22 10:01:48 -0500 | [diff] [blame] | 73 | PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)" |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 74 | PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))' |
| 75 | endif |
| 76 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 77 | include ../../scripts/Makefile.include |
Jiri Olsa | c3d090f | 2013-12-19 14:42:02 +0100 | [diff] [blame] | 78 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 79 | # copy a bit from Linux kbuild |
| 80 | |
| 81 | ifeq ("$(origin V)", "command line") |
| 82 | VERBOSE = $(V) |
| 83 | endif |
| 84 | ifndef VERBOSE |
| 85 | VERBOSE = 0 |
| 86 | endif |
| 87 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 88 | ifeq ($(srctree),) |
| 89 | srctree := $(patsubst %/,%,$(dir $(shell pwd))) |
| 90 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 91 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 92 | #$(info Determined 'srctree' to be $(srctree)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 93 | endif |
| 94 | |
Wang Nan | bb53e17 | 2015-05-17 10:56:28 +0000 | [diff] [blame] | 95 | export prefix libdir src obj |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 96 | |
| 97 | # Shell quotes |
Wang Nan | bb53e17 | 2015-05-17 10:56:28 +0000 | [diff] [blame] | 98 | libdir_SQ = $(subst ','\'',$(libdir)) |
| 99 | libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 100 | plugin_dir_SQ = $(subst ','\'',$(plugin_dir)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 101 | |
| 102 | LIB_FILE = libtraceevent.a libtraceevent.so |
| 103 | |
| 104 | CONFIG_INCLUDES = |
| 105 | CONFIG_LIBS = |
| 106 | CONFIG_FLAGS = |
| 107 | |
| 108 | VERSION = $(EP_VERSION) |
| 109 | PATCHLEVEL = $(EP_PATCHLEVEL) |
| 110 | EXTRAVERSION = $(EP_EXTRAVERSION) |
| 111 | |
| 112 | OBJ = $@ |
| 113 | N = |
| 114 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 115 | EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) |
| 116 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 117 | INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 118 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 119 | # Set compile option CFLAGS |
| 120 | ifdef EXTRA_CFLAGS |
| 121 | CFLAGS := $(EXTRA_CFLAGS) |
| 122 | else |
| 123 | CFLAGS := -g -Wall |
| 124 | endif |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 125 | |
| 126 | # Append required CFLAGS |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 127 | override CFLAGS += -fPIC |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 128 | override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) |
Arnaldo Carvalho de Melo | c055875b7 | 2012-09-12 14:29:40 -0300 | [diff] [blame] | 129 | override CFLAGS += $(udis86-flags) -D_GNU_SOURCE |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 130 | |
| 131 | ifeq ($(VERBOSE),1) |
| 132 | Q = |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 133 | else |
| 134 | Q = @ |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 135 | endif |
| 136 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 137 | # Disable command line variables (CFLAGS) overide from top |
| 138 | # level Makefile (perf), otherwise build Makefile will get |
| 139 | # the same command line setup. |
| 140 | MAKEOVERRIDES= |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 141 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 142 | export srctree OUTPUT CC LD CFLAGS V |
| 143 | build := -f $(srctree)/tools/build/Makefile.build dir=. obj |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 144 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 145 | PLUGINS = plugin_jbd2.so |
| 146 | PLUGINS += plugin_hrtimer.so |
| 147 | PLUGINS += plugin_kmem.so |
| 148 | PLUGINS += plugin_kvm.so |
| 149 | PLUGINS += plugin_mac80211.so |
| 150 | PLUGINS += plugin_sched_switch.so |
| 151 | PLUGINS += plugin_function.so |
| 152 | PLUGINS += plugin_xen.so |
| 153 | PLUGINS += plugin_scsi.so |
| 154 | PLUGINS += plugin_cfg80211.so |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 155 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 156 | PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS)) |
| 157 | PLUGINS_IN := $(PLUGINS:.so=-in.o) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 158 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 159 | TE_IN := $(OUTPUT)libtraceevent-in.o |
| 160 | LIB_FILE := $(addprefix $(OUTPUT),$(LIB_FILE)) |
He Kuang | e3d09ec | 2015-05-28 13:28:54 +0000 | [diff] [blame] | 161 | DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 162 | |
He Kuang | e3d09ec | 2015-05-28 13:28:54 +0000 | [diff] [blame] | 163 | CMD_TARGETS = $(LIB_FILE) $(PLUGINS) $(DYNAMIC_LIST_FILE) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 164 | |
| 165 | TARGETS = $(CMD_TARGETS) |
| 166 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 167 | all: all_cmd |
| 168 | |
| 169 | all_cmd: $(CMD_TARGETS) |
| 170 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 171 | $(TE_IN): force |
| 172 | $(Q)$(MAKE) $(build)=libtraceevent |
| 173 | |
| 174 | $(OUTPUT)libtraceevent.so: $(TE_IN) |
Jiri Olsa | e6262e2 | 2013-12-19 14:42:04 +0100 | [diff] [blame] | 175 | $(QUIET_LINK)$(CC) --shared $^ -o $@ |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 176 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 177 | $(OUTPUT)libtraceevent.a: $(TE_IN) |
Jiri Olsa | e6262e2 | 2013-12-19 14:42:04 +0100 | [diff] [blame] | 178 | $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 179 | |
He Kuang | e3d09ec | 2015-05-28 13:28:54 +0000 | [diff] [blame] | 180 | $(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS) |
| 181 | $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@) |
| 182 | |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 183 | plugins: $(PLUGINS) |
| 184 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 185 | __plugin_obj = $(notdir $@) |
| 186 | plugin_obj = $(__plugin_obj:-in.o=) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 187 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 188 | $(PLUGINS_IN): force |
| 189 | $(Q)$(MAKE) $(build)=$(plugin_obj) |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 190 | |
Jiri Olsa | 2d58ab9 | 2015-01-07 18:39:45 +0100 | [diff] [blame] | 191 | $(OUTPUT)%.so: $(OUTPUT)%-in.o |
| 192 | $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^ |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 193 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 194 | define make_version.h |
Jiri Olsa | 198430b | 2014-01-02 10:53:04 +0100 | [diff] [blame] | 195 | (echo '/* This file is automatically generated. Do not modify. */'; \ |
| 196 | echo \#define VERSION_CODE $(shell \ |
| 197 | expr $(VERSION) \* 256 + $(PATCHLEVEL)); \ |
| 198 | echo '#define EXTRAVERSION ' $(EXTRAVERSION); \ |
| 199 | echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \ |
| 200 | echo '#define FILE_VERSION '$(FILE_VERSION); \ |
| 201 | ) > $1 |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 202 | endef |
| 203 | |
| 204 | define update_version.h |
Jiri Olsa | 198430b | 2014-01-02 10:53:04 +0100 | [diff] [blame] | 205 | ($(call make_version.h, $@.tmp); \ |
| 206 | if [ -r $@ ] && cmp -s $@ $@.tmp; then \ |
| 207 | rm -f $@.tmp; \ |
| 208 | else \ |
| 209 | echo ' UPDATE $@'; \ |
| 210 | mv -f $@.tmp $@; \ |
| 211 | fi); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 212 | endef |
| 213 | |
| 214 | ep_version.h: force |
| 215 | $(Q)$(N)$(call update_version.h) |
| 216 | |
| 217 | VERSION_FILES = ep_version.h |
| 218 | |
| 219 | define update_dir |
Jiri Olsa | 198430b | 2014-01-02 10:53:04 +0100 | [diff] [blame] | 220 | (echo $1 > $@.tmp; \ |
| 221 | if [ -r $@ ] && cmp -s $@ $@.tmp; then \ |
| 222 | rm -f $@.tmp; \ |
| 223 | else \ |
| 224 | echo ' UPDATE $@'; \ |
| 225 | mv -f $@.tmp $@; \ |
| 226 | fi); |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 227 | endef |
| 228 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 229 | tags: force |
| 230 | $(RM) tags |
Namhyung Kim | 6545e3a | 2012-06-22 17:10:14 +0900 | [diff] [blame] | 231 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ |
| 232 | --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 233 | |
| 234 | TAGS: force |
| 235 | $(RM) TAGS |
Namhyung Kim | 6545e3a | 2012-06-22 17:10:14 +0900 | [diff] [blame] | 236 | find . -name '*.[ch]' | xargs etags \ |
| 237 | --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 238 | |
| 239 | define do_install |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 240 | if [ ! -d '$(DESTDIR_SQ)$2' ]; then \ |
| 241 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \ |
| 242 | fi; \ |
| 243 | $(INSTALL) $1 '$(DESTDIR_SQ)$2' |
| 244 | endef |
| 245 | |
Jiri Olsa | 02a82c7 | 2013-12-19 14:42:05 +0100 | [diff] [blame] | 246 | define do_install_plugins |
| 247 | for plugin in $1; do \ |
| 248 | $(call do_install,$$plugin,$(plugin_dir_SQ)); \ |
| 249 | done |
| 250 | endef |
| 251 | |
He Kuang | e3d09ec | 2015-05-28 13:28:54 +0000 | [diff] [blame] | 252 | define do_generate_dynamic_list_file |
| 253 | (echo '{'; \ |
| 254 | $(NM) -u -D $1 | awk 'NF>1 {print "\t"$$2";"}' | sort -u; \ |
| 255 | echo '};'; \ |
| 256 | ) > $2 |
| 257 | endef |
| 258 | |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 259 | install_lib: all_cmd install_plugins |
Jiri Olsa | 02a82c7 | 2013-12-19 14:42:05 +0100 | [diff] [blame] | 260 | $(call QUIET_INSTALL, $(LIB_FILE)) \ |
Wang Nan | bb53e17 | 2015-05-17 10:56:28 +0000 | [diff] [blame] | 261 | $(call do_install,$(LIB_FILE),$(libdir_SQ)) |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 262 | |
Jiri Olsa | 02a82c7 | 2013-12-19 14:42:05 +0100 | [diff] [blame] | 263 | install_plugins: $(PLUGINS) |
| 264 | $(call QUIET_INSTALL, trace_plugins) \ |
| 265 | $(call do_install_plugins, $(PLUGINS)) |
Jiri Olsa | e0e96d0 | 2013-12-03 14:09:17 +0100 | [diff] [blame] | 266 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 267 | install: install_lib |
| 268 | |
| 269 | clean: |
Jiri Olsa | 4a953c7 | 2013-12-19 14:42:06 +0100 | [diff] [blame] | 270 | $(call QUIET_CLEAN, libtraceevent) \ |
Riku Voipio | c867b15 | 2015-06-18 15:52:18 +0300 | [diff] [blame^] | 271 | $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \ |
Jiri Olsa | 4a953c7 | 2013-12-19 14:42:06 +0100 | [diff] [blame] | 272 | $(RM) TRACEEVENT-CFLAGS tags TAGS |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 273 | |
Jiri Olsa | 9bb8e5e | 2014-01-01 17:50:50 +0100 | [diff] [blame] | 274 | PHONY += force plugins |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 275 | force: |
| 276 | |
Steven Rostedt | f7d8235 | 2012-04-06 00:47:53 +0200 | [diff] [blame] | 277 | # Declare the contents of the .PHONY variable as phony. We keep that |
| 278 | # information in a variable so we can use it in if_changed and friends. |
| 279 | .PHONY: $(PHONY) |