Back to home page

OSCL-LXR

 
 

    


0001 # SPDX-License-Identifier: GPL-2.0
0002 
0003 #MAKEFLAGS += --no-print-directory
0004 
0005 
0006 # Makefiles suck: This macro sets a default value of $(2) for the
0007 # variable named by $(1), unless the variable has been set by
0008 # environment or command line. This is necessary for CC and AR
0009 # because make sets default values, so the simpler ?= approach
0010 # won't work as expected.
0011 define allow-override
0012   $(if $(or $(findstring environment,$(origin $(1))),\
0013             $(findstring command line,$(origin $(1)))),,\
0014     $(eval $(1) = $(2)))
0015 endef
0016 
0017 # Allow setting CC and AR, or setting CROSS_COMPILE as a prefix.
0018 $(call allow-override,CC,$(CROSS_COMPILE)gcc)
0019 $(call allow-override,AR,$(CROSS_COMPILE)ar)
0020 $(call allow-override,NM,$(CROSS_COMPILE)nm)
0021 $(call allow-override,PKG_CONFIG,pkg-config)
0022 
0023 EXT = -std=gnu99
0024 INSTALL = install
0025 
0026 # Use DESTDIR for installing into a different root directory.
0027 # This is useful for building a package. The program will be
0028 # installed in this directory as if it was the root directory.
0029 # Then the build tool can move it later.
0030 DESTDIR ?=
0031 DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
0032 
0033 LP64 := $(shell echo __LP64__ | ${CC} ${CFLAGS} -E -x c - | tail -n 1)
0034 ifeq ($(LP64), 1)
0035   libdir_relative_tmp = lib64
0036 else
0037   libdir_relative_tmp = lib
0038 endif
0039 
0040 libdir_relative ?= $(libdir_relative_tmp)
0041 prefix ?= /usr/local
0042 libdir = $(prefix)/$(libdir_relative)
0043 
0044 set_plugin_dir := 1
0045 
0046 # Set plugin_dir to preffered global plugin location
0047 # If we install under $HOME directory we go under
0048 # $(HOME)/.local/lib/traceevent/plugins
0049 #
0050 # We dont set PLUGIN_DIR in case we install under $HOME
0051 # directory, because by default the code looks under:
0052 # $(HOME)/.local/lib/traceevent/plugins by default.
0053 #
0054 ifeq ($(plugin_dir),)
0055 ifeq ($(prefix),$(HOME))
0056 override plugin_dir = $(HOME)/.local/lib/traceevent/plugins
0057 set_plugin_dir := 0
0058 else
0059 override plugin_dir = $(libdir)/traceevent/plugins
0060 endif
0061 endif
0062 
0063 ifeq ($(set_plugin_dir),1)
0064 PLUGIN_DIR = -DPLUGIN_DIR="$(plugin_dir)"
0065 PLUGIN_DIR_SQ = '$(subst ','\'',$(PLUGIN_DIR))'
0066 endif
0067 
0068 include ../../../scripts/Makefile.include
0069 
0070 # copy a bit from Linux kbuild
0071 
0072 ifeq ("$(origin V)", "command line")
0073   VERBOSE = $(V)
0074 endif
0075 ifndef VERBOSE
0076   VERBOSE = 0
0077 endif
0078 
0079 ifeq ($(srctree),)
0080 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
0081 srctree := $(patsubst %/,%,$(dir $(srctree)))
0082 srctree := $(patsubst %/,%,$(dir $(srctree)))
0083 srctree := $(patsubst %/,%,$(dir $(srctree)))
0084 #$(info Determined 'srctree' to be $(srctree))
0085 endif
0086 
0087 export prefix libdir src obj
0088 
0089 # Shell quotes
0090 plugin_dir_SQ = $(subst ','\'',$(plugin_dir))
0091 
0092 CONFIG_INCLUDES =
0093 CONFIG_LIBS    =
0094 CONFIG_FLAGS   =
0095 
0096 OBJ            = $@
0097 N              =
0098 
0099 INCLUDES = -I. -I.. -I $(srctree)/tools/include $(CONFIG_INCLUDES)
0100 
0101 # Set compile option CFLAGS
0102 ifdef EXTRA_CFLAGS
0103   CFLAGS := $(EXTRA_CFLAGS)
0104 else
0105   CFLAGS := -g -Wall
0106 endif
0107 
0108 # Append required CFLAGS
0109 override CFLAGS += -fPIC
0110 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
0111 override CFLAGS += $(udis86-flags) -D_GNU_SOURCE
0112 
0113 ifeq ($(VERBOSE),1)
0114   Q =
0115 else
0116   Q = @
0117 endif
0118 
0119 # Disable command line variables (CFLAGS) override from top
0120 # level Makefile (perf), otherwise build Makefile will get
0121 # the same command line setup.
0122 MAKEOVERRIDES=
0123 
0124 export srctree OUTPUT CC LD CFLAGS V
0125 
0126 build := -f $(srctree)/tools/build/Makefile.build dir=. obj
0127 
0128 DYNAMIC_LIST_FILE := $(OUTPUT)libtraceevent-dynamic-list
0129 
0130 PLUGINS  = plugin_jbd2.so
0131 PLUGINS += plugin_hrtimer.so
0132 PLUGINS += plugin_kmem.so
0133 PLUGINS += plugin_kvm.so
0134 PLUGINS += plugin_mac80211.so
0135 PLUGINS += plugin_sched_switch.so
0136 PLUGINS += plugin_function.so
0137 PLUGINS += plugin_futex.so
0138 PLUGINS += plugin_xen.so
0139 PLUGINS += plugin_scsi.so
0140 PLUGINS += plugin_cfg80211.so
0141 PLUGINS += plugin_tlb.so
0142 
0143 PLUGINS    := $(addprefix $(OUTPUT),$(PLUGINS))
0144 PLUGINS_IN := $(PLUGINS:.so=-in.o)
0145 
0146 plugins: $(PLUGINS) $(DYNAMIC_LIST_FILE)
0147 
0148 __plugin_obj = $(notdir $@)
0149   plugin_obj = $(__plugin_obj:-in.o=)
0150 
0151 $(PLUGINS_IN): force
0152         $(Q)$(MAKE) $(build)=$(plugin_obj)
0153 
0154 $(OUTPUT)libtraceevent-dynamic-list: $(PLUGINS)
0155         $(QUIET_GEN)$(call do_generate_dynamic_list_file, $(PLUGINS), $@)
0156 
0157 $(OUTPUT)%.so: $(OUTPUT)%-in.o
0158         $(QUIET_LINK)$(CC) $(CFLAGS) -shared $(LDFLAGS) -nostartfiles -o $@ $^
0159 
0160 define update_dir
0161   (echo $1 > $@.tmp;                           \
0162    if [ -r $@ ] && cmp -s $@ $@.tmp; then      \
0163      rm -f $@.tmp;                             \
0164    else                                                \
0165      echo '  UPDATE                 $@';       \
0166      mv -f $@.tmp $@;                          \
0167    fi);
0168 endef
0169 
0170 tags:   force
0171         $(RM) tags
0172         find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
0173         --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
0174 
0175 TAGS:   force
0176         $(RM) TAGS
0177         find . -name '*.[ch]' | xargs etags \
0178         --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
0179 
0180 define do_install_mkdir
0181         if [ ! -d '$(DESTDIR_SQ)$1' ]; then             \
0182                 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$1'; \
0183         fi
0184 endef
0185 
0186 define do_install
0187         $(call do_install_mkdir,$2);                    \
0188         $(INSTALL) $(if $3,-m $3,) $1 '$(DESTDIR_SQ)$2'
0189 endef
0190 
0191 define do_install_plugins
0192        for plugin in $1; do                            \
0193          $(call do_install,$$plugin,$(plugin_dir_SQ)); \
0194        done
0195 endef
0196 
0197 define do_generate_dynamic_list_file
0198         symbol_type=`$(NM) -u -D $1 | awk 'NF>1 {print $$1}' | \
0199         xargs echo "U w W" | tr 'w ' 'W\n' | sort -u | xargs echo`;\
0200         if [ "$$symbol_type" = "U W" ];then                             \
0201                 (echo '{';                                              \
0202                 $(NM) -u -D $1 | awk 'NF>1 {sub("@.*", "", $$2); print "\t"$$2";"}' | sort -u;\
0203                 echo '};';                                              \
0204                 ) > $2;                                                 \
0205         else                                                            \
0206                 (echo Either missing one of [$1] or bad version of $(NM)) 1>&2;\
0207                 fi
0208 endef
0209 
0210 install: $(PLUGINS)
0211         $(call QUIET_INSTALL, trace_plugins) \
0212         $(call do_install_plugins, $(PLUGINS))
0213 
0214 clean:
0215         $(call QUIET_CLEAN, trace_plugins) \
0216                 $(RM) *.o *~ $(TARGETS) *.a *.so $(VERSION_FILES) .*.d .*.cmd; \
0217                 $(RM) $(OUTPUT)libtraceevent-dynamic-list \
0218                 $(RM) TRACEEVENT-CFLAGS tags TAGS;
0219 
0220 PHONY += force plugins
0221 force:
0222 
0223 # Declare the contents of the .PHONY variable as phony.  We keep that
0224 # information in a variable so we can use it in if_changed and friends.
0225 .PHONY: $(PHONY)