Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 1 | # file format version |
| 2 | FILE_VERSION = 1 |
| 3 | |
S. Lockwood-Childs | 0041898e | 2014-05-08 13:34:01 -0400 | [diff] [blame] | 4 | LIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 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. |
| 11 | define allow-override |
| 12 | $(if $(or $(findstring environment,$(origin $(1))),\ |
| 13 | $(findstring command line,$(origin $(1)))),,\ |
| 14 | $(eval $(1) = $(2))) |
| 15 | endef |
| 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 | |
| 21 | INSTALL = 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. |
| 27 | DESTDIR ?= |
| 28 | DESTDIR_SQ = '$(subst ','\'',$(DESTDIR))' |
| 29 | |
| 30 | prefix ?= /usr/local |
| 31 | libdir_relative = lib |
| 32 | libdir = $(prefix)/$(libdir_relative) |
| 33 | bindir_relative = bin |
| 34 | bindir = $(prefix)/$(bindir_relative) |
| 35 | |
| 36 | export DESTDIR DESTDIR_SQ INSTALL |
| 37 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 38 | MAKEFLAGS += --no-print-directory |
| 39 | |
| 40 | include ../../scripts/Makefile.include |
| 41 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 42 | # copy a bit from Linux kbuild |
| 43 | |
| 44 | ifeq ("$(origin V)", "command line") |
| 45 | VERBOSE = $(V) |
| 46 | endif |
| 47 | ifndef VERBOSE |
| 48 | VERBOSE = 0 |
| 49 | endif |
| 50 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 51 | ifeq ($(srctree),) |
| 52 | srctree := $(patsubst %/,%,$(dir $(shell pwd))) |
| 53 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 54 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
| 55 | #$(info Determined 'srctree' to be $(srctree)) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 56 | endif |
| 57 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 58 | # Shell quotes |
| 59 | libdir_SQ = $(subst ','\'',$(libdir)) |
| 60 | bindir_SQ = $(subst ','\'',$(bindir)) |
| 61 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 62 | LIB_IN := $(OUTPUT)liblockdep-in.o |
| 63 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 64 | BIN_FILE = lockdep |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 65 | LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 66 | |
| 67 | CONFIG_INCLUDES = |
| 68 | CONFIG_LIBS = |
| 69 | CONFIG_FLAGS = |
| 70 | |
| 71 | OBJ = $@ |
| 72 | N = |
| 73 | |
| 74 | export Q VERBOSE |
| 75 | |
Baruch Siach | 8baeccd | 2015-01-25 15:30:23 +0200 | [diff] [blame] | 76 | INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 77 | |
| 78 | # Set compile option CFLAGS if not set elsewhere |
| 79 | 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] | 80 | CFLAGS += -fPIC |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 81 | |
| 82 | override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) |
| 83 | |
| 84 | ifeq ($(VERBOSE),1) |
| 85 | Q = |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 86 | print_shared_lib_compile = |
| 87 | print_install = |
| 88 | else |
| 89 | Q = @ |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 90 | 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 Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 93 | endif |
| 94 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 95 | export srctree OUTPUT CC LD CFLAGS V |
| 96 | build := -f $(srctree)/tools/build/Makefile.build dir=. obj |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 97 | |
| 98 | do_compile_shared_library = \ |
| 99 | ($(print_shared_lib_compile) \ |
Sasha Levin | be227b4 | 2014-04-01 11:42:18 -0400 | [diff] [blame] | 100 | $(CC) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='"$@"';$(shell ln -s $@ liblockdep.so)) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 101 | |
| 102 | do_build_static_lib = \ |
| 103 | ($(print_static_lib_build) \ |
| 104 | $(RM) $@; $(AR) rcs $@ $^) |
| 105 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 106 | CMD_TARGETS = $(LIB_FILE) |
| 107 | |
| 108 | TARGETS = $(CMD_TARGETS) |
| 109 | |
| 110 | |
| 111 | all: all_cmd |
| 112 | |
| 113 | all_cmd: $(CMD_TARGETS) |
| 114 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 115 | $(LIB_IN): force |
| 116 | $(Q)$(MAKE) $(build)=liblockdep |
| 117 | |
| 118 | liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 119 | $(Q)$(do_compile_shared_library) |
| 120 | |
Jiri Olsa | 9244e2c | 2015-01-09 17:11:04 +0100 | [diff] [blame] | 121 | liblockdep.a: $(LIB_IN) |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 122 | $(Q)$(do_build_static_lib) |
| 123 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 124 | tags: force |
| 125 | $(RM) tags |
| 126 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ |
| 127 | --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' |
| 128 | |
| 129 | TAGS: force |
| 130 | $(RM) TAGS |
| 131 | find . -name '*.[ch]' | xargs etags \ |
| 132 | --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' |
| 133 | |
| 134 | define 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' |
| 140 | endef |
| 141 | |
| 142 | install_lib: all_cmd |
| 143 | $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ)) |
| 144 | $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ)) |
| 145 | |
| 146 | install: install_lib |
| 147 | |
| 148 | clean: |
Sasha Levin | ad3b564 | 2014-05-08 13:55:13 -0400 | [diff] [blame] | 149 | $(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 150 | $(RM) tags TAGS |
| 151 | |
Sasha Levin | 5634bd7 | 2013-06-13 18:41:17 -0400 | [diff] [blame] | 152 | PHONY += force |
| 153 | force: |
| 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) |