| .. | .. |
|---|
| 25 | 25 | $(call allow-override,CC,$(CROSS_COMPILE)gcc) |
|---|
| 26 | 26 | $(call allow-override,AR,$(CROSS_COMPILE)ar) |
|---|
| 27 | 27 | $(call allow-override,NM,$(CROSS_COMPILE)nm) |
|---|
| 28 | +$(call allow-override,PKG_CONFIG,pkg-config) |
|---|
| 28 | 29 | |
|---|
| 29 | 30 | EXT = -std=gnu99 |
|---|
| 30 | 31 | INSTALL = install |
|---|
| .. | .. |
|---|
| 38 | 39 | |
|---|
| 39 | 40 | LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) |
|---|
| 40 | 41 | ifeq ($(LP64), 1) |
|---|
| 41 | | - libdir_relative = lib64 |
|---|
| 42 | + libdir_relative_temp = lib64 |
|---|
| 42 | 43 | else |
|---|
| 43 | | - libdir_relative = lib |
|---|
| 44 | + libdir_relative_temp = lib |
|---|
| 44 | 45 | endif |
|---|
| 45 | 46 | |
|---|
| 47 | +libdir_relative ?= $(libdir_relative_temp) |
|---|
| 46 | 48 | prefix ?= /usr/local |
|---|
| 47 | 49 | libdir = $(prefix)/$(libdir_relative) |
|---|
| 48 | 50 | man_dir = $(prefix)/share/man |
|---|
| 49 | 51 | man_dir_SQ = '$(subst ','\'',$(man_dir))' |
|---|
| 52 | +pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \ |
|---|
| 53 | + --variable pc_path pkg-config | tr ":" " ")) |
|---|
| 54 | +includedir_relative = traceevent |
|---|
| 55 | +includedir = $(prefix)/include/$(includedir_relative) |
|---|
| 56 | +includedir_SQ = '$(subst ','\'',$(includedir))' |
|---|
| 50 | 57 | |
|---|
| 51 | 58 | export man_dir man_dir_SQ INSTALL |
|---|
| 52 | 59 | export DESTDIR DESTDIR_SQ |
|---|
| 53 | | - |
|---|
| 54 | | -set_plugin_dir := 1 |
|---|
| 55 | | - |
|---|
| 56 | | -# Set plugin_dir to preffered global plugin location |
|---|
| 57 | | -# If we install under $HOME directory we go under |
|---|
| 58 | | -# $(HOME)/.local/lib/traceevent/plugins |
|---|
| 59 | | -# |
|---|
| 60 | | -# We dont set PLUGIN_DIR in case we install under $HOME |
|---|
| 61 | | -# directory, because by default the code looks under: |
|---|
| 62 | | -# $(HOME)/.local/lib/traceevent/plugins by default. |
|---|
| 63 | | -# |
|---|
| 64 | | -ifeq ($(plugin_dir),) |
|---|
| 65 | | -ifeq ($(prefix),$(HOME)) |
|---|
| 66 | | -override plugin_dir = $(HOME)/.local/lib/traceevent/plugins |
|---|
| 67 | | -set_plugin_dir := 0 |
|---|
| 68 | | -else |
|---|
| 69 | | -override plugin_dir = $(libdir)/traceevent/plugins |
|---|
| 70 | | -endif |
|---|
| 71 | | -endif |
|---|
| 72 | | - |
|---|
| 73 | | -ifeq ($(set_plugin_dir),1) |
|---|
| 74 | | -PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)" |
|---|
| 75 | | -PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))' |
|---|
| 76 | | -endif |
|---|
| 60 | +export EVENT_PARSE_VERSION |
|---|
| 77 | 61 | |
|---|
| 78 | 62 | include ../../scripts/Makefile.include |
|---|
| 79 | 63 | |
|---|
| .. | .. |
|---|
| 98 | 82 | # Shell quotes |
|---|
| 99 | 83 | libdir_SQ = $(subst ','\'',$(libdir)) |
|---|
| 100 | 84 | libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) |
|---|
| 101 | | -plugin_dir_SQ = $(subst ','\'',$(plugin_dir)) |
|---|
| 102 | 85 | |
|---|
| 103 | 86 | CONFIG_INCLUDES = |
|---|
| 104 | 87 | CONFIG_LIBS = |
|---|
| .. | .. |
|---|
| 145 | 128 | export srctree OUTPUT CC LD CFLAGS V |
|---|
| 146 | 129 | build := -f $(srctree)/tools/build/Makefile.build dir=. obj |
|---|
| 147 | 130 | |
|---|
| 148 | | -PLUGINS = plugin_jbd2.so |
|---|
| 149 | | -PLUGINS += plugin_hrtimer.so |
|---|
| 150 | | -PLUGINS += plugin_kmem.so |
|---|
| 151 | | -PLUGINS += plugin_kvm.so |
|---|
| 152 | | -PLUGINS += plugin_mac80211.so |
|---|
| 153 | | -PLUGINS += plugin_sched_switch.so |
|---|
| 154 | | -PLUGINS += plugin_function.so |
|---|
| 155 | | -PLUGINS += plugin_xen.so |
|---|
| 156 | | -PLUGINS += plugin_scsi.so |
|---|
| 157 | | -PLUGINS += plugin_cfg80211.so |
|---|
| 158 | | - |
|---|
| 159 | | -PLUGINS := $(addprefix $(OUTPUT),$(PLUGINS)) |
|---|
| 160 | | -PLUGINS_IN := $(PLUGINS:.so=-in.o) |
|---|
| 161 | | - |
|---|
| 162 | 131 | TE_IN := $(OUTPUT)libtraceevent-in.o |
|---|
| 163 | 132 | LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET)) |
|---|
| 164 | | -DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list |
|---|
| 165 | 133 | |
|---|
| 166 | | -CMD_TARGETS = $(LIB_TARGET) $(PLUGINS) $(DYNAMIC_LIST_FILE) |
|---|
| 134 | +CMD_TARGETS = $(LIB_TARGET) |
|---|
| 167 | 135 | |
|---|
| 168 | 136 | TARGETS = $(CMD_TARGETS) |
|---|
| 169 | 137 | |
|---|
| 170 | | -all: all_cmd |
|---|
| 138 | +all: all_cmd plugins |
|---|
| 171 | 139 | |
|---|
| 172 | 140 | all_cmd: $(CMD_TARGETS) |
|---|
| 173 | 141 | |
|---|
| .. | .. |
|---|
| 175 | 143 | $(Q)$(MAKE) $(build)=libtraceevent |
|---|
| 176 | 144 | |
|---|
| 177 | 145 | $(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN) |
|---|
| 178 | | - $(QUIET_LINK)$(CC) --shared $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@ |
|---|
| 146 | + $(QUIET_LINK)$(CC) --shared $(LDFLAGS) $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@ |
|---|
| 179 | 147 | @ln -sf $(@F) $(OUTPUT)libtraceevent.so |
|---|
| 180 | 148 | @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION) |
|---|
| 181 | 149 | |
|---|
| 182 | 150 | $(OUTPUT)libtraceevent.a: $(TE_IN) |
|---|
| 183 | 151 | $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ |
|---|
| 184 | 152 | |
|---|
| 185 | | -$(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS) |
|---|
| 186 | | - $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@) |
|---|
| 187 | | - |
|---|
| 188 | | -plugins: $(PLUGINS) |
|---|
| 189 | | - |
|---|
| 190 | | -__plugin_obj = $(notdir $@) |
|---|
| 191 | | - plugin_obj = $(__plugin_obj:-in.o=) |
|---|
| 192 | | - |
|---|
| 193 | | -$(PLUGINS_IN): force |
|---|
| 194 | | - $(Q)$(MAKE) $(build)=$(plugin_obj) |
|---|
| 195 | | - |
|---|
| 196 | 153 | $(OUTPUT)%.so: $(OUTPUT)%-in.o |
|---|
| 197 | | - $(QUIET_LINK)$(CC) $(CFLAGS) -shared -nostartfiles -o $@ $^ |
|---|
| 154 | + $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^ |
|---|
| 198 | 155 | |
|---|
| 199 | 156 | define make_version.h |
|---|
| 200 | 157 | (echo '/* This file is automatically generated. Do not modify. */'; \ |
|---|
| .. | .. |
|---|
| 252 | 209 | $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2' |
|---|
| 253 | 210 | endef |
|---|
| 254 | 211 | |
|---|
| 255 | | -define do_install_plugins |
|---|
| 256 | | - for plugin in $1; do \ |
|---|
| 257 | | - $(call do_install,$$plugin,$(plugin_dir_SQ)); \ |
|---|
| 258 | | - done |
|---|
| 259 | | -endef |
|---|
| 260 | | - |
|---|
| 261 | | -define do_generate_dynamic_list_file |
|---|
| 262 | | - symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \ |
|---|
| 263 | | - xargs echo "U w W" | tr 'w ' 'W\n' | sort -u | xargs echo`;\ |
|---|
| 264 | | - if [ "$$symbol_type" = "U W" ];then \ |
|---|
| 265 | | - (echo '{'; \ |
|---|
| 266 | | - $(NM) -u -D $1 | awk 'NF>1 {sub("@.*", "", $$2); print "\t"$$2";"}' | sort -u;\ |
|---|
| 267 | | - echo '};'; \ |
|---|
| 268 | | - ) > $2; \ |
|---|
| 269 | | - else \ |
|---|
| 270 | | - (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\ |
|---|
| 212 | +PKG_CONFIG_SOURCE_FILE = libtraceevent.pc |
|---|
| 213 | +PKG_CONFIG_FILE := $(addprefix $(OUTPUT),$(PKG_CONFIG_SOURCE_FILE)) |
|---|
| 214 | +define do_install_pkgconfig_file |
|---|
| 215 | + if [ -n "${pkgconfig_dir}" ]; then \ |
|---|
| 216 | + cp -f ${PKG_CONFIG_SOURCE_FILE}.template ${PKG_CONFIG_FILE}; \ |
|---|
| 217 | + sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \ |
|---|
| 218 | + sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \ |
|---|
| 219 | + sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \ |
|---|
| 220 | + sed -i "s|HEADER_DIR|$(includedir)|g" ${PKG_CONFIG_FILE}; \ |
|---|
| 221 | + $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \ |
|---|
| 222 | + else \ |
|---|
| 223 | + (echo Failed to locate pkg-config directory) 1>&2; \ |
|---|
| 271 | 224 | fi |
|---|
| 272 | 225 | endef |
|---|
| 273 | 226 | |
|---|
| 274 | | -install_lib: all_cmd install_plugins |
|---|
| 227 | +install_lib: all_cmd install_plugins install_headers install_pkgconfig |
|---|
| 275 | 228 | $(call QUIET_INSTALL, $(LIB_TARGET)) \ |
|---|
| 276 | 229 | $(call do_install_mkdir,$(libdir_SQ)); \ |
|---|
| 277 | 230 | cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ) |
|---|
| 278 | 231 | |
|---|
| 279 | | -install_plugins: $(PLUGINS) |
|---|
| 280 | | - $(call QUIET_INSTALL, trace_plugins) \ |
|---|
| 281 | | - $(call do_install_plugins, $(PLUGINS)) |
|---|
| 232 | +install_pkgconfig: |
|---|
| 233 | + $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \ |
|---|
| 234 | + $(call do_install_pkgconfig_file,$(prefix)) |
|---|
| 282 | 235 | |
|---|
| 283 | 236 | install_headers: |
|---|
| 284 | 237 | $(call QUIET_INSTALL, headers) \ |
|---|
| 285 | | - $(call do_install,event-parse.h,$(prefix)/include/traceevent,644); \ |
|---|
| 286 | | - $(call do_install,event-utils.h,$(prefix)/include/traceevent,644); \ |
|---|
| 287 | | - $(call do_install,kbuffer.h,$(prefix)/include/traceevent,644) |
|---|
| 238 | + $(call do_install,event-parse.h,$(includedir_SQ),644); \ |
|---|
| 239 | + $(call do_install,event-utils.h,$(includedir_SQ),644); \ |
|---|
| 240 | + $(call do_install,trace-seq.h,$(includedir_SQ),644); \ |
|---|
| 241 | + $(call do_install,kbuffer.h,$(includedir_SQ),644) |
|---|
| 288 | 242 | |
|---|
| 289 | 243 | install: install_lib |
|---|
| 290 | 244 | |
|---|
| 291 | | -clean: |
|---|
| 245 | +clean: clean_plugins |
|---|
| 292 | 246 | $(call QUIET_CLEAN, libtraceevent) \ |
|---|
| 293 | | - $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd \ |
|---|
| 294 | | - $(RM) TRACEEVENT-CFLAGS tags TAGS |
|---|
| 247 | + $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \ |
|---|
| 248 | + $(RM) TRACEEVENT-CFLAGS tags TAGS; \ |
|---|
| 249 | + $(RM) $(PKG_CONFIG_FILE) |
|---|
| 295 | 250 | |
|---|
| 296 | | -PHONY += force plugins |
|---|
| 251 | +PHONY += doc |
|---|
| 252 | +doc: |
|---|
| 253 | + $(call descend,Documentation) |
|---|
| 254 | + |
|---|
| 255 | +PHONY += doc-clean |
|---|
| 256 | +doc-clean: |
|---|
| 257 | + $(call descend,Documentation,clean) |
|---|
| 258 | + |
|---|
| 259 | +PHONY += doc-install |
|---|
| 260 | +doc-install: |
|---|
| 261 | + $(call descend,Documentation,install) |
|---|
| 262 | + |
|---|
| 263 | +PHONY += doc-uninstall |
|---|
| 264 | +doc-uninstall: |
|---|
| 265 | + $(call descend,Documentation,uninstall) |
|---|
| 266 | + |
|---|
| 267 | +PHONY += help |
|---|
| 268 | +help: |
|---|
| 269 | + @echo 'Possible targets:' |
|---|
| 270 | + @echo'' |
|---|
| 271 | + @echo ' all - default, compile the library and the'\ |
|---|
| 272 | + 'plugins' |
|---|
| 273 | + @echo ' plugins - compile the plugins' |
|---|
| 274 | + @echo ' install - install the library, the plugins,'\ |
|---|
| 275 | + 'the header and pkgconfig files' |
|---|
| 276 | + @echo ' clean - clean the library and the plugins object files' |
|---|
| 277 | + @echo ' doc - compile the documentation files - man'\ |
|---|
| 278 | + 'and html pages, in the Documentation directory' |
|---|
| 279 | + @echo ' doc-clean - clean the documentation files' |
|---|
| 280 | + @echo ' doc-install - install the man pages' |
|---|
| 281 | + @echo ' doc-uninstall - uninstall the man pages' |
|---|
| 282 | + @echo'' |
|---|
| 283 | + |
|---|
| 284 | +PHONY += plugins |
|---|
| 285 | +plugins: |
|---|
| 286 | + $(call descend,plugins) |
|---|
| 287 | + |
|---|
| 288 | +PHONY += install_plugins |
|---|
| 289 | +install_plugins: |
|---|
| 290 | + $(call descend,plugins,install) |
|---|
| 291 | + |
|---|
| 292 | +PHONY += clean_plugins |
|---|
| 293 | +clean_plugins: |
|---|
| 294 | + $(call descend,plugins,clean) |
|---|
| 295 | + |
|---|
| 297 | 296 | force: |
|---|
| 298 | 297 | |
|---|
| 299 | 298 | # Declare the contents of the .PHONY variable as phony. We keep that |
|---|