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