at v4.1-rc2 157 lines 4.0 kB view raw
1# file format version 2FILE_VERSION = 1 3 4LIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion) 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. 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 38MAKEFLAGS += --no-print-directory 39 40include ../../scripts/Makefile.include 41 42# copy a bit from Linux kbuild 43 44ifeq ("$(origin V)", "command line") 45 VERBOSE = $(V) 46endif 47ifndef VERBOSE 48 VERBOSE = 0 49endif 50 51ifeq ($(srctree),) 52srctree := $(patsubst %/,%,$(dir $(shell pwd))) 53srctree := $(patsubst %/,%,$(dir $(srctree))) 54srctree := $(patsubst %/,%,$(dir $(srctree))) 55#$(info Determined 'srctree' to be $(srctree)) 56endif 57 58# Shell quotes 59libdir_SQ = $(subst ','\'',$(libdir)) 60bindir_SQ = $(subst ','\'',$(bindir)) 61 62LIB_IN := $(OUTPUT)liblockdep-in.o 63 64BIN_FILE = lockdep 65LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION) 66 67CONFIG_INCLUDES = 68CONFIG_LIBS = 69CONFIG_FLAGS = 70 71OBJ = $@ 72N = 73 74export Q VERBOSE 75 76INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES) 77 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 80CFLAGS += -fPIC 81 82override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) 83 84ifeq ($(VERBOSE),1) 85 Q = 86 print_shared_lib_compile = 87 print_install = 88else 89 Q = @ 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'; 93endif 94 95export srctree OUTPUT CC LD CFLAGS V 96build := -f $(srctree)/tools/build/Makefile.build dir=. obj 97 98do_compile_shared_library = \ 99 ($(print_shared_lib_compile) \ 100 $(CC) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='"$@"';$(shell ln -s $@ liblockdep.so)) 101 102do_build_static_lib = \ 103 ($(print_static_lib_build) \ 104 $(RM) $@; $(AR) rcs $@ $^) 105 106CMD_TARGETS = $(LIB_FILE) 107 108TARGETS = $(CMD_TARGETS) 109 110 111all: all_cmd 112 113all_cmd: $(CMD_TARGETS) 114 115$(LIB_IN): force 116 $(Q)$(MAKE) $(build)=liblockdep 117 118liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN) 119 $(Q)$(do_compile_shared_library) 120 121liblockdep.a: $(LIB_IN) 122 $(Q)$(do_build_static_lib) 123 124tags: 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: 149 $(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d 150 $(RM) tags TAGS 151 152PHONY += 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)