]> git.ipfire.org Git - thirdparty/mdadm.git/blob - Makefile
tests/10ddf-geometry: new unit test
[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 ifdef DEBIAN
52 CPPFLAGS += -DDEBIAN
53 endif
54 ifdef DEFAULT_OLD_METADATA
55 CPPFLAGS += -DDEFAULT_OLD_METADATA
56 DEFAULT_METADATA=0.90
57 else
58 DEFAULT_METADATA=1.2
59 endif
60
61 PKG_CONFIG ?= pkg-config
62
63 SYSCONFDIR = /etc
64 CONFFILE = $(SYSCONFDIR)/mdadm.conf
65 CONFFILE2 = $(SYSCONFDIR)/mdadm/mdadm.conf
66 MAILCMD =/usr/sbin/sendmail -t
67 CONFFILEFLAGS = -DCONFFILE=\"$(CONFFILE)\" -DCONFFILE2=\"$(CONFFILE2)\"
68 # Both MAP_DIR and MDMON_DIR should be somewhere that persists across the
69 # pivotroot from early boot to late boot.
70 # /run is best, but for distros that don't support that, /dev can work.
71 MAP_DIR=/run/mdadm
72 MAP_FILE = map
73 MAP_PATH = $(MAP_DIR)/$(MAP_FILE)
74 MDMON_DIR = $(MAP_DIR)
75 # place for autoreplace cookies
76 FAILED_SLOTS_DIR = /run/mdadm/failed-slots
77 SYSTEMD_DIR=/lib/systemd/system
78 DIRFLAGS = -DMAP_DIR=\"$(MAP_DIR)\" -DMAP_FILE=\"$(MAP_FILE)\"
79 DIRFLAGS += -DMDMON_DIR=\"$(MDMON_DIR)\"
80 DIRFLAGS += -DFAILED_SLOTS_DIR=\"$(FAILED_SLOTS_DIR)\"
81 CFLAGS = $(CWFLAGS) $(CXFLAGS) -DSendmail=\""$(MAILCMD)"\" $(CONFFILEFLAGS) $(DIRFLAGS)
82
83 VERSION = $(shell [ -d .git ] && git describe HEAD | sed 's/mdadm-//')
84 VERS_DATE = $(shell [ -d .git ] && date --date="`git log -n1 --format=format:%cd --date=short`" '+%0dth %B %Y' | sed -e 's/1th/1st/' -e 's/2th/2nd/' -e 's/11st/11th/' -e 's/12nd/12th/')
85 DVERS = $(if $(VERSION),-DVERSION=\"$(VERSION)\",)
86 DDATE = $(if $(VERS_DATE),-DVERS_DATE="\"$(VERS_DATE)\"",)
87 CFLAGS += $(DVERS) $(DDATE)
88
89 # The glibc TLS ABI requires applications that call clone(2) to set up
90 # TLS data structures, use pthreads until mdmon implements this support
91 USE_PTHREADS = 1
92 ifdef USE_PTHREADS
93 CFLAGS += -DUSE_PTHREADS
94 MON_LDFLAGS += -pthread
95 endif
96
97 # If you want a static binary, you might uncomment these
98 # LDFLAGS = -static
99 # STRIP = -s
100
101 INSTALL = /usr/bin/install
102 DESTDIR =
103 BINDIR = /sbin
104 MANDIR = /usr/share/man
105 MAN4DIR = $(MANDIR)/man4
106 MAN5DIR = $(MANDIR)/man5
107 MAN8DIR = $(MANDIR)/man8
108
109 UDEVDIR := $(shell $(PKG_CONFIG) --variable=udevdir udev 2>/dev/null)
110 ifndef UDEVDIR
111 UDEVDIR = /lib/udev
112 endif
113
114 OBJS = mdadm.o config.o policy.o mdstat.o ReadMe.o util.o maps.o lib.o \
115 Manage.o Assemble.o Build.o \
116 Create.o Detail.o Examine.o Grow.o Monitor.o dlink.o Kill.o Query.o \
117 Incremental.o Dump.o \
118 mdopen.o super0.o super1.o super-ddf.o super-intel.o bitmap.o \
119 super-mbr.o super-gpt.o \
120 restripe.o sysfs.o sha1.o mapfile.o crc32.o sg_io.o msg.o xmalloc.o \
121 platform-intel.o probe_roms.o
122
123 CHECK_OBJS = restripe.o sysfs.o maps.o lib.o xmalloc.o dlink.o
124
125 SRCS = $(patsubst %.o,%.c,$(OBJS))
126
127 INCL = mdadm.h part.h bitmap.h
128
129 MON_OBJS = mdmon.o monitor.o managemon.o util.o maps.o mdstat.o sysfs.o \
130 policy.o lib.o \
131 Kill.o sg_io.o dlink.o ReadMe.o super0.o super1.o super-intel.o \
132 super-mbr.o super-gpt.o \
133 super-ddf.o sha1.o crc32.o msg.o bitmap.o xmalloc.o \
134 platform-intel.o probe_roms.o
135
136 MON_SRCS = $(patsubst %.o,%.c,$(MON_OBJS))
137
138 STATICSRC = pwgr.c
139 STATICOBJS = pwgr.o
140
141 ASSEMBLE_SRCS := mdassemble.c Assemble.c Manage.c config.c policy.c dlink.c util.c \
142 maps.c lib.c xmalloc.c \
143 super0.c super1.c super-ddf.c super-intel.c sha1.c crc32.c sg_io.c mdstat.c \
144 platform-intel.c probe_roms.c sysfs.c super-mbr.c super-gpt.c
145 ASSEMBLE_AUTO_SRCS := mdopen.c
146 ASSEMBLE_FLAGS:= $(CFLAGS) -DMDASSEMBLE
147 ifdef MDASSEMBLE_AUTO
148 ASSEMBLE_SRCS += $(ASSEMBLE_AUTO_SRCS)
149 ASSEMBLE_FLAGS += -DMDASSEMBLE_AUTO
150 endif
151
152 all : mdadm mdmon
153 man : mdadm.man md.man mdadm.conf.man mdmon.man raid6check.man
154
155 everything: all mdadm.static swap_super test_stripe raid6check \
156 mdassemble mdassemble.auto mdassemble.static mdassemble.man \
157 mdadm.Os mdadm.O2 man
158 everything-test: all mdadm.static swap_super test_stripe \
159 mdassemble.auto mdassemble.static mdassemble.man \
160 mdadm.Os mdadm.O2 man
161 # mdadm.uclibc and mdassemble.uclibc don't work on x86-64
162 # mdadm.tcc doesn't work..
163
164 mdadm : $(OBJS)
165 $(CC) $(CFLAGS) $(LDFLAGS) -o mdadm $(OBJS) $(LDLIBS)
166
167 mdadm.static : $(OBJS) $(STATICOBJS)
168 $(CC) $(CFLAGS) $(LDFLAGS) -static -o mdadm.static $(OBJS) $(STATICOBJS)
169
170 mdadm.tcc : $(SRCS) $(INCL)
171 $(TCC) -o mdadm.tcc $(SRCS)
172
173 mdadm.klibc : $(SRCS) $(INCL)
174 rm -f $(OBJS)
175 $(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)
176
177 mdadm.Os : $(SRCS) $(INCL)
178 $(CC) -o mdadm.Os $(CFLAGS) $(LDFLAGS) -DHAVE_STDINT_H -Os $(SRCS)
179
180 mdadm.O2 : $(SRCS) $(INCL) mdmon.O2
181 $(CC) -o mdadm.O2 $(CFLAGS) $(LDFLAGS) -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(SRCS)
182
183 mdmon.O2 : $(MON_SRCS) $(INCL) mdmon.h
184 $(CC) -o mdmon.O2 $(CFLAGS) $(LDFLAGS) $(MON_LDFLAGS) -DHAVE_STDINT_H -O2 -D_FORTIFY_SOURCE=2 $(MON_SRCS)
185
186 # use '-z now' to guarantee no dynamic linker interactions with the monitor thread
187 mdmon : $(MON_OBJS)
188 $(CC) $(CFLAGS) $(LDFLAGS) $(MON_LDFLAGS) -Wl,-z,now -o mdmon $(MON_OBJS) $(LDLIBS)
189 msg.o: msg.c msg.h
190
191 test_stripe : restripe.c xmalloc.o mdadm.h
192 $(CC) $(CXFLAGS) $(LDFLAGS) -o test_stripe xmalloc.o -DMAIN restripe.c
193
194 raid6check : raid6check.o mdadm.h $(CHECK_OBJS)
195 $(CC) $(CXFLAGS) $(LDFLAGS) -o raid6check raid6check.o $(CHECK_OBJS)
196
197 mdassemble : $(ASSEMBLE_SRCS) $(INCL)
198 $(CC) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) $(STATICSRC)
199
200 mdassemble.diet : $(ASSEMBLE_SRCS) $(INCL)
201 rm -f $(OBJS)
202 $(DIET_GCC) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS) $(STATICSRC)
203
204 mdassemble.static : $(ASSEMBLE_SRCS) $(INCL)
205 rm -f $(OBJS)
206 $(CC) $(LDFLAGS) $(ASSEMBLE_FLAGS) -static -DHAVE_STDINT_H -o mdassemble.static $(ASSEMBLE_SRCS) $(STATICSRC)
207
208 mdassemble.auto : $(ASSEMBLE_SRCS) $(INCL) $(ASSEMBLE_AUTO_SRCS)
209 rm -f mdassemble.static
210 $(MAKE) MDASSEMBLE_AUTO=1 mdassemble.static
211 mv mdassemble.static mdassemble.auto
212
213 mdassemble.uclibc : $(ASSEMBLE_SRCS) $(INCL)
214 rm -f $(OJS)
215 $(UCLIBC_GCC) $(ASSEMBLE_FLAGS) -DUCLIBC -DHAVE_STDINT_H -static -o mdassemble.uclibc $(ASSEMBLE_SRCS) $(STATICSRC)
216
217 # This doesn't work
218 mdassemble.klibc : $(ASSEMBLE_SRCS) $(INCL)
219 rm -f $(OBJS)
220 $(KLIBC_GCC) $(ASSEMBLE_FLAGS) -o mdassemble $(ASSEMBLE_SRCS)
221
222 mdadm.8 : mdadm.8.in
223 sed -e 's/{DEFAULT_METADATA}/$(DEFAULT_METADATA)/g' \
224 -e 's,{MAP_PATH},$(MAP_PATH),g' mdadm.8.in > mdadm.8
225
226 mdadm.man : mdadm.8
227 nroff -man mdadm.8 > mdadm.man
228
229 mdmon.man : mdmon.8
230 nroff -man mdmon.8 > mdmon.man
231
232 md.man : md.4
233 nroff -man md.4 > md.man
234
235 mdadm.conf.man : mdadm.conf.5
236 nroff -man mdadm.conf.5 > mdadm.conf.man
237
238 mdassemble.man : mdassemble.8
239 nroff -man mdassemble.8 > mdassemble.man
240
241 raid6check.man : raid6check.8
242 nroff -man raid6check.8 > raid6check.man
243
244 $(OBJS) : $(INCL) mdmon.h
245 $(MON_OBJS) : $(INCL) mdmon.h
246
247 sha1.o : sha1.c sha1.h md5.h
248 $(CC) $(CFLAGS) -DHAVE_STDINT_H -o sha1.o -c sha1.c
249
250 install : mdadm mdmon install-man install-udev
251 $(INSTALL) -D $(STRIP) -m 755 mdadm $(DESTDIR)$(BINDIR)/mdadm
252 $(INSTALL) -D $(STRIP) -m 755 mdmon $(DESTDIR)$(BINDIR)/mdmon
253
254 install-static : mdadm.static install-man
255 $(INSTALL) -D $(STRIP) -m 755 mdadm.static $(DESTDIR)$(BINDIR)/mdadm
256
257 install-tcc : mdadm.tcc install-man
258 $(INSTALL) -D $(STRIP) -m 755 mdadm.tcc $(DESTDIR)$(BINDIR)/mdadm
259
260 install-uclibc : mdadm.uclibc install-man
261 $(INSTALL) -D $(STRIP) -m 755 mdadm.uclibc $(DESTDIR)$(BINDIR)/mdadm
262
263 install-klibc : mdadm.klibc install-man
264 $(INSTALL) -D $(STRIP) -m 755 mdadm.klibc $(DESTDIR)$(BINDIR)/mdadm
265
266 install-man: mdadm.8 md.4 mdadm.conf.5 mdmon.8
267 $(INSTALL) -D -m 644 mdadm.8 $(DESTDIR)$(MAN8DIR)/mdadm.8
268 $(INSTALL) -D -m 644 mdmon.8 $(DESTDIR)$(MAN8DIR)/mdmon.8
269 $(INSTALL) -D -m 644 md.4 $(DESTDIR)$(MAN4DIR)/md.4
270 $(INSTALL) -D -m 644 mdadm.conf.5 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5
271
272 install-udev: udev-md-raid-arrays.rules udev-md-raid-assembly.rules
273 $(INSTALL) -D -m 644 udev-md-raid-arrays.rules $(DESTDIR)$(UDEVDIR)/rules.d/63-md-raid-arrays.rules
274 $(INSTALL) -D -m 644 udev-md-raid-assembly.rules $(DESTDIR)$(UDEVDIR)/rules.d/64-md-raid-assembly.rules
275
276 install-systemd: systemd/mdmon@.service
277 $(INSTALL) -D -m 644 systemd/mdmon@.service $(DESTDIR)$(SYSTEMD_DIR)/mdmon@.service
278
279 uninstall:
280 rm -f $(DESTDIR)$(MAN8DIR)/mdadm.8 $(DESTDIR)$(MAN8DIR)/mdmon.8 $(DESTDIR)$(MAN4DIR)/md.4 $(DESTDIR)$(MAN5DIR)/mdadm.conf.5 $(DESTDIR)$(BINDIR)/mdadm
281
282 test: mdadm mdmon test_stripe swap_super raid6check
283 @echo "Please run './test' as root"
284
285 clean :
286 rm -f mdadm mdmon $(OBJS) $(MON_OBJS) $(STATICOBJS) core *.man \
287 mdadm.tcc mdadm.uclibc mdadm.static *.orig *.porig *.rej *.alt .merge_file_* \
288 mdadm.Os mdadm.O2 mdmon.O2 \
289 mdassemble mdassemble.static mdassemble.auto mdassemble.uclibc \
290 mdassemble.klibc swap_super \
291 init.cpio.gz mdadm.uclibc.static test_stripe raid6check raid6check.o mdmon \
292 mdadm.8
293
294 dist : clean
295 ./makedist
296
297 testdist : everything-test clean
298 ./makedist test
299
300 TAGS :
301 etags *.h *.c
302
303 DISTRO_MAKEFILE := $(wildcard distropkg/Makefile)
304 ifdef DISTRO_MAKEFILE
305 include $(DISTRO_MAKEFILE)
306 endif