imsm: PPL support
[thirdparty/mdadm.git] / Makefile
1 #
2 # mdadm - manage Linux "md" devices aka RAID arrays.
3 #
4 # Copyright (C) 2001-2002 Neil Brown <neilb@cse.unsw.edu.au>
5 # Copyright (C) 2013 Neil Brown <neilb@suse.de>
6 #
7 #
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2 of the License, or
11 # (at your option) any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, write to the Free Software
20 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21 #
22 # Author: Neil Brown
23 # Email: <neilb@cse.unsw.edu.au>
24 # Paper: Neil Brown
25 # School of Computer Science and Engineering
26 # The University of New South Wales
27 # Sydney, 2052
28 # Australia
29 #
30
31 # define "CXFLAGS" to give extra flags to CC.
32 # e.g. make CXFLAGS=-O to optimise
33 TCC = tcc
34 UCLIBC_GCC = $(shell for nm in i386-uclibc-linux-gcc i386-uclibc-gcc; do which $$nm > /dev/null && { echo $$nm ; exit; } ; done; echo false No uclibc found )
35 #DIET_GCC = diet gcc
36 # sorry, but diet-libc doesn't know about posix_memalign,
37 # so we cannot use it any more.
38 DIET_GCC = gcc -DHAVE_STDINT_H
39
40 KLIBC=/home/src/klibc/klibc-0.77
41
42 KLIBC_GCC = gcc -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32
43
44 CC ?= $(CROSS_COMPILE)gcc
45 CXFLAGS ?= -ggdb
46 CWFLAGS = -Wall -Werror -Wstrict-prototypes -Wextra -Wno-unused-parameter
47 ifdef WARN_UNUSED
48 CWFLAGS += -Wp,-D_FORTIFY_SOURCE=2 -O3
49 endif
50
51 FALLTHROUGH := $(shell gcc -v --help 2>&1 | grep "implicit-fallthrough" | wc -l)
52 ifneq "$(FALLTHROUGH)" "0"
53 CWFLAGS += -Wimplicit-fallthrough=0
54 endif
55
56 ifdef DEBIAN
57 CPPFLAGS += -DDEBIAN
58 endif
59 ifdef DEFAULT_OLD_METADATA
60 CPPFLAGS += -DDEFAULT_OLD_METADATA
61 DEFAULT_METADATA=0.90
62 else
63 DEFAULT_METADATA=1.2
64 endif
65 CPPFLAGS += -DBINDIR=\"$(BINDIR)\"
66
67 PKG_CONFIG ?= pkg-config
68
69 SYSCONFDIR = /etc
70 CONFFILE = $(SYSCONFDIR)/mdadm.conf
71 CONFFILE2 = $(SYSCONFDIR)/mdadm/mdadm.conf
72 MAILCMD =/usr/sbin/sendmail -t
73 CONFFILEFLAGS = -DCONFFILE=\"$(CONFFILE)\" -DCONFFILE2=\"$(CONFFILE2)\"
74 # Both MAP_DIR and MDMON_DIR should be somewhere that persists across the
75 # pivotroot from early boot to late boot.
76 # /run is best, but for distros that don't support that.
77 # /dev can work, in which case you probably want /dev/.mdadm
78 RUN_DIR=/run/mdadm
79 CHECK_RUN_DIR=1
80 MAP_DIR=$(RUN_DIR)
81 MAP_FILE = map
82 MAP_PATH = $(MAP_DIR)/$(MAP_FILE)
83 MDMON_DIR = $(RUN_DIR)
84 # place for autoreplace cookies
85 FAILED_SLOTS_DIR = $(RUN_DIR)/failed-slots
86 SYSTEMD_DIR=/lib/systemd/system
87
88 COROSYNC:=$(shell [ -d /usr/include/corosync ] || echo -DNO_COROSYNC)
89 DLM:=$(shell [ -f /usr/include/libdlm.h ] || echo -DNO_DLM)
90
91 DIRFLAGS = -DMAP_DIR=\"$(MAP_DIR)\" -DMAP_FILE=\"$(MAP_FILE)\"
92 DIRFLAGS += -DMDMON_DIR=\"$(MDMON_DIR)\"
93 DIRFLAGS += -DFAILED_SLOTS_DIR=\"$(FAILED_SLOTS_DIR)\"
94 CFLAGS = $(CWFLAGS) $(CXFLAGS) -DSendmail=\""$(MAILCMD)"\" $(CONFFILEFLAGS) $(DIRFLAGS) $(COROSYNC) $(DLM)
95
96 VERSION = $(shell [ -d .git ] && git describe HEAD | sed 's/mdadm-//')
97 VERS_DATE = $(shell [ -d .git ] && date --iso-8601 --date="`git log -n1 --format=format:%cd --date=iso --date=short`")
98 DVERS = $(if $(VERSION),-DVERSION=\"$(VERSION)\",)
99 DDATE = $(if $(VERS_DATE),-DVERS_DATE="\"$(VERS_DATE)\"",)
100 CFLAGS += $(DVERS) $(DDATE)
101
102 # The glibc TLS ABI requires applications that call clone(2) to set up
103 # TLS data structures, use pthreads until mdmon implements this support
104 USE_PTHREADS = 1
105 ifdef USE_PTHREADS
106 CFLAGS += -DUSE_PTHREADS
107 MON_LDFLAGS += -pthread
108 endif
109
110 # If you want a static binary, you might uncomment these
111 # LDFLAGS = -static
112 # STRIP = -s
113 LDLIBS=-ldl
114
115 INSTALL = /usr/bin/install
116 DESTDIR =
117 BINDIR = /sbin
118 MANDIR = /usr/share/man
119 MAN4DIR = $(MANDIR)/man4
120 MAN5DIR = $(MANDIR)/man5
121 MAN8DIR = $(MANDIR)/man8
122
123 UDEVDIR := $(shell $(PKG_CONFIG) --variable=udevdir udev 2>/dev/null)
124 ifndef UDEVDIR
125 UDEVDIR = /lib/udev
126 endif
127
128 ifeq (,$(findstring s,$(MAKEFLAGS)))
129 ECHO=echo
130 else
131 ECHO=:
132 endif
133
134 OBJS = mdadm.o config.o policy.o mdstat.o ReadMe.o util.o maps.o lib.o \
135 Manage.o Assemble.o Build.o \
136 Create.o Detail.o Examine.o Grow.o Monitor.o dlink.o Kill.o Query.o \
137 Incremental.o Dump.o \
138 mdopen.o super0.o super1.o super-ddf.o super-intel.o bitmap.o \
139 super-mbr.o super-gpt.o \
140 restripe.o sysfs.o sha1.o mapfile.o crc32.o sg_io.o msg.o xmalloc.o \
141 platform-intel.o probe_roms.o crc32c.o
142
143 CHECK_OBJS = restripe.o sysfs.o maps.o lib.o xmalloc.o dlink.o
144
145 SRCS = $(patsubst %.o,%.c,$(OBJS))
146
147 INCL = mdadm.h part.h bitmap.h
148
149 MON_OBJS = mdmon.o monitor.o managemon.o util.o maps.o mdstat.o sysfs.o \
150 policy.o lib.o \
151 Kill.o sg_io.o dlink.o ReadMe.o super-intel.o \
152 super-mbr.o super-gpt.o \
153 super-ddf.o sha1.o crc32.o msg.o bitmap.o xmalloc.o \
154 platform-intel.o probe_roms.o crc32c.o
155
156 MON_SRCS = $(patsubst %.o,%.c,$(MON_OBJS))
157
158 STATICSRC = pwgr.c
159 STATICOBJS = pwgr.o
160
161 ASSEMBLE_SRCS := mdassemble.c Assemble.c Manage.c config.c policy.c dlink.c util.c \
162 maps.c lib.c xmalloc.c \
163 super0.c super1.c super-ddf.c super-intel.c sha1.c crc32.c sg_io.c mdstat.c \
164 platform-intel.c probe_roms.c sysfs.c super-mbr.c super-gpt.c mapfile.c \
165 crc32c.c
166 ASSEMBLE_AUTO_SRCS := mdopen.c
167 ASSEMBLE_FLAGS:= $(CFLAGS) -DMDASSEMBLE
168 ifdef MDASSEMBLE_AUTO
169 ASSEMBLE_SRCS += $(ASSEMBLE_AUTO_SRCS)
170 ASSEMBLE_FLAGS += -DMDASSEMBLE_AUTO
171 endif
172
173 all : mdadm mdmon
174 man : mdadm.man md.man mdadm.conf.man mdmon.man raid6check.man
175
176 check_rundir:
177 @if [ ! -d "$(dir $(RUN_DIR))" -a "$(CHECK_RUN_DIR)" = 1 ]; then \
178 echo "***** Parent of $(RUN_DIR) does not exist. Maybe set different RUN_DIR="; \
179 echo "***** e.g. make RUN_DIR=/dev/.mdadm" ; \
180 echo "***** or set CHECK_RUN_DIR=0"; exit 1; \
181 fi
182
183 everything: all mdadm.static swap_super test_stripe raid6check \
184 mdassemble mdassemble.auto mdassemble.static mdassemble.man \
185 mdadm.Os mdadm.O2 man
186 everything-test: all mdadm.static swap_super test_stripe \
187 mdassemble.auto mdassemble.static mdassemble.man \
188 mdadm.Os mdadm.O2 man
189 # mdadm.uclibc and mdassemble.uclibc don't work on x86-64
190 # mdadm.tcc doesn't work..
191
192 mdadm : $(OBJS) | check_rundir
193 $(CC) $(CFLAGS) $(LDFLAGS) -o mdadm $(OBJS) $(LDLIBS)
194
195 mdadm.static : $(OBJS) $(STATICOBJS)
196 $(CC) $(CFLAGS) $(LDFLAGS) -static -o mdadm.static $(OBJS) $(STATICOBJS) $(LDLIBS)
197
198 mdadm.tcc : $(SRCS) $(INCL)
199 $(TCC) -o mdadm.tcc $(SRCS)
200
201 mdadm.klibc : $(SRCS) $(INCL)
202 rm -f $(OBJS)
203 $(CC) -nostdinc -iwithprefix include -I$(KLIBC)/klibc/include -I$(KLIBC)/linux/include -I$(KLIBC)/klibc/arch/i386/include -I$(KLIBC)/klibc/include/bits32 $(CFLAGS) $(SRCS)
204
205 mdadm.Os : $(SRCS) $(INCL)
206 $(CC) -o mdadm.Os $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -DHAVE_STDINT_H -Os $(SRCS) $(LDLIBS)
207
208 mdadm.O2 : $(SRCS) $(INCL) mdmon.O2
209 $(CC) -o mdadm.O2 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(SRCS) $(LDLIBS)
210
211 mdmon.O2 : $(MON_SRCS) $(INCL) mdmon.h
212 $(CC) -o mdmon.O2 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(MON_LDFLAGS) -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(MON_SRCS) $(LDLIBS)
213
214 # use '-z now' to guarantee no dynamic linker interactions with the monitor thread
215 mdmon : $(MON_OBJS) | check_rundir
216 $(CC) $(CFLAGS) $(LDFLAGS) $(MON_LDFLAGS) -Wl,-z,now -o mdmon $(MON_OBJS) $(LDLIBS)
217 msg.o: msg.c msg.h
218
219 test_stripe : restripe.c xmalloc.o mdadm.h
220 $(CC) $(CFLAGS) $(CXFLAGS) $(LDFLAGS) -o test_stripe xmalloc.o -DMAIN restripe.c
221
222 raid6check : raid6check.o mdadm.h $(CHECK_OBJS)
223 $(CC) $(CXFLAGS) $(LDFLAGS) -o raid6check raid6check.o $(CHECK_OBJS)
224
225 mdassemble : $(ASSEMBLE_SRCS) $(INCL)
226 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) $(STATICSRC)
227
228 mdassemble.diet : $(ASSEMBLE_SRCS) $(INCL)
229 rm -f $(OBJS)
230 $(DIET_GCC) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) $(STATICSRC)
231
232 mdassemble.static : $(ASSEMBLE_SRCS) $(INCL)
233 rm -f $(OBJS)
234 $(CC) $(LDFLAGS) $(CPPFLAGS) $(ASSEMBLE_FLAGS) -static -DHAVE_STDINT_H -o mdassemble.static $(ASSEMBLE_SRCS) $(STATICSRC)
235
236 mdassemble.auto : $(ASSEMBLE_SRCS) $(INCL) $(ASSEMBLE_AUTO_SRCS)
237 rm -f mdassemble.static
238 $(MAKE) MDASSEMBLE_AUTO=1 mdassemble.static
239 mv mdassemble.static mdassemble.auto
240
241 mdassemble.uclibc : $(ASSEMBLE_SRCS) $(INCL)
242 rm -f $(OJS)
243 $(UCLIBC_GCC) $(ASSEMBLE_FLAGS) -DUCLIBC -DHAVE_STDINT_H -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) $(STATICSRC)
244
245 # This doesn't work
246 mdassemble.klibc : $(ASSEMBLE_SRCS) $(INCL)
247 rm -f $(OBJS)
248 $(KLIBC_GCC) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS)
249
250 mdadm.8 : mdadm.8.in
251 sed -e 's/{DEFAULT_METADATA}/$(DEFAULT_METADATA)/g' \
252 -e 's,{MAP_PATH},$(MAP_PATH),g' mdadm.8.in > mdadm.8
253
254 mdadm.man : mdadm.8
255 man -l mdadm.8 > mdadm.man
256
257 mdmon.man : mdmon.8
258 man -l mdmon.8 > mdmon.man
259
260 md.man : md.4
261 man -l md.4 > md.man
262
263 mdadm.conf.man : mdadm.conf.5
264 man -l mdadm.conf.5 > mdadm.conf.man
265
266 mdassemble.man : mdassemble.8
267 man -l mdassemble.8 > mdassemble.man
268
269 raid6check.man : raid6check.8
270 man -l raid6check.8 > raid6check.man
271
272 $(OBJS) : $(INCL) mdmon.h
273 $(MON_OBJS) : $(INCL) mdmon.h
274
275 sha1.o : sha1.c sha1.h md5.h
276 $(CC) $(CFLAGS) -DHAVE_STDINT_H -o sha1.o -c sha1.c
277
278 install : mdadm mdmon install-man install-udev
279 $(INSTALL) -D $(STRIP) -m 755 mdadm $(DESTDIR)$(BINDIR)/mdadm
280 $(INSTALL) -D $(STRIP) -m 755 mdmon $(DESTDIR)$(BINDIR)/mdmon
281
282 install-static : mdadm.static install-man
283 $(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(BINDIR)/mdadm
284
285 install-tcc : mdadm.tcc install-man
286 $(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(BINDIR)/mdadm
287
288 install-uclibc : mdadm.uclibc install-man
289 $(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(BINDIR)/mdadm
290
291 install-klibc : mdadm.klibc install-man
292 $(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(BINDIR)/mdadm
293
294 install-man: mdadm.8 md.4 mdadm.conf.5 mdmon.8
295 $(INSTALL) -D -m 644 mdadm.8 $(DESTDIR)$(MAN8DIR)/mdadm.8
296 $(INSTALL) -D -m 644 mdmon.8 $(DESTDIR)$(MAN8DIR)/mdmon.8
297 $(INSTALL) -D -m 644 md.4 $(DESTDIR)$(MAN4DIR)/md.4
298 $(INSTALL) -D -m 644 mdadm.conf.5 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5
299
300 install-udev: udev-md-raid-arrays.rules udev-md-raid-assembly.rules
301 @for file in 63-md-raid-arrays.rules 64-md-raid-assembly.rules ; \
302 do sed -e 's,BINDIR,$(BINDIR),g' udev-$${file#??-} > .install.tmp.1 && \
303 $(ECHO) $(INSTALL) -D -m 644 udev-$${file#??-} $(DESTDIR)$(UDEVDIR)/rules.d/$$file ; \
304 $(INSTALL) -D -m 644 .install.tmp.1 $(DESTDIR)$(UDEVDIR)/rules.d/$$file ; \
305 rm -f .install.tmp.1; \
306 done
307
308 install-systemd: systemd/mdmon@.service
309 @for file in mdmon@.service mdmonitor.service mdadm-last-resort@.timer \
310 mdadm-last-resort@.service mdadm-grow-continue@.service; \
311 do sed -e 's,BINDIR,$(BINDIR),g' systemd/$$file > .install.tmp.2 && \
312 $(ECHO) $(INSTALL) -D -m 644 systemd/$$file $(DESTDIR)$(SYSTEMD_DIR)/$$file ; \
313 $(INSTALL) -D -m 644 .install.tmp.2 $(DESTDIR)$(SYSTEMD_DIR)/$$file ; \
314 rm -f .install.tmp.2; \
315 done
316 @for file in mdadm.shutdown ; \
317 do sed -e 's,BINDIR,$(BINDIR),g' systemd/$$file > .install.tmp.3 && \
318 $(ECHO) $(INSTALL) -D -m 755 systemd/$$file $(DESTDIR)$(SYSTEMD_DIR)-shutdown/$$file ; \
319 $(INSTALL) -D -m 755 .install.tmp.3 $(DESTDIR)$(SYSTEMD_DIR)-shutdown/$$file ; \
320 rm -f .install.tmp.3; \
321 done
322 if [ -f /etc/SuSE-release -o -n "$(SUSE)" ] ;then $(INSTALL) -D -m 755 systemd/SUSE-mdadm_env.sh $(DESTDIR)$(SYSTEMD_DIR)/../scripts/mdadm_env.sh ;fi
323
324 uninstall:
325 rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(BINDIR)/mdadm
326
327 test: mdadm mdmon test_stripe swap_super raid6check
328 @echo "Please run './test' as root"
329
330 clean :
331 rm -f mdadm mdmon $(OBJS) $(MON_OBJS) $(STATICOBJS) core *.man \
332 mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt .merge_file_* \
333 mdadm.Os mdadm.O2 mdmon.O2 \
334 mdassemble mdassemble.static mdassemble.auto mdassemble.uclibc \
335 mdassemble.klibc swap_super \
336 init.cpio.gz mdadm.uclibc.static test_stripe raid6check raid6check.o mdmon \
337 mdadm.8
338
339 dist : clean
340 ./makedist
341
342 testdist : everything-test clean
343 ./makedist test
344
345 TAGS :
346 etags *.h *.c
347
348 DISTRO_MAKEFILE := $(wildcard distropkg/Makefile)
349 ifdef DISTRO_MAKEFILE
350 include $(DISTRO_MAKEFILE)
351 endif