xref: /OK3568_Linux_fs/kernel/tools/lib/lockdep/Makefile (revision 4882a59341e53eb6f0b4789bf948001014eff981)
1*4882a593Smuzhiyun# SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun# file format version
3*4882a593SmuzhiyunFILE_VERSION = 1
4*4882a593Smuzhiyun
5*4882a593SmuzhiyunLIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion)
6*4882a593Smuzhiyun
7*4882a593Smuzhiyun# Makefiles suck: This macro sets a default value of $(2) for the
8*4882a593Smuzhiyun# variable named by $(1), unless the variable has been set by
9*4882a593Smuzhiyun# environment or command line. This is necessary for CC and AR
10*4882a593Smuzhiyun# because make sets default values, so the simpler ?= approach
11*4882a593Smuzhiyun# won't work as expected.
12*4882a593Smuzhiyundefine allow-override
13*4882a593Smuzhiyun  $(if $(or $(findstring environment,$(origin $(1))),\
14*4882a593Smuzhiyun            $(findstring command line,$(origin $(1)))),,\
15*4882a593Smuzhiyun    $(eval $(1) = $(2)))
16*4882a593Smuzhiyunendef
17*4882a593Smuzhiyun
18*4882a593Smuzhiyun# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix.
19*4882a593Smuzhiyun$(call allow-override,CC,$(CROSS_COMPILE)gcc)
20*4882a593Smuzhiyun$(call allow-override,AR,$(CROSS_COMPILE)ar)
21*4882a593Smuzhiyun$(call allow-override,LD,$(CROSS_COMPILE)ld)
22*4882a593Smuzhiyun
23*4882a593SmuzhiyunINSTALL = install
24*4882a593Smuzhiyun
25*4882a593Smuzhiyun# Use DESTDIR for installing into a different root directory.
26*4882a593Smuzhiyun# This is useful for building a package. The program will be
27*4882a593Smuzhiyun# installed in this directory as if it was the root directory.
28*4882a593Smuzhiyun# Then the build tool can move it later.
29*4882a593SmuzhiyunDESTDIR ?=
30*4882a593SmuzhiyunDESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
31*4882a593Smuzhiyun
32*4882a593Smuzhiyunprefix ?= /usr/local
33*4882a593Smuzhiyunlibdir_relative = lib
34*4882a593Smuzhiyunlibdir = $(prefix)/$(libdir_relative)
35*4882a593Smuzhiyunbindir_relative = bin
36*4882a593Smuzhiyunbindir = $(prefix)/$(bindir_relative)
37*4882a593Smuzhiyun
38*4882a593Smuzhiyunexport DESTDIR DESTDIR_SQ INSTALL
39*4882a593Smuzhiyun
40*4882a593SmuzhiyunMAKEFLAGS += --no-print-directory
41*4882a593Smuzhiyun
42*4882a593Smuzhiyuninclude ../../scripts/Makefile.include
43*4882a593Smuzhiyun
44*4882a593Smuzhiyun# copy a bit from Linux kbuild
45*4882a593Smuzhiyun
46*4882a593Smuzhiyunifeq ("$(origin V)", "command line")
47*4882a593Smuzhiyun  VERBOSE = $(V)
48*4882a593Smuzhiyunendif
49*4882a593Smuzhiyunifndef VERBOSE
50*4882a593Smuzhiyun  VERBOSE = 0
51*4882a593Smuzhiyunendif
52*4882a593Smuzhiyun
53*4882a593Smuzhiyunifeq ($(srctree),)
54*4882a593Smuzhiyunsrctree := $(patsubst %/,%,$(dir $(CURDIR)))
55*4882a593Smuzhiyunsrctree := $(patsubst %/,%,$(dir $(srctree)))
56*4882a593Smuzhiyunsrctree := $(patsubst %/,%,$(dir $(srctree)))
57*4882a593Smuzhiyun#$(info Determined 'srctree' to be $(srctree))
58*4882a593Smuzhiyunendif
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun# Shell quotes
61*4882a593Smuzhiyunlibdir_SQ = $(subst ','\'',$(libdir))
62*4882a593Smuzhiyunbindir_SQ = $(subst ','\'',$(bindir))
63*4882a593Smuzhiyun
64*4882a593SmuzhiyunLIB_IN := $(OUTPUT)liblockdep-in.o
65*4882a593Smuzhiyun
66*4882a593SmuzhiyunBIN_FILE = lockdep
67*4882a593SmuzhiyunLIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION)
68*4882a593Smuzhiyun
69*4882a593SmuzhiyunCONFIG_INCLUDES =
70*4882a593SmuzhiyunCONFIG_LIBS	=
71*4882a593SmuzhiyunCONFIG_FLAGS	=
72*4882a593Smuzhiyun
73*4882a593SmuzhiyunOBJ		= $@
74*4882a593SmuzhiyunN		=
75*4882a593Smuzhiyun
76*4882a593Smuzhiyunexport Q VERBOSE
77*4882a593Smuzhiyun
78*4882a593SmuzhiyunINCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES)
79*4882a593Smuzhiyun
80*4882a593Smuzhiyun# Set compile option CFLAGS if not set elsewhere
81*4882a593SmuzhiyunCFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
82*4882a593SmuzhiyunCFLAGS += -fPIC
83*4882a593SmuzhiyunCFLAGS += -Wall
84*4882a593Smuzhiyun
85*4882a593Smuzhiyunoverride CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
86*4882a593Smuzhiyun
87*4882a593Smuzhiyunifeq ($(VERBOSE),1)
88*4882a593Smuzhiyun  Q =
89*4882a593Smuzhiyun  print_shared_lib_compile =
90*4882a593Smuzhiyun  print_install =
91*4882a593Smuzhiyunelse
92*4882a593Smuzhiyun  Q = @
93*4882a593Smuzhiyun  print_shared_lib_compile =	echo '  LD       '$(OBJ);
94*4882a593Smuzhiyun  print_static_lib_build =	echo '  LD       '$(OBJ);
95*4882a593Smuzhiyun  print_install =		echo '  INSTALL  '$1'	to	$(DESTDIR_SQ)$2';
96*4882a593Smuzhiyunendif
97*4882a593Smuzhiyun
98*4882a593Smuzhiyunall:
99*4882a593Smuzhiyun
100*4882a593Smuzhiyunexport srctree OUTPUT CC LD CFLAGS V
101*4882a593Smuzhiyuninclude $(srctree)/tools/build/Makefile.include
102*4882a593Smuzhiyun
103*4882a593Smuzhiyundo_compile_shared_library =			\
104*4882a593Smuzhiyun	($(print_shared_lib_compile)		\
105*4882a593Smuzhiyun	$(CC) $(LDFLAGS) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='$(@F)';$(shell ln -sf $(@F) $(@D)/liblockdep.so))
106*4882a593Smuzhiyun
107*4882a593Smuzhiyundo_build_static_lib =				\
108*4882a593Smuzhiyun	($(print_static_lib_build)		\
109*4882a593Smuzhiyun	$(RM) $@;  $(AR) rcs $@ $^)
110*4882a593Smuzhiyun
111*4882a593SmuzhiyunCMD_TARGETS = $(LIB_FILE)
112*4882a593Smuzhiyun
113*4882a593SmuzhiyunTARGETS = $(CMD_TARGETS)
114*4882a593Smuzhiyun
115*4882a593Smuzhiyun
116*4882a593Smuzhiyunall: fixdep all_cmd
117*4882a593Smuzhiyun
118*4882a593Smuzhiyunall_cmd: $(CMD_TARGETS)
119*4882a593Smuzhiyun
120*4882a593Smuzhiyun$(LIB_IN): force
121*4882a593Smuzhiyun	$(Q)$(MAKE) $(build)=liblockdep
122*4882a593Smuzhiyun
123*4882a593Smuzhiyun$(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN)
124*4882a593Smuzhiyun	$(Q)$(do_compile_shared_library)
125*4882a593Smuzhiyun
126*4882a593Smuzhiyun$(OUTPUT)liblockdep.a: $(LIB_IN)
127*4882a593Smuzhiyun	$(Q)$(do_build_static_lib)
128*4882a593Smuzhiyun
129*4882a593Smuzhiyuntags:	force
130*4882a593Smuzhiyun	$(RM) tags
131*4882a593Smuzhiyun	find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
132*4882a593Smuzhiyun	--regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/'
133*4882a593Smuzhiyun
134*4882a593SmuzhiyunTAGS:	force
135*4882a593Smuzhiyun	$(RM) TAGS
136*4882a593Smuzhiyun	find . -name '*.[ch]' | xargs etags \
137*4882a593Smuzhiyun	--regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/'
138*4882a593Smuzhiyun
139*4882a593Smuzhiyundefine do_install
140*4882a593Smuzhiyun	$(print_install)				\
141*4882a593Smuzhiyun	if [ ! -d '$(DESTDIR_SQ)$2' ]; then		\
142*4882a593Smuzhiyun		$(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2';	\
143*4882a593Smuzhiyun	fi;						\
144*4882a593Smuzhiyun	$(INSTALL) $1 '$(DESTDIR_SQ)$2'
145*4882a593Smuzhiyunendef
146*4882a593Smuzhiyun
147*4882a593Smuzhiyuninstall_lib: all_cmd
148*4882a593Smuzhiyun	$(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
149*4882a593Smuzhiyun	$(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
150*4882a593Smuzhiyun
151*4882a593Smuzhiyuninstall: install_lib
152*4882a593Smuzhiyun
153*4882a593Smuzhiyunclean:
154*4882a593Smuzhiyun	$(RM) $(OUTPUT)*.o *~ $(TARGETS) $(OUTPUT)*.a $(OUTPUT)*liblockdep*.so* $(VERSION_FILES) $(OUTPUT).*.d $(OUTPUT).*.cmd
155*4882a593Smuzhiyun	$(RM) tags TAGS
156*4882a593Smuzhiyun
157*4882a593SmuzhiyunPHONY += force
158*4882a593Smuzhiyunforce:
159*4882a593Smuzhiyun
160*4882a593Smuzhiyun# Declare the contents of the .PHONY variable as phony.  We keep that
161*4882a593Smuzhiyun# information in a variable so we can use it in if_changed and friends.
162*4882a593Smuzhiyun.PHONY: $(PHONY)
163