blob: 0c356fb650220c6cd5d452d68a22eeb286d40d13 [file] [log] [blame]
Sasha Levin5634bd72013-06-13 18:41:17 -04001# file format version
2FILE_VERSION = 1
3
S. Lockwood-Childs0041898e2014-05-08 13:34:01 -04004LIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion)
Sasha Levin5634bd72013-06-13 18:41:17 -04005
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, or setting CROSS_COMPILE as a prefix.
18$(call allow-override,CC,$(CROSS_COMPILE)gcc)
19$(call allow-override,AR,$(CROSS_COMPILE)ar)
20
21INSTALL = install
22
23# Use DESTDIR for installing into a different root directory.
24# This is useful for building a package. The program will be
25# installed in this directory as if it was the root directory.
26# Then the build tool can move it later.
27DESTDIR ?=
28DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))'
29
30prefix ?= /usr/local
31libdir_relative = lib
32libdir = $(prefix)/$(libdir_relative)
33bindir_relative = bin
34bindir = $(prefix)/$(bindir_relative)
35
36export DESTDIR DESTDIR_SQ INSTALL
37
Jiri Olsa9244e2c2015-01-09 17:11:04 +010038MAKEFLAGS += --no-print-directory
39
40include ../../scripts/Makefile.include
41
Sasha Levin5634bd72013-06-13 18:41:17 -040042# copy a bit from Linux kbuild
43
44ifeq ("$(origin V)", "command line")
45 VERBOSE = $(V)
46endif
47ifndef VERBOSE
48 VERBOSE = 0
49endif
50
Jiri Olsa9244e2c2015-01-09 17:11:04 +010051ifeq ($(srctree),)
52srctree := $(patsubst %/,%,$(dir $(shell pwd)))
53srctree := $(patsubst %/,%,$(dir $(srctree)))
54srctree := $(patsubst %/,%,$(dir $(srctree)))
55#$(info Determined 'srctree' to be $(srctree))
Sasha Levin5634bd72013-06-13 18:41:17 -040056endif
57
Sasha Levin5634bd72013-06-13 18:41:17 -040058# Shell quotes
59libdir_SQ = $(subst ','\'',$(libdir))
60bindir_SQ = $(subst ','\'',$(bindir))
61
Jiri Olsa9244e2c2015-01-09 17:11:04 +010062LIB_IN := $(OUTPUT)liblockdep-in.o
63
Sasha Levin5634bd72013-06-13 18:41:17 -040064BIN_FILE = lockdep
Jiri Olsa9244e2c2015-01-09 17:11:04 +010065LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION)
Sasha Levin5634bd72013-06-13 18:41:17 -040066
67CONFIG_INCLUDES =
68CONFIG_LIBS =
69CONFIG_FLAGS =
70
71OBJ = $@
72N =
73
74export Q VERBOSE
75
Baruch Siach8baeccd2015-01-25 15:30:23 +020076INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES)
Sasha Levin5634bd72013-06-13 18:41:17 -040077
78# Set compile option CFLAGS if not set elsewhere
79CFLAGS ?= -g -DCONFIG_LOCKDEP -DCONFIG_STACKTRACE -DCONFIG_PROVE_LOCKING -DBITS_PER_LONG=__WORDSIZE -DLIBLOCKDEP_VERSION='"$(LIBLOCKDEP_VERSION)"' -rdynamic -O0 -g
Jiri Olsa9244e2c2015-01-09 17:11:04 +010080CFLAGS += -fPIC
Sasha Levin5634bd72013-06-13 18:41:17 -040081
82override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
83
84ifeq ($(VERBOSE),1)
85 Q =
Sasha Levin5634bd72013-06-13 18:41:17 -040086 print_shared_lib_compile =
87 print_install =
88else
89 Q = @
Jiri Olsa9244e2c2015-01-09 17:11:04 +010090 print_shared_lib_compile = echo ' LD '$(OBJ);
91 print_static_lib_build = echo ' LD '$(OBJ);
92 print_install = echo ' INSTALL '$1' to $(DESTDIR_SQ)$2';
Sasha Levin5634bd72013-06-13 18:41:17 -040093endif
94
Jiri Olsa9244e2c2015-01-09 17:11:04 +010095export srctree OUTPUT CC LD CFLAGS V
96build := -f $(srctree)/tools/build/Makefile.build dir=. obj
Sasha Levin5634bd72013-06-13 18:41:17 -040097
98do_compile_shared_library = \
99 ($(print_shared_lib_compile) \
Sasha Levinbe227b42014-04-01 11:42:18 -0400100 $(CC) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='"$@"';$(shell ln -s $@ liblockdep.so))
Sasha Levin5634bd72013-06-13 18:41:17 -0400101
102do_build_static_lib = \
103 ($(print_static_lib_build) \
104 $(RM) $@; $(AR) rcs $@ $^)
105
Sasha Levin5634bd72013-06-13 18:41:17 -0400106CMD_TARGETS = $(LIB_FILE)
107
108TARGETS = $(CMD_TARGETS)
109
110
111all: all_cmd
112
113all_cmd: $(CMD_TARGETS)
114
Jiri Olsa9244e2c2015-01-09 17:11:04 +0100115$(LIB_IN): force
116 $(Q)$(MAKE) $(build)=liblockdep
117
118liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN)
Sasha Levin5634bd72013-06-13 18:41:17 -0400119 $(Q)$(do_compile_shared_library)
120
Jiri Olsa9244e2c2015-01-09 17:11:04 +0100121liblockdep.a: $(LIB_IN)
Sasha Levin5634bd72013-06-13 18:41:17 -0400122 $(Q)$(do_build_static_lib)
123
Sasha Levin5634bd72013-06-13 18:41:17 -0400124tags: force
125 $(RM) tags
126 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
127 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
128
129TAGS: force
130 $(RM) TAGS
131 find . -name '*.[ch]' | xargs etags \
132 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
133
134define do_install
135 $(print_install) \
136 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
137 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
138 fi; \
139 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
140endef
141
142install_lib: all_cmd
143 $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
144 $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
145
146install: install_lib
147
148clean:
Sasha Levinad3b5642014-05-08 13:55:13 -0400149 $(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d
Sasha Levin5634bd72013-06-13 18:41:17 -0400150 $(RM) tags TAGS
151
Sasha Levin5634bd72013-06-13 18:41:17 -0400152PHONY += force
153force:
154
155# Declare the contents of the .PHONY variable as phony. We keep that
156# information in a variable so we can use it in if_changed and friends.
157.PHONY: $(PHONY)