Greg Kroah-Hartman | b244131 | 2017-11-01 15:07:57 +0100 | [diff] [blame] | 1 | # SPDX-License-Identifier: GPL-2.0 |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 2 | # file format version |
| 3 | FILE_VERSION = 1 |
| 4 | |
S. Lockwood-Childs | 0041898e | 2014-05-08 13:34:01 -0400 | [diff] [blame] | 5 | LIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 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. |
| 12 | define allow-override |
| 13 | $(if $(or $(findstring environment,$(origin $(1))),\ |
| 14 | $(findstring command line,$(origin $(1)))),,\ |
| 15 | $(eval $(1) = $(2))) |
| 16 | endef |
| 17 | |
Eunbong Song | d1e40e5 | 2015-04-24 04:36:27 +0000 | [diff] [blame] | 18 | # Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix. |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 19 | $(call allow-override,CC,$(CROSS_COMPILE)gcc) |
| 20 | $(call allow-override,AR,$(CROSS_COMPILE)ar) |
Eunbong Song | d1e40e5 | 2015-04-24 04:36:27 +0000 | [diff] [blame] | 21 | $(call allow-override,LD,$(CROSS_COMPILE)ld) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 22 | |
| 23 | INSTALL = 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. |
| 29 | DESTDIR ?= |
| 30 | DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' |
| 31 | |
| 32 | prefix ?= /usr/local |
| 33 | libdir_relative = lib |
| 34 | libdir = $(prefix)/$(libdir_relative) |
| 35 | bindir_relative = bin |
| 36 | bindir = $(prefix)/$(bindir_relative) |
| 37 | |
| 38 | export DESTDIR DESTDIR_SQ INSTALL |
| 39 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 40 | MAKEFLAGS += --no-print-directory |
| 41 | |
| 42 | include ../../scripts/Makefile.include |
| 43 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 44 | # copy a bit from Linux kbuild |
| 45 | |
| 46 | ifeq ("$(origin V)", "command line") |
| 47 | VERBOSE = $(V) |
| 48 | endif |
| 49 | ifndef VERBOSE |
| 50 | VERBOSE = 0 |
| 51 | endif |
| 52 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 53 | ifeq ($(srctree),) |
Uwe Kleine-König | e19b7ce | 2016-11-22 09:30:26 +0100 | [diff] [blame] | 54 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 55 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 56 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 57 | #$(info Determined 'srctree' to be $(srctree)) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 58 | endif |
| 59 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 60 | # Shell quotes |
| 61 | libdir_SQ = $(subst ','\'',$(libdir)) |
| 62 | bindir_SQ = $(subst ','\'',$(bindir)) |
| 63 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 64 | LIB_IN := $(OUTPUT)liblockdep-in.o |
| 65 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 66 | BIN_FILE = lockdep |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 67 | LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 68 | |
| 69 | CONFIG_INCLUDES = |
| 70 | CONFIG_LIBS = |
| 71 | CONFIG_FLAGS = |
| 72 | |
| 73 | OBJ = $@ |
| 74 | N = |
| 75 | |
| 76 | export Q VERBOSE |
| 77 | |
Baruch Siach | 8baeccd | 2015-01-25 15:30:23 +0200 | [diff] [blame] | 78 | INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 79 | |
| 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 |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 82 | CFLAGS += -fPIC |
Ben Hutchings | db8f779 | 2017-05-25 12:58:36 +0000 | [diff] [blame] | 83 | CFLAGS += -Wall |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 84 | |
| 85 | override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) |
| 86 | |
| 87 | ifeq ($(VERBOSE),1) |
| 88 | Q = |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 89 | print_shared_lib_compile = |
| 90 | print_install = |
| 91 | else |
| 92 | Q = @ |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 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'; |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 96 | endif |
| 97 | |
Jiri Olsa | 7c422f5 | 2015-09-23 12:34:02 +0200 | [diff] [blame] | 98 | all: |
| 99 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 100 | export srctree OUTPUT CC LD CFLAGS V |
Jiri Olsa | ab6201d | 2015-09-23 12:33:56 +0200 | [diff] [blame] | 101 | include $(srctree)/tools/build/Makefile.include |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 102 | |
| 103 | do_compile_shared_library = \ |
| 104 | ($(print_shared_lib_compile) \ |
Ben Hutchings | d8633a3 | 2017-05-25 12:58:51 +0000 | [diff] [blame] | 105 | $(CC) $(LDFLAGS) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='$(@F)';$(shell ln -sf $(@F) $(@D)/liblockdep.so)) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 106 | |
| 107 | do_build_static_lib = \ |
| 108 | ($(print_static_lib_build) \ |
| 109 | $(RM) $@; $(AR) rcs $@ $^) |
| 110 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 111 | CMD_TARGETS = $(LIB_FILE) |
| 112 | |
| 113 | TARGETS = $(CMD_TARGETS) |
| 114 | |
| 115 | |
Jiri Olsa | 7c422f5 | 2015-09-23 12:34:02 +0200 | [diff] [blame] | 116 | all: fixdep all_cmd |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 117 | |
| 118 | all_cmd: $(CMD_TARGETS) |
| 119 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 120 | $(LIB_IN): force |
| 121 | $(Q)$(MAKE) $(build)=liblockdep |
| 122 | |
Ben Hutchings | ea59f30 | 2017-05-25 12:58:48 +0000 | [diff] [blame] | 123 | $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 124 | $(Q)$(do_compile_shared_library) |
| 125 | |
Ben Hutchings | ea59f30 | 2017-05-25 12:58:48 +0000 | [diff] [blame] | 126 | $(OUTPUT)liblockdep.a: $(LIB_IN) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 127 | $(Q)$(do_build_static_lib) |
| 128 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 129 | tags: force |
| 130 | $(RM) tags |
| 131 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 132 | --regex-c++='/_PE\(([^,)]*).*/TEP_ERRNO__\1/' |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 133 | |
| 134 | TAGS: force |
| 135 | $(RM) TAGS |
| 136 | find . -name '*.[ch]' | xargs etags \ |
Tzvetomir Stoyanov (VMware) | d97f4ef | 2018-08-08 14:02:58 -0400 | [diff] [blame] | 137 | --regex='/_PE(\([^,)]*\).*/TEP_ERRNO__\1/' |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 138 | |
| 139 | define 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' |
| 145 | endef |
| 146 | |
| 147 | install_lib: all_cmd |
| 148 | $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ)) |
| 149 | $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ)) |
| 150 | |
| 151 | install: install_lib |
| 152 | |
| 153 | clean: |
Ben Hutchings | ea59f30 | 2017-05-25 12:58:48 +0000 | [diff] [blame] | 154 | $(RM) $(OUTPUT)*.o *~ $(TARGETS) $(OUTPUT)*.a $(OUTPUT)*liblockdep*.so* $(VERSION_FILES) $(OUTPUT).*.d $(OUTPUT).*.cmd |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 155 | $(RM) tags TAGS |
| 156 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 157 | PHONY += force |
| 158 | force: |
| 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) |