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