Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 # trace-cmd version
0003 EP_VERSION = 1
0004 EP_PATCHLEVEL = 1
0005 EP_EXTRAVERSION = 0
0006 
0007 # file format version
0008 FILE_VERSION = 6
0009 
0010 MAKEFLAGS += --no-print-directory
0011 
0012 
0013 # Makefiles suck: This macro sets a default value of $(2) for the
0014 # variable named by $(1), unless the variable has been set by
0015 # environment or command line. This is necessary for CC and AR
0016 # because make sets default values, so the simpler ?= approach
0017 # won't work as expected.
0018 define allow-override
0019   $(if $(or $(findstring environment,$(origin $(1))),\
0020             $(findstring command line,$(origin $(1)))),,\
0021     $(eval $(1) = $(2)))
0022 endef
0023 
0024 # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
0025 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
0026 $(call allow-override,AR,$(CROSS_COMPILE)ar)
0027 $(call allow-override,NM,$(CROSS_COMPILE)nm)
0028 $(call allow-override,PKG_CONFIG,pkg-config)
0029 
0030 EXT = -std=gnu99
0031 INSTALL = install
0032 
0033 # Use DESTDIR for installing into a different root directory.
0034 # This is useful for building a package. The program will be
0035 # installed in this directory as if it was the root directory.
0036 # Then the build tool can move it later.
0037 DESTDIR ?=
0038 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
0039 
0040 LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
0041 ifeq ($(LP64), 1)
0042   libdir_relative_temp = lib64
0043 else
0044   libdir_relative_temp = lib
0045 endif
0046 
0047 libdir_relative ?= $(libdir_relative_temp)
0048 prefix ?= /usr/local
0049 libdir = $(prefix)/$(libdir_relative)
0050 man_dir = $(prefix)/share/man
0051 man_dir_SQ = '$(subst ','\'',$(man_dir))'
0052 pkgconfig_dir ?= $(word 1,$(shell $(PKG_CONFIG)                 \
0053                         --variable pc_path pkg-config | tr ":" " "))
0054 includedir_relative = traceevent
0055 includedir = $(prefix)/include/$(includedir_relative)
0056 includedir_SQ = '$(subst ','\'',$(includedir))'
0057 
0058 export man_dir man_dir_SQ INSTALL
0059 export DESTDIR DESTDIR_SQ
0060 export EVENT_PARSE_VERSION
0061 
0062 include ../../scripts/Makefile.include
0063 
0064 # copy a bit from Linux kbuild
0065 
0066 ifeq ("$(origin V)", "command line")
0067   VERBOSE = $(V)
0068 endif
0069 ifndef VERBOSE
0070   VERBOSE = 0
0071 endif
0072 
0073 ifeq ($(srctree),)
0074 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
0075 srctree := $(patsubst %/,%,$(dir $(srctree)))
0076 srctree := $(patsubst %/,%,$(dir $(srctree)))
0077 #$(info Determined 'srctree' to be $(srctree))
0078 endif
0079 
0080 export prefix libdir src obj
0081 
0082 # Shell quotes
0083 libdir_SQ = $(subst ','\'',$(libdir))
0084 libdir_relative_SQ = $(subst ','\'',$(libdir_relative))
0085 
0086 CONFIG_INCLUDES = 
0087 CONFIG_LIBS     =
0088 CONFIG_FLAGS    =
0089 
0090 VERSION         = $(EP_VERSION)
0091 PATCHLEVEL      = $(EP_PATCHLEVEL)
0092 EXTRAVERSION    = $(EP_EXTRAVERSION)
0093 
0094 OBJ             = $@
0095 N               =
0096 
0097 EVENT_PARSE_VERSION = $(EP_VERSION).$(EP_PATCHLEVEL).$(EP_EXTRAVERSION)
0098 
0099 LIB_TARGET  = libtraceevent.a libtraceevent.so.$(EVENT_PARSE_VERSION)
0100 LIB_INSTALL = libtraceevent.a libtraceevent.so*
0101 LIB_INSTALL := $(addprefix $(OUTPUT),$(LIB_INSTALL))
0102 
0103 INCLUDES = -I. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
0104 
0105 # Set compile option CFLAGS
0106 ifdef EXTRA_CFLAGS
0107   CFLAGS := $(EXTRA_CFLAGS)
0108 else
0109   CFLAGS := -g -Wall
0110 endif
0111 
0112 # Append required CFLAGS
0113 override CFLAGS += -fPIC
0114 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
0115 override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
0116 
0117 ifeq ($(VERBOSE),1)
0118   Q =
0119 else
0120   Q = @
0121 endif
0122 
0123 # Disable command line variables (CFLAGS) override from top
0124 # level Makefile (perf), otherwise build Makefile will get
0125 # the same command line setup.
0126 MAKEOVERRIDES=
0127 
0128 export srctree OUTPUT CC LD CFLAGS V
0129 build := -f $(srctree)/tools/build/Makefile.build dir=. obj
0130 
0131 TE_IN      := $(OUTPUT)libtraceevent-in.o
0132 LIB_TARGET := $(addprefix $(OUTPUT),$(LIB_TARGET))
0133 
0134 CMD_TARGETS = $(LIB_TARGET)
0135 
0136 TARGETS = $(CMD_TARGETS)
0137 
0138 all: all_cmd plugins
0139 
0140 all_cmd: $(CMD_TARGETS)
0141 
0142 $(TE_IN): force
0143         $(Q)$(MAKE) $(build)=libtraceevent
0144 
0145 $(OUTPUT)libtraceevent.so.$(EVENT_PARSE_VERSION): $(TE_IN)
0146         $(QUIET_LINK)$(CC) --shared $(LDFLAGS) $^ -Wl,-soname,libtraceevent.so.$(EP_VERSION) -o $@
0147         @ln -sf $(@F) $(OUTPUT)libtraceevent.so
0148         @ln -sf $(@F) $(OUTPUT)libtraceevent.so.$(EP_VERSION)
0149 
0150 $(OUTPUT)libtraceevent.a: $(TE_IN)
0151         $(QUIET_LINK)$(RM) $@; $(AR) rcs $@ $^
0152 
0153 $(OUTPUT)%.so: $(OUTPUT)%-in.o
0154         $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^
0155 
0156 define make_version.h
0157   (echo '/* This file is automatically generated. Do not modify. */';           \
0158    echo \#define VERSION_CODE $(shell                                           \
0159    expr $(VERSION) \* 256 + $(PATCHLEVEL));                                     \
0160    echo '#define EXTRAVERSION ' $(EXTRAVERSION);                                \
0161    echo '#define VERSION_STRING "'$(VERSION).$(PATCHLEVEL).$(EXTRAVERSION)'"';  \
0162    echo '#define FILE_VERSION '$(FILE_VERSION);                                 \
0163   ) > $1
0164 endef
0165 
0166 define update_version.h
0167   ($(call make_version.h, $@.tmp);              \
0168     if [ -r $@ ] && cmp -s $@ $@.tmp; then      \
0169       rm -f $@.tmp;                             \
0170     else                                        \
0171       echo '  UPDATE                 $@';       \
0172       mv -f $@.tmp $@;                          \
0173     fi);
0174 endef
0175 
0176 ep_version.h: force
0177         $(Q)$(N)$(call update_version.h)
0178 
0179 VERSION_FILES = ep_version.h
0180 
0181 define update_dir
0182   (echo $1 > $@.tmp;                            \
0183    if [ -r $@ ] && cmp -s $@ $@.tmp; then       \
0184      rm -f $@.tmp;                              \
0185    else                                         \
0186      echo '  UPDATE                 $@';        \
0187      mv -f $@.tmp $@;                           \
0188    fi);
0189 endef
0190 
0191 tags:   force
0192         $(RM) tags
0193         find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
0194         --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
0195 
0196 TAGS:   force
0197         $(RM) TAGS
0198         find . -name '*.[ch]' | xargs etags \
0199         --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
0200 
0201 define do_install_mkdir
0202         if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
0203                 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
0204         fi
0205 endef
0206 
0207 define do_install
0208         $(call do_install_mkdir,$2);                    \
0209         $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
0210 endef
0211 
0212 PKG_CONFIG_SOURCE_FILE = libtraceevent.pc
0213 PKG_CONFIG_FILE := $(addprefix $(OUTPUT),$(PKG_CONFIG_SOURCE_FILE))
0214 define do_install_pkgconfig_file
0215         if [ -n "${pkgconfig_dir}" ]; then                                      \
0216                 cp -f ${PKG_CONFIG_SOURCE_FILE}.template ${PKG_CONFIG_FILE};    \
0217                 sed -i "s|INSTALL_PREFIX|${1}|g" ${PKG_CONFIG_FILE};            \
0218                 sed -i "s|LIB_VERSION|${EVENT_PARSE_VERSION}|g" ${PKG_CONFIG_FILE}; \
0219                 sed -i "s|LIB_DIR|${libdir}|g" ${PKG_CONFIG_FILE}; \
0220                 sed -i "s|HEADER_DIR|$(includedir)|g" ${PKG_CONFIG_FILE}; \
0221                 $(call do_install,$(PKG_CONFIG_FILE),$(pkgconfig_dir),644);     \
0222         else                                                                    \
0223                 (echo Failed to locate pkg-config directory) 1>&2;              \
0224         fi
0225 endef
0226 
0227 install_lib: all_cmd install_plugins install_headers install_pkgconfig
0228         $(call QUIET_INSTALL, $(LIB_TARGET)) \
0229                 $(call do_install_mkdir,$(libdir_SQ)); \
0230                 cp -fpR $(LIB_INSTALL) $(DESTDIR)$(libdir_SQ)
0231 
0232 install_pkgconfig:
0233         $(call QUIET_INSTALL, $(PKG_CONFIG_FILE)) \
0234                 $(call do_install_pkgconfig_file,$(prefix))
0235 
0236 install_headers:
0237         $(call QUIET_INSTALL, headers) \
0238                 $(call do_install,event-parse.h,$(includedir_SQ),644); \
0239                 $(call do_install,event-utils.h,$(includedir_SQ),644); \
0240                 $(call do_install,trace-seq.h,$(includedir_SQ),644); \
0241                 $(call do_install,kbuffer.h,$(includedir_SQ),644)
0242 
0243 install: install_lib
0244 
0245 clean: clean_plugins
0246         $(call QUIET_CLEAN, libtraceevent) \
0247                 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \
0248                 $(RM) TRACEEVENT-CFLAGS tags TAGS; \
0249                 $(RM) $(PKG_CONFIG_FILE)
0250 
0251 PHONY += doc
0252 doc:
0253         $(call descend,Documentation)
0254 
0255 PHONY += doc-clean
0256 doc-clean:
0257         $(call descend,Documentation,clean)
0258 
0259 PHONY += doc-install
0260 doc-install:
0261         $(call descend,Documentation,install)
0262 
0263 PHONY += doc-uninstall
0264 doc-uninstall:
0265         $(call descend,Documentation,uninstall)
0266 
0267 PHONY += help
0268 help:
0269         @echo 'Possible targets:'
0270         @echo''
0271         @echo '  all                 - default, compile the library and the'\
0272                                       'plugins'
0273         @echo '  plugins             - compile the plugins'
0274         @echo '  install             - install the library, the plugins,'\
0275                                         'the header and pkgconfig files'
0276         @echo '  clean               - clean the library and the plugins object files'
0277         @echo '  doc                 - compile the documentation files - man'\
0278                                         'and html pages, in the Documentation directory'
0279         @echo '  doc-clean           - clean the documentation files'
0280         @echo '  doc-install         - install the man pages'
0281         @echo '  doc-uninstall       - uninstall the man pages'
0282         @echo''
0283 
0284 PHONY += plugins
0285 plugins:
0286         $(call descend,plugins)
0287 
0288 PHONY += install_plugins
0289 install_plugins:
0290         $(call descend,plugins,install)
0291 
0292 PHONY += clean_plugins
0293 clean_plugins:
0294         $(call descend,plugins,clean)
0295 
0296 force:
0297 
0298 # Declare the contents of the .PHONY variable as phony.  We keep that
0299 # information in a variable so we can use it in if_changed and friends.
0300 .PHONY: $(PHONY)