Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
| 2 | # trace-cmd version |
| 3 | EP_VERSION = 1 |
| 4 | EP_PATCHLEVEL = 1 |
| 5 | EP_EXTRAVERSION = 0 |
| 6 | |
| 7 | # file format version |
| 8 | FILE_VERSION = 6 |
| 9 | |
| 10 | MAKEFLAGS += --no-print-directory |
| 11 | |
| 12 | |
| 13 | # Makefiles suck: This macro sets a default value of $(2) for the |
| 14 | # variable named by $(1), unless the variable has been set by |
| 15 | # environment or command line. This is necessary for CC and AR |
| 16 | # because make sets default values, so the simpler ?= approach |
| 17 | # won't work as expected. |
| 18 | define allow-override |
| 19 | $(if $(or $(findstring environment,$(origin $(1))),\ |
| 20 | $(findstring command line,$(origin $(1)))),,\ |
| 21 | $(eval $(1) = $(2))) |
| 22 | endef |
| 23 | |
| 24 | # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix. |
| 25 | $(call allow-override,CC,$(CROSS_COMPILE)gcc) |
| 26 | $(call allow-override,AR,$(CROSS_COMPILE)ar) |
| 27 | $(call allow-override,NM,$(CROSS_COMPILE)nm) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 28 | $(call allow-override,PKG_CONFIG,pkg-config) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 29 | |
| 30 | EXT = -std=gnu99 |
| 31 | INSTALL = install |
| 32 | |
| 33 | # Use DESTDIR for installing into a different root directory. |
| 34 | # This is useful for building a package. The program will be |
| 35 | # installed in this directory as if it was the root directory. |
| 36 | # Then the build tool can move it later. |
| 37 | DESTDIR ?= |
| 38 | DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' |
| 39 | |
| 40 | LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1) |
| 41 | ifeq ($(LP64), 1) |
| 42 | libdir_relative = lib64 |
| 43 | else |
| 44 | libdir_relative = lib |
| 45 | endif |
| 46 | |
| 47 | prefix ?= /usr/local |
| 48 | libdir = $(prefix)/$(libdir_relative) |
| 49 | man_dir = $(prefix)/share/man |
| 50 | man_dir_SQ = '$(subst ','\'',$(man_dir))' |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 51 | pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG) \ |
| 52 | --variable pc_path pkg-config | tr ":" " ")) |
| 53 | includedir_relative = traceevent |
| 54 | includedir = $(prefix)/include/$(includedir_relative) |
| 55 | includedir_SQ = '$(subst ','\'',$(includedir))' |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 56 | |
| 57 | export man_dir man_dir_SQ INSTALL |
| 58 | export DESTDIR DESTDIR_SQ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 59 | export EVENT_PARSE_VERSION |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 60 | |
| 61 | include ../../scripts/Makefile.include |
| 62 | |
| 63 | # copy a bit from Linux kbuild |
| 64 | |
| 65 | ifeq ("$(origin V)", "command line") |
| 66 | VERBOSE = $(V) |
| 67 | endif |
| 68 | ifndef VERBOSE |
| 69 | VERBOSE = 0 |
| 70 | endif |
| 71 | |
| 72 | ifeq ($(srctree),) |
| 73 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
| 74 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 75 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 76 | #$(info Determined 'srctree' to be $(srctree)) |
| 77 | endif |
| 78 | |
| 79 | export prefix libdir src obj |
| 80 | |
| 81 | # Shell quotes |
| 82 | libdir_SQ = $(subst ','\'',$(libdir)) |
| 83 | libdir_relative_SQ = $(subst ','\'',$(libdir_relative)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 84 | |
| 85 | CONFIG_INCLUDES = |
| 86 | CONFIG_LIBS = |
| 87 | CONFIG_FLAGS = |
| 88 | |
| 89 | VERSION = $(EP_VERSION) |
| 90 | PATCHLEVEL = $(EP_PATCHLEVEL) |
| 91 | EXTRAVERSION = $(EP_EXTRAVERSION) |
| 92 | |
| 93 | OBJ = $@ |
| 94 | N = |
| 95 | |
| 96 | EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION) |
| 97 | |
| 98 | LIB_TARGET = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION) |
| 99 | LIB_INSTALL = libtraceevent.a libtraceevent.so* |
| 100 | |
| 101 | INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES) |
| 102 | |
| 103 | # Set compile option CFLAGS |
| 104 | ifdef EXTRA_CFLAGS |
| 105 | CFLAGS := $(EXTRA_CFLAGS) |
| 106 | else |
| 107 | CFLAGS := -g -Wall |
| 108 | endif |
| 109 | |
| 110 | # Append required CFLAGS |
| 111 | override CFLAGS += -fPIC |
| 112 | override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) |
| 113 | override CFLAGS += $(udis86-flags) -D_GNU_SOURCE |
| 114 | |
| 115 | ifeq ($(VERBOSE),1) |
| 116 | Q = |
| 117 | else |
| 118 | Q = @ |
| 119 | endif |
| 120 | |
| 121 | # Disable command line variables (CFLAGS) override from top |
| 122 | # level Makefile (perf), otherwise build Makefile will get |
| 123 | # the same command line setup. |
| 124 | MAKEOVERRIDES= |
| 125 | |
| 126 | export srctree OUTPUT CC LD CFLAGS V |
| 127 | build := -f $(srctree)/tools/build/Makefile.build dir=. obj |
| 128 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 129 | TE_IN := $(OUTPUT)libtraceevent-in.o |
| 130 | LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 131 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 132 | CMD_TARGETS = $(LIB_TARGET) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 133 | |
| 134 | TARGETS = $(CMD_TARGETS) |
| 135 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 136 | all: all_cmd plugins |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 137 | |
| 138 | all_cmd: $(CMD_TARGETS) |
| 139 | |
| 140 | $(TE_IN): force |
| 141 | $(Q)$(MAKE) $(build)=libtraceevent |
| 142 | |
| 143 | $(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN) |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 144 | $(QUIET_LINK)$(CC) --shared $(LDFLAGS) $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 145 | @ln -sf $(@F) $(OUTPUT)libtraceevent.so |
| 146 | @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION) |
| 147 | |
| 148 | $(OUTPUT)libtraceevent.a: $(TE_IN) |
| 149 | $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^ |
| 150 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 151 | $(OUTPUT)%.so: $(OUTPUT)%-in.o |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 152 | $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 153 | |
| 154 | define make_version.h |
| 155 | (echo '/* This file is automatically generated. Do not modify. */'; \ |
| 156 | echo \#define VERSION_CODE $(shell \ |
| 157 | expr $(VERSION) \* 256 + $(PATCHLEVEL)); \ |
| 158 | echo '#define EXTRAVERSION ' $(EXTRAVERSION); \ |
| 159 | echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"'; \ |
| 160 | echo '#define FILE_VERSION '$(FILE_VERSION); \ |
| 161 | ) > $1 |
| 162 | endef |
| 163 | |
| 164 | define update_version.h |
| 165 | ($(call make_version.h, $@.tmp); \ |
| 166 | if [ -r $@ ] && cmp -s $@ $@.tmp; then \ |
| 167 | rm -f $@.tmp; \ |
| 168 | else \ |
| 169 | echo ' UPDATE $@'; \ |
| 170 | mv -f $@.tmp $@; \ |
| 171 | fi); |
| 172 | endef |
| 173 | |
| 174 | ep_version.h: force |
| 175 | $(Q)$(N)$(call update_version.h) |
| 176 | |
| 177 | VERSION_FILES = ep_version.h |
| 178 | |
| 179 | define update_dir |
| 180 | (echo $1 > $@.tmp; \ |
| 181 | if [ -r $@ ] && cmp -s $@ $@.tmp; then \ |
| 182 | rm -f $@.tmp; \ |
| 183 | else \ |
| 184 | echo ' UPDATE $@'; \ |
| 185 | mv -f $@.tmp $@; \ |
| 186 | fi); |
| 187 | endef |
| 188 | |
| 189 | tags: force |
| 190 | $(RM) tags |
| 191 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ |
| 192 | --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/' |
| 193 | |
| 194 | TAGS: force |
| 195 | $(RM) TAGS |
| 196 | find . -name '*.[ch]' | xargs etags \ |
| 197 | --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/' |
| 198 | |
| 199 | define do_install_mkdir |
| 200 | if [ ! -d '$(DESTDIR_SQ)$1' ]; then \ |
| 201 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \ |
| 202 | fi |
| 203 | endef |
| 204 | |
| 205 | define do_install |
| 206 | $(call do_install_mkdir,$2); \ |
| 207 | $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2' |
| 208 | endef |
| 209 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 210 | PKG_CONFIG_FILE = libtraceevent.pc |
| 211 | define do_install_pkgconfig_file |
| 212 | if [ -n "${pkgconfig_dir}" ]; then \ |
| 213 | cp -f ${PKG_CONFIG_FILE}.template ${PKG_CONFIG_FILE}; \ |
| 214 | sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE}; \ |
| 215 | sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \ |
| 216 | sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \ |
| 217 | sed -i "s|HEADER_DIR|$(includedir)|g" ${PKG_CONFIG_FILE}; \ |
| 218 | $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644); \ |
| 219 | else \ |
| 220 | (echo Failed to locate pkg-config directory) 1>&2; \ |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 221 | fi |
| 222 | endef |
| 223 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 224 | install_lib: all_cmd install_plugins install_headers install_pkgconfig |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 225 | $(call QUIET_INSTALL, $(LIB_TARGET)) \ |
| 226 | $(call do_install_mkdir,$(libdir_SQ)); \ |
| 227 | cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ) |
| 228 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 229 | install_pkgconfig: |
| 230 | $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \ |
| 231 | $(call do_install_pkgconfig_file,$(prefix)) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 232 | |
| 233 | install_headers: |
| 234 | $(call QUIET_INSTALL, headers) \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 235 | $(call do_install,event-parse.h,$(DESTDIR)$(includedir_SQ),644); \ |
| 236 | $(call do_install,event-utils.h,$(DESTDIR)$(includedir_SQ),644); \ |
| 237 | $(call do_install,trace-seq.h,$(DESTDIR)$(includedir_SQ),644); \ |
| 238 | $(call do_install,kbuffer.h,$(DESTDIR)$(includedir_SQ),644) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 239 | |
| 240 | install: install_lib |
| 241 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 242 | clean: clean_plugins |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 243 | $(call QUIET_CLEAN, libtraceevent) \ |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 244 | $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \ |
| 245 | $(RM) TRACEEVENT-CFLAGS tags TAGS; \ |
| 246 | $(RM) $(PKG_CONFIG_FILE) |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 247 | |
David Brazdil | 0f672f6 | 2019-12-10 10:32:29 +0000 | [diff] [blame^] | 248 | PHONY += doc |
| 249 | doc: |
| 250 | $(call descend,Documentation) |
| 251 | |
| 252 | PHONY += doc-clean |
| 253 | doc-clean: |
| 254 | $(call descend,Documentation,clean) |
| 255 | |
| 256 | PHONY += doc-install |
| 257 | doc-install: |
| 258 | $(call descend,Documentation,install) |
| 259 | |
| 260 | PHONY += doc-uninstall |
| 261 | doc-uninstall: |
| 262 | $(call descend,Documentation,uninstall) |
| 263 | |
| 264 | PHONY += help |
| 265 | help: |
| 266 | @echo 'Possible targets:' |
| 267 | @echo'' |
| 268 | @echo ' all - default, compile the library and the'\ |
| 269 | 'plugins' |
| 270 | @echo ' plugins - compile the plugins' |
| 271 | @echo ' install - install the library, the plugins,'\ |
| 272 | 'the header and pkgconfig files' |
| 273 | @echo ' clean - clean the library and the plugins object files' |
| 274 | @echo ' doc - compile the documentation files - man'\ |
| 275 | 'and html pages, in the Documentation directory' |
| 276 | @echo ' doc-clean - clean the documentation files' |
| 277 | @echo ' doc-install - install the man pages' |
| 278 | @echo ' doc-uninstall - uninstall the man pages' |
| 279 | @echo'' |
| 280 | |
| 281 | PHONY += plugins |
| 282 | plugins: |
| 283 | $(call descend,plugins) |
| 284 | |
| 285 | PHONY += install_plugins |
| 286 | install_plugins: |
| 287 | $(call descend,plugins,install) |
| 288 | |
| 289 | PHONY += clean_plugins |
| 290 | clean_plugins: |
| 291 | $(call descend,plugins,clean) |
| 292 | |
Andrew Scull | b4b6d4a | 2019-01-02 15:54:55 +0000 | [diff] [blame] | 293 | force: |
| 294 | |
| 295 | # Declare the contents of the .PHONY variable as phony. We keep that |
| 296 | # information in a variable so we can use it in if_changed and friends. |
| 297 | .PHONY: $(PHONY) |