blob: 18ffccf004264d202632990d40227c27c41d27ad [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
Eunbong Songd1e40e52015-04-24 04:36:27 +000017# Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix.
Sasha Levin5634bd72013-06-13 18:41:17 -040018$(call allow-override,CC,$(CROSS_COMPILE)gcc)
19$(call allow-override,AR,$(CROSS_COMPILE)ar)
Eunbong Songd1e40e52015-04-24 04:36:27 +000020$(call allow-override,LD,$(CROSS_COMPILE)ld)
Sasha Levin5634bd72013-06-13 18:41:17 -040021
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
Jiri Olsa9244e2c2015-01-09 17:11:04 +010039MAKEFLAGS += --no-print-directory
40
41include ../../scripts/Makefile.include
42
Sasha Levin5634bd72013-06-13 18:41:17 -040043# copy a bit from Linux kbuild
44
45ifeq ("$(origin V)", "command line")
46 VERBOSE = $(V)
47endif
48ifndef VERBOSE
49 VERBOSE = 0
50endif
51
Jiri Olsa9244e2c2015-01-09 17:11:04 +010052ifeq ($(srctree),)
53srctree := $(patsubst %/,%,$(dir $(shell pwd)))
54srctree := $(patsubst %/,%,$(dir $(srctree)))
55srctree := $(patsubst %/,%,$(dir $(srctree)))
56#$(info Determined 'srctree' to be $(srctree))
Sasha Levin5634bd72013-06-13 18:41:17 -040057endif
58
Sasha Levin5634bd72013-06-13 18:41:17 -040059# Shell quotes
60libdir_SQ = $(subst ','\'',$(libdir))
61bindir_SQ = $(subst ','\'',$(bindir))
62
Jiri Olsa9244e2c2015-01-09 17:11:04 +010063LIB_IN := $(OUTPUT)liblockdep-in.o
64
Sasha Levin5634bd72013-06-13 18:41:17 -040065BIN_FILE = lockdep
Jiri Olsa9244e2c2015-01-09 17:11:04 +010066LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION)
Sasha Levin5634bd72013-06-13 18:41:17 -040067
68CONFIG_INCLUDES =
69CONFIG_LIBS =
70CONFIG_FLAGS =
71
72OBJ = $@
73N =
74
75export Q VERBOSE
76
Baruch Siach8baeccd2015-01-25 15:30:23 +020077INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES)
Sasha Levin5634bd72013-06-13 18:41:17 -040078
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
Jiri Olsa9244e2c2015-01-09 17:11:04 +010081CFLAGS += -fPIC
Sasha Levin5634bd72013-06-13 18:41:17 -040082
83override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ)
84
85ifeq ($(VERBOSE),1)
86 Q =
Sasha Levin5634bd72013-06-13 18:41:17 -040087 print_shared_lib_compile =
88 print_install =
89else
90 Q = @
Jiri Olsa9244e2c2015-01-09 17:11:04 +010091 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';
Sasha Levin5634bd72013-06-13 18:41:17 -040094endif
95
Jiri Olsa9244e2c2015-01-09 17:11:04 +010096export srctree OUTPUT CC LD CFLAGS V
97build := -f $(srctree)/tools/build/Makefile.build dir=. obj
Sasha Levin5634bd72013-06-13 18:41:17 -040098
99do_compile_shared_library = \
100 ($(print_shared_lib_compile) \
Sasha Levinbe227b42014-04-01 11:42:18 -0400101 $(CC) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='"$@"';$(shell ln -s $@ liblockdep.so))
Sasha Levin5634bd72013-06-13 18:41:17 -0400102
103do_build_static_lib = \
104 ($(print_static_lib_build) \
105 $(RM) $@; $(AR) rcs $@ $^)
106
Sasha Levin5634bd72013-06-13 18:41:17 -0400107CMD_TARGETS = $(LIB_FILE)
108
109TARGETS = $(CMD_TARGETS)
110
111
112all: all_cmd
113
114all_cmd: $(CMD_TARGETS)
115
Jiri Olsa9244e2c2015-01-09 17:11:04 +0100116$(LIB_IN): force
117 $(Q)$(MAKE) $(build)=liblockdep
118
119liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN)
Sasha Levin5634bd72013-06-13 18:41:17 -0400120 $(Q)$(do_compile_shared_library)
121
Jiri Olsa9244e2c2015-01-09 17:11:04 +0100122liblockdep.a: $(LIB_IN)
Sasha Levin5634bd72013-06-13 18:41:17 -0400123 $(Q)$(do_build_static_lib)
124
Sasha Levin5634bd72013-06-13 18:41:17 -0400125tags: force
126 $(RM) tags
127 find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \
128 --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/'
129
130TAGS: force
131 $(RM) TAGS
132 find . -name '*.[ch]' | xargs etags \
133 --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/'
134
135define do_install
136 $(print_install) \
137 if [ ! -d '$(DESTDIR_SQ)$2' ]; then \
138 $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \
139 fi; \
140 $(INSTALL) $1 '$(DESTDIR_SQ)$2'
141endef
142
143install_lib: all_cmd
144 $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ))
145 $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ))
146
147install: install_lib
148
149clean:
Sasha Levinad3b5642014-05-08 13:55:13 -0400150 $(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d
Sasha Levin5634bd72013-06-13 18:41:17 -0400151 $(RM) tags TAGS
152
Sasha Levin5634bd72013-06-13 18:41:17 -0400153PHONY += force
154force:
155
156# Declare the contents of the .PHONY variable as phony. We keep that
157# information in a variable so we can use it in if_changed and friends.
158.PHONY: $(PHONY)