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