d1a6ac46eea0c038e8efd3382bec761447fff9c8
[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
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 ASSEMBLE_AUTO_SRCS := mdopen.c
166 ASSEMBLE_FLAGS:= $(CFLAGS) -DMDASSEMBLE
167 ifdef MDASSEMBLE_AUTO
168 ASSEMBLE_SRCS += $(ASSEMBLE_AUTO_SRCS)
169 ASSEMBLE_FLAGS += -DMDASSEMBLE_AUTO
170 endif
171
172 all : mdadm mdmon
173 man : mdadm.man md.man mdadm.conf.man mdmon.man raid6check.man
174
175 check_rundir:
176 @if [ ! -d "$(dir $(RUN_DIR))" -a "$(CHECK_RUN_DIR)" = 1 ]; then \
177 echo "***** Parent of $(RUN_DIR) does not exist. Maybe set different RUN_DIR="; \
178 echo "***** e.g. make RUN_DIR=/dev/.mdadm" ; \
179 echo "***** or set CHECK_RUN_DIR=0"; exit 1; \
180 fi
181
182 everything: all mdadm.static swap_super test_stripe raid6check \
183 mdassemble mdassemble.auto mdassemble.static mdassemble.man \
184 mdadm.Os mdadm.O2 man
185 everything-test: all mdadm.static swap_super test_stripe \
186 mdassemble.auto mdassemble.static mdassemble.man \
187 mdadm.Os mdadm.O2 man
188 # mdadm.uclibc and mdassemble.uclibc don't work on x86-64
189 # mdadm.tcc doesn't work..
190
191 mdadm : $(OBJS) | check_rundir
192 $(CC) $(CFLAGS) $(LDFLAGS) -o mdadm $(OBJS) $(LDLIBS)
193
194 mdadm.static : $(OBJS) $(STATICOBJS)
195 $(CC) $(CFLAGS) $(LDFLAGS) -static -o mdadm.static $(OBJS) $(STATICOBJS) $(LDLIBS)
196
197 mdadm.tcc : $(SRCS) $(INCL)
198 $(TCC) -o mdadm.tcc $(SRCS)
199
200 mdadm.klibc : $(SRCS) $(INCL)
201 rm -f $(OBJS)
202 $(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)
203
204 mdadm.Os : $(SRCS) $(INCL)
205 $(CC) -o mdadm.Os $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -DHAVE_STDINT_H -Os $(SRCS) $(LDLIBS)
206
207 mdadm.O2 : $(SRCS) $(INCL) mdmon.O2
208 $(CC) -o mdadm.O2 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(SRCS) $(LDLIBS)
209
210 mdmon.O2 : $(MON_SRCS) $(INCL) mdmon.h
211 $(CC) -o mdmon.O2 $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(MON_LDFLAGS) -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(MON_SRCS) $(LDLIBS)
212
213 # use '-z now' to guarantee no dynamic linker interactions with the monitor thread
214 mdmon : $(MON_OBJS) | check_rundir
215 $(CC) $(CFLAGS) $(LDFLAGS) $(MON_LDFLAGS) -Wl,-z,now -o mdmon $(MON_OBJS) $(LDLIBS)
216 msg.o: msg.c msg.h
217
218 test_stripe : restripe.c xmalloc.o mdadm.h
219 $(CC) $(CFLAGS) $(CXFLAGS) $(LDFLAGS) -o test_stripe xmalloc.o -DMAIN restripe.c
220
221 raid6check : raid6check.o mdadm.h $(CHECK_OBJS)
222 $(CC) $(CXFLAGS) $(LDFLAGS) -o raid6check raid6check.o $(CHECK_OBJS)
223
224 mdassemble : $(ASSEMBLE_SRCS) $(INCL)
225 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) $(STATICSRC)
226
227 mdassemble.diet : $(ASSEMBLE_SRCS) $(INCL)
228 rm -f $(OBJS)
229 $(DIET_GCC) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) $(STATICSRC)
230
231 mdassemble.static : $(ASSEMBLE_SRCS) $(INCL)
232 rm -f $(OBJS)
233 $(CC) $(LDFLAGS) $(CPPFLAGS) $(ASSEMBLE_FLAGS) -static -DHAVE_STDINT_H -o mdassemble.static $(ASSEMBLE_SRCS) $(STATICSRC)
234
235 mdassemble.auto : $(ASSEMBLE_SRCS) $(INCL) $(ASSEMBLE_AUTO_SRCS)
236 rm -f mdassemble.static
237 $(MAKE) MDASSEMBLE_AUTO=1 mdassemble.static
238 mv mdassemble.static mdassemble.auto
239
240 mdassemble.uclibc : $(ASSEMBLE_SRCS) $(INCL)
241 rm -f $(OJS)
242 $(UCLIBC_GCC) $(ASSEMBLE_FLAGS) -DUCLIBC -DHAVE_STDINT_H -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) $(STATICSRC)
243
244 # This doesn't work
245 mdassemble.klibc : $(ASSEMBLE_SRCS) $(INCL)
246 rm -f $(OBJS)
247 $(KLIBC_GCC) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS)
248
249 mdadm.8 : mdadm.8.in
250 sed -e 's/{DEFAULT_METADATA}/$(DEFAULT_METADATA)/g' \
251 -e 's,{MAP_PATH},$(MAP_PATH),g' mdadm.8.in > mdadm.8
252
253 mdadm.man : mdadm.8
254 man -l mdadm.8 > mdadm.man
255
256 mdmon.man : mdmon.8
257 man -l mdmon.8 > mdmon.man
258
259 md.man : md.4
260 man -l md.4 > md.man
261
262 mdadm.conf.man : mdadm.conf.5
263 man -l mdadm.conf.5 > mdadm.conf.man
264
265 mdassemble.man : mdassemble.8
266 man -l mdassemble.8 > mdassemble.man
267
268 raid6check.man : raid6check.8
269 man -l raid6check.8 > raid6check.man
270
271 $(OBJS) : $(INCL) mdmon.h
272 $(MON_OBJS) : $(INCL) mdmon.h
273
274 sha1.o : sha1.c sha1.h md5.h
275 $(CC) $(CFLAGS) -DHAVE_STDINT_H -o sha1.o -c sha1.c
276
277 install : mdadm mdmon install-man install-udev
278 $(INSTALL) -D $(STRIP) -m 755 mdadm $(DESTDIR)$(BINDIR)/mdadm
279 $(INSTALL) -D $(STRIP) -m 755 mdmon $(DESTDIR)$(BINDIR)/mdmon
280
281 install-static : mdadm.static install-man
282 $(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(BINDIR)/mdadm
283
284 install-tcc : mdadm.tcc install-man
285 $(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(BINDIR)/mdadm
286
287 install-uclibc : mdadm.uclibc install-man
288 $(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(BINDIR)/mdadm
289
290 install-klibc : mdadm.klibc install-man
291 $(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(BINDIR)/mdadm
292
293 install-man: mdadm.8 md.4 mdadm.conf.5 mdmon.8
294 $(INSTALL) -D -m 644 mdadm.8 $(DESTDIR)$(MAN8DIR)/mdadm.8
295 $(INSTALL) -D -m 644 mdmon.8 $(DESTDIR)$(MAN8DIR)/mdmon.8
296 $(INSTALL) -D -m 644 md.4 $(DESTDIR)$(MAN4DIR)/md.4
297 $(INSTALL) -D -m 644 mdadm.conf.5 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5
298
299 install-udev: udev-md-raid-arrays.rules udev-md-raid-assembly.rules
300 @for file in 63-md-raid-arrays.rules 64-md-raid-assembly.rules ; \
301 do sed -e 's,BINDIR,$(BINDIR),g' udev-$${file#??-} > .install.tmp.1 && \
302 $(ECHO) $(INSTALL) -D -m 644 udev-$${file#??-} $(DESTDIR)$(UDEVDIR)/rules.d/$$file ; \
303 $(INSTALL) -D -m 644 .install.tmp.1 $(DESTDIR)$(UDEVDIR)/rules.d/$$file ; \
304 rm -f .install.tmp.1; \
305 done
306
307 install-systemd: systemd/mdmon@.service
308 @for file in mdmon@.service mdmonitor.service mdadm-last-resort@.timer \
309 mdadm-last-resort@.service mdadm-grow-continue@.service; \
310 do sed -e 's,BINDIR,$(BINDIR),g' systemd/$$file > .install.tmp.2 && \
311 $(ECHO) $(INSTALL) -D -m 644 systemd/$$file $(DESTDIR)$(SYSTEMD_DIR)/$$file ; \
312 $(INSTALL) -D -m 644 .install.tmp.2 $(DESTDIR)$(SYSTEMD_DIR)/$$file ; \
313 rm -f .install.tmp.2; \
314 done
315 @for file in mdadm.shutdown ; \
316 do sed -e 's,BINDIR,$(BINDIR),g' systemd/$$file > .install.tmp.3 && \
317 $(ECHO) $(INSTALL) -D -m 755 systemd/$$file $(DESTDIR)$(SYSTEMD_DIR)-shutdown/$$file ; \
318 $(INSTALL) -D -m 755 .install.tmp.3 $(DESTDIR)$(SYSTEMD_DIR)-shutdown/$$file ; \
319 rm -f .install.tmp.3; \
320 done
321 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
322
323 uninstall:
324 rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(BINDIR)/mdadm
325
326 test: mdadm mdmon test_stripe swap_super raid6check
327 @echo "Please run './test' as root"
328
329 clean :
330 rm -f mdadm mdmon $(OBJS) $(MON_OBJS) $(STATICOBJS) core *.man \
331 mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt .merge_file_* \
332 mdadm.Os mdadm.O2 mdmon.O2 \
333 mdassemble mdassemble.static mdassemble.auto mdassemble.uclibc \
334 mdassemble.klibc swap_super \
335 init.cpio.gz mdadm.uclibc.static test_stripe raid6check raid6check.o mdmon \
336 mdadm.8
337
338 dist : clean
339 ./makedist
340
341 testdist : everything-test clean
342 ./makedist test
343
344 TAGS :
345 etags *.h *.c
346
347 DISTRO_MAKEFILE := $(wildcard distropkg/Makefile)
348 ifdef DISTRO_MAKEFILE
349 include $(DISTRO_MAKEFILE)
350 endif