]>
Commit | Line | Data |
---|---|---|
5634bd7d SL |
1 | # file format version |
2 | FILE_VERSION = 1 | |
3 | ||
0041898e | 4 | LIBLOCKDEP_VERSION=$(shell make --no-print-directory -sC ../../.. kernelversion) |
5634bd7d SL |
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 | ||
d1e40e59 | 17 | # Allow setting CC and AR and LD, or setting CROSS_COMPILE as a prefix. |
5634bd7d SL |
18 | $(call allow-override,CC,$(CROSS_COMPILE)gcc) |
19 | $(call allow-override,AR,$(CROSS_COMPILE)ar) | |
d1e40e59 | 20 | $(call allow-override,LD,$(CROSS_COMPILE)ld) |
5634bd7d SL |
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 | ||
9244e2c6 JO |
39 | MAKEFLAGS += --no-print-directory |
40 | ||
41 | include ../../scripts/Makefile.include | |
42 | ||
5634bd7d SL |
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 | ||
9244e2c6 | 52 | ifeq ($(srctree),) |
e19b7cee | 53 | srctree := $(patsubst %/,%,$(dir $(CURDIR))) |
9244e2c6 JO |
54 | srctree := $(patsubst %/,%,$(dir $(srctree))) |
55 | srctree := $(patsubst %/,%,$(dir $(srctree))) | |
56 | #$(info Determined 'srctree' to be $(srctree)) | |
5634bd7d SL |
57 | endif |
58 | ||
5634bd7d SL |
59 | # Shell quotes |
60 | libdir_SQ = $(subst ','\'',$(libdir)) | |
61 | bindir_SQ = $(subst ','\'',$(bindir)) | |
62 | ||
9244e2c6 JO |
63 | LIB_IN := $(OUTPUT)liblockdep-in.o |
64 | ||
5634bd7d | 65 | BIN_FILE = lockdep |
9244e2c6 | 66 | LIB_FILE = $(OUTPUT)liblockdep.a $(OUTPUT)liblockdep.so.$(LIBLOCKDEP_VERSION) |
5634bd7d SL |
67 | |
68 | CONFIG_INCLUDES = | |
69 | CONFIG_LIBS = | |
70 | CONFIG_FLAGS = | |
71 | ||
72 | OBJ = $@ | |
73 | N = | |
74 | ||
75 | export Q VERBOSE | |
76 | ||
8baeccdc | 77 | INCLUDES = -I. -I./uinclude -I./include -I../../include $(CONFIG_INCLUDES) |
5634bd7d SL |
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 | |
9244e2c6 | 81 | CFLAGS += -fPIC |
5634bd7d SL |
82 | |
83 | override CFLAGS += $(CONFIG_FLAGS) $(INCLUDES) $(PLUGIN_DIR_SQ) | |
84 | ||
85 | ifeq ($(VERBOSE),1) | |
86 | Q = | |
5634bd7d SL |
87 | print_shared_lib_compile = |
88 | print_install = | |
89 | else | |
90 | Q = @ | |
9244e2c6 JO |
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'; | |
5634bd7d SL |
94 | endif |
95 | ||
7c422f55 JO |
96 | all: |
97 | ||
9244e2c6 | 98 | export srctree OUTPUT CC LD CFLAGS V |
ab6201d0 | 99 | include $(srctree)/tools/build/Makefile.include |
5634bd7d SL |
100 | |
101 | do_compile_shared_library = \ | |
102 | ($(print_shared_lib_compile) \ | |
013e379a | 103 | $(CC) --shared $^ -o $@ -lpthread -ldl -Wl,-soname='"$@"';$(shell ln -sf $@ liblockdep.so)) |
5634bd7d SL |
104 | |
105 | do_build_static_lib = \ | |
106 | ($(print_static_lib_build) \ | |
107 | $(RM) $@; $(AR) rcs $@ $^) | |
108 | ||
5634bd7d SL |
109 | CMD_TARGETS = $(LIB_FILE) |
110 | ||
111 | TARGETS = $(CMD_TARGETS) | |
112 | ||
113 | ||
7c422f55 | 114 | all: fixdep all_cmd |
5634bd7d SL |
115 | |
116 | all_cmd: $(CMD_TARGETS) | |
117 | ||
9244e2c6 JO |
118 | $(LIB_IN): force |
119 | $(Q)$(MAKE) $(build)=liblockdep | |
120 | ||
121 | liblockdep.so.$(LIBLOCKDEP_VERSION): $(LIB_IN) | |
5634bd7d SL |
122 | $(Q)$(do_compile_shared_library) |
123 | ||
9244e2c6 | 124 | liblockdep.a: $(LIB_IN) |
5634bd7d SL |
125 | $(Q)$(do_build_static_lib) |
126 | ||
5634bd7d SL |
127 | tags: force |
128 | $(RM) tags | |
129 | find . -name '*.[ch]' | xargs ctags --extra=+f --c-kinds=+px \ | |
130 | --regex-c++='/_PE\(([^,)]*).*/PEVENT_ERRNO__\1/' | |
131 | ||
132 | TAGS: force | |
133 | $(RM) TAGS | |
134 | find . -name '*.[ch]' | xargs etags \ | |
135 | --regex='/_PE(\([^,)]*\).*/PEVENT_ERRNO__\1/' | |
136 | ||
137 | define do_install | |
138 | $(print_install) \ | |
139 | if [ ! -d '$(DESTDIR_SQ)$2' ]; then \ | |
140 | $(INSTALL) -d -m 755 '$(DESTDIR_SQ)$2'; \ | |
141 | fi; \ | |
142 | $(INSTALL) $1 '$(DESTDIR_SQ)$2' | |
143 | endef | |
144 | ||
145 | install_lib: all_cmd | |
146 | $(Q)$(call do_install,$(LIB_FILE),$(libdir_SQ)) | |
147 | $(Q)$(call do_install,$(BIN_FILE),$(bindir_SQ)) | |
148 | ||
149 | install: install_lib | |
150 | ||
151 | clean: | |
24ee9b57 | 152 | $(RM) *.o *~ $(TARGETS) *.a *liblockdep*.so* $(VERSION_FILES) .*.d .*.cmd |
5634bd7d SL |
153 | $(RM) tags TAGS |
154 | ||
5634bd7d SL |
155 | PHONY += force |
156 | force: | |
157 | ||
158 | # Declare the contents of the .PHONY variable as phony. We keep that | |
159 | # information in a variable so we can use it in if_changed and friends. | |
160 | .PHONY: $(PHONY) |