1 # SPDX-License-Identifier: GPL-2.0
5 LIBLOCKDEP_VERSION
=$(shell make
--no-print-directory
-sC ..
/..
/.. kernelversion
)
7 # Makefiles suck: This macro sets a default value of $(2) for the
8 # variable named by $(1), unless the variable has been set by
9 # environment or command line. This is necessary for CC and AR
10 # because make sets default values, so the simpler ?= approach
11 # won't work as expected.
13 $(if
$(or
$(findstring environment
,$(origin $(1))),\
14 $(findstring command line
,$(origin $(1)))),,\
18 # Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix.
19 $(call allow-override
,CC
,$(CROSS_COMPILE
)gcc
)
20 $(call allow-override
,AR
,$(CROSS_COMPILE
)ar)
21 $(call allow-override
,LD
,$(CROSS_COMPILE
)ld)
25 # Use DESTDIR for installing into a different root directory.
26 # This is useful for building a package. The program will be
27 # installed in this directory as if it was the root directory.
28 # Then the build tool can move it later.
30 DESTDIR_SQ
= '$(subst ','\'',$(DESTDIR
))'
34 libdir = $(prefix)/$(libdir_relative)
36 bindir = $(prefix)/$(bindir_relative)
38 export DESTDIR DESTDIR_SQ INSTALL
40 MAKEFLAGS += --no-print-directory
42 include ../../scripts/Makefile.include
44 # copy a bit from Linux kbuild
46 ifeq ("$(origin V)", "command line")
54 srctree := $(patsubst %/,%,$(dir $(CURDIR)))
55 srctree := $(patsubst %/,%,$(dir $(srctree)))
56 srctree := $(patsubst %/,%,$(dir $(srctree)))
57 #$(info Determined 'srctree
' to be $(srctree))
61 libdir_SQ = $(subst ','\'',$(libdir))
62 bindir_SQ
= $(subst ','\'',$(bindir))
64 LIB_IN := $(OUTPUT)liblockdep-in.o
67 LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION)
78 INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES)
80 # Set compile option CFLAGS if not set elsewhere
81 CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
85 override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
89 print_shared_lib_compile =
93 print_shared_lib_compile = echo ' LD
'$(OBJ);
94 print_static_lib_build = echo ' LD
'$(OBJ);
95 print_install = echo ' INSTALL
'$1' to
$(DESTDIR_SQ
)$2';
100 export srctree OUTPUT CC LD CFLAGS V
101 include $(srctree)/tools/build/Makefile.include
103 do_compile_shared_library = \
104 ($(print_shared_lib_compile) \
105 $(CC) $(LDFLAGS) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='$(@F
)';$(shell ln -sf $(@F) $(@D)/liblockdep.so))
107 do_build_static_lib = \
108 ($(print_static_lib_build) \
109 $(RM) $@; $(AR) rcs $@ $^)
111 CMD_TARGETS = $(LIB_FILE)
113 TARGETS = $(CMD_TARGETS)
118 all_cmd: $(CMD_TARGETS)
121 $(Q)$(MAKE) $(build)=liblockdep
123 $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN)
124 $(Q)$(do_compile_shared_library)
126 $(OUTPUT)liblockdep.a: $(LIB_IN)
127 $(Q)$(do_build_static_lib)
131 find . -name '*.
[ch
]' | xargs ctags --extra=+f --c-kinds=+px \
132 --regex-c++='/_PE\
(([^
,)]*).
*/TEP_ERRNO__\
1/'
136 find . -name '*.
[ch
]' | xargs etags \
137 --regex='/_PE
(\
([^
,)]*\
).
*/TEP_ERRNO__\
1/'
141 if [ ! -d '$(DESTDIR_SQ
)$2' ]; then \
142 $(INSTALL) -d -m 755 '$(DESTDIR_SQ
)$2'; \
144 $(INSTALL) $1 '$(DESTDIR_SQ
)$2'
148 $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
149 $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
154 $(RM) $(OUTPUT)*.o *~ $(TARGETS) $(OUTPUT)*.a $(OUTPUT)*liblockdep*.so* $(VERSION_FILES) $(OUTPUT).*.d $(OUTPUT).*.cmd
160 # Declare the contents of the .PHONY variable as phony. We keep that
161 # information in a variable so we can use it in if_changed and friends.