dracut-functions.sh: simplify some for loops
[dracut.git] / Makefile
blob98a2fbf60418ebfe39dd6c076e1dc333c76635bb
1 -include dracut-version.sh
3 VERSION = $(shell [ -d .git ] && git describe --abbrev=0 --tags 2>/dev/null || echo $(DRACUT_VERSION))
4 GITVERSION = $(shell [ -d .git ] && { v=$$(git describe --tags 2>/dev/null); [ $${v\#*-} != $$v ] && echo -$${v\#*-}; } )
6 -include Makefile.inc
8 prefix ?= /usr
9 libdir ?= ${prefix}/lib
10 datadir ?= ${prefix}/share
11 pkglibdir ?= ${libdir}/dracut
12 sysconfdir ?= ${prefix}/etc
13 bindir ?= ${prefix}/bin
14 mandir ?= ${prefix}/share/man
15 CFLAGS ?= -O2 -g -Wall
16 CFLAGS += -std=gnu99 -D_FILE_OFFSET_BITS=64 -Wformat -Werror=format-security -Wp,-D_FORTIFY_SOURCE=2
17 bashcompletiondir ?= ${datadir}/bash-completion/completions
18 pkgconfigdatadir ?= $(datadir)/pkgconfig
20 man1pages = lsinitrd.1
22 man5pages = dracut.conf.5
24 man7pages = dracut.cmdline.7 \
25 dracut.bootup.7 \
26 dracut.modules.7
28 man8pages = dracut.8 \
29 dracut-catimages.8 \
30 mkinitrd.8 \
31 mkinitrd-suse.8 \
32 modules.d/98dracut-systemd/dracut-cmdline.service.8 \
33 modules.d/98dracut-systemd/dracut-initqueue.service.8 \
34 modules.d/98dracut-systemd/dracut-mount.service.8 \
35 modules.d/98dracut-systemd/dracut-shutdown.service.8 \
36 modules.d/98dracut-systemd/dracut-pre-mount.service.8 \
37 modules.d/98dracut-systemd/dracut-pre-pivot.service.8 \
38 modules.d/98dracut-systemd/dracut-pre-trigger.service.8 \
39 modules.d/98dracut-systemd/dracut-pre-udev.service.8
41 manpages = $(man1pages) $(man5pages) $(man7pages) $(man8pages)
43 .PHONY: install clean archive rpm testimage test all check AUTHORS doc dracut-version.sh
45 all: dracut-version.sh dracut.pc dracut-install skipcpio/skipcpio
47 DRACUT_INSTALL_OBJECTS = \
48 install/dracut-install.o \
49 install/hashmap.o\
50 install/log.o \
51 install/strv.o \
52 install/util.o
54 # deps generated with gcc -MM
55 install/dracut-install.o: install/dracut-install.c install/log.h install/macro.h \
56 install/hashmap.h install/util.h
57 install/hashmap.o: install/hashmap.c install/util.h install/macro.h install/log.h \
58 install/hashmap.h
59 install/log.o: install/log.c install/log.h install/macro.h install/util.h
60 install/util.o: install/util.c install/util.h install/macro.h install/log.h
61 install/strv.o: install/strv.c install/strv.h install/util.h install/macro.h install/log.h
63 install/dracut-install: $(DRACUT_INSTALL_OBJECTS)
65 dracut-install: install/dracut-install
66 ln -fs $< $@
68 SKIPCPIO_OBJECTS= \
69 skipcpio/skipcpio.o
71 skipcpio/skipcpio.o: skipcpio/skipcpio.c
72 skipcpio/skipcpio: skipcpio/skipcpio.o
74 indent:
75 indent -i8 -nut -br -linux -l120 install/dracut-install.c
76 indent -i8 -nut -br -linux -l120 skipcpio/skipcpio.c
78 doc: $(manpages) dracut.html
80 ifneq ($(enable_documentation),no)
81 all: doc
82 endif
84 %: %.xml
85 xsltproc -o $@ -nonet http://docbook.sourceforge.net/release/xsl/current/manpages/docbook.xsl $<
87 %.xml: %.asc
88 asciidoc -d manpage -b docbook -o $@ $<
90 dracut.8: dracut.usage.asc dracut.8.asc
92 dracut.html: dracut.asc $(manpages) dracut.css dracut.usage.asc
93 asciidoc -a numbered -d book -b docbook -o dracut.xml dracut.asc
94 xsltproc -o dracut.html --xinclude -nonet \
95 --stringparam custom.css.source dracut.css \
96 --stringparam generate.css.header 1 \
97 http://docbook.sourceforge.net/release/xsl/current/xhtml/docbook.xsl dracut.xml
98 rm -f -- dracut.xml
100 dracut.pc: Makefile.inc Makefile
101 @echo "Name: dracut" > dracut.pc
102 @echo "Description: dracut" >> dracut.pc
103 @echo "Version: $(VERSION)$(GITVERSION)" >> dracut.pc
104 @echo "dracutdir=$(pkglibdir)" >> dracut.pc
105 @echo "dracutmodulesdir=$(pkglibdir)/modules.d" >> dracut.pc
106 @echo "dracutconfdir=$(pkglibdir)/dracut.conf.d" >> dracut.pc
108 install: all
109 mkdir -p $(DESTDIR)$(pkglibdir)
110 mkdir -p $(DESTDIR)$(bindir)
111 mkdir -p $(DESTDIR)$(sysconfdir)
112 mkdir -p $(DESTDIR)$(pkglibdir)/modules.d
113 mkdir -p $(DESTDIR)$(mandir)/man1 $(DESTDIR)$(mandir)/man5 $(DESTDIR)$(mandir)/man7 $(DESTDIR)$(mandir)/man8
114 install -m 0755 dracut.sh $(DESTDIR)$(bindir)/dracut
115 install -m 0755 dracut-catimages.sh $(DESTDIR)$(bindir)/dracut-catimages
116 install -m 0755 mkinitrd-dracut.sh $(DESTDIR)$(bindir)/mkinitrd
117 install -m 0755 lsinitrd.sh $(DESTDIR)$(bindir)/lsinitrd
118 install -m 0644 dracut.conf $(DESTDIR)$(sysconfdir)/dracut.conf
119 mkdir -p $(DESTDIR)$(sysconfdir)/dracut.conf.d
120 mkdir -p $(DESTDIR)$(pkglibdir)/dracut.conf.d
121 install -m 0755 dracut-init.sh $(DESTDIR)$(pkglibdir)/dracut-init.sh
122 install -m 0755 dracut-functions.sh $(DESTDIR)$(pkglibdir)/dracut-functions.sh
123 install -m 0755 dracut-version.sh $(DESTDIR)$(pkglibdir)/dracut-version.sh
124 ln -fs dracut-functions.sh $(DESTDIR)$(pkglibdir)/dracut-functions
125 install -m 0755 dracut-logger.sh $(DESTDIR)$(pkglibdir)/dracut-logger.sh
126 install -m 0755 dracut-initramfs-restore.sh $(DESTDIR)$(pkglibdir)/dracut-initramfs-restore
127 cp -arx modules.d $(DESTDIR)$(pkglibdir)
128 ifneq ($(enable_documentation),no)
129 for i in $(man1pages); do install -m 0644 $$i $(DESTDIR)$(mandir)/man1/$${i##*/}; done
130 for i in $(man5pages); do install -m 0644 $$i $(DESTDIR)$(mandir)/man5/$${i##*/}; done
131 for i in $(man7pages); do install -m 0644 $$i $(DESTDIR)$(mandir)/man7/$${i##*/}; done
132 for i in $(man8pages); do install -m 0644 $$i $(DESTDIR)$(mandir)/man8/$${i##*/}; done
133 ln -fs dracut.cmdline.7 $(DESTDIR)$(mandir)/man7/dracut.kernel.7
134 endif
135 if [ -n "$(systemdsystemunitdir)" ]; then \
136 mkdir -p $(DESTDIR)$(systemdsystemunitdir); \
137 ln -srf $(DESTDIR)$(pkglibdir)/modules.d/98dracut-systemd/dracut-shutdown.service $(DESTDIR)$(systemdsystemunitdir)/dracut-shutdown.service; \
138 mkdir -p $(DESTDIR)$(systemdsystemunitdir)/sysinit.target.wants; \
139 ln -s ../dracut-shutdown.service \
140 $(DESTDIR)$(systemdsystemunitdir)/sysinit.target.wants/dracut-shutdown.service; \
141 mkdir -p $(DESTDIR)$(systemdsystemunitdir)/initrd.target.wants; \
142 for i in \
143 dracut-cmdline.service \
144 dracut-initqueue.service \
145 dracut-mount.service \
146 dracut-pre-mount.service \
147 dracut-pre-pivot.service \
148 dracut-pre-trigger.service \
149 dracut-pre-udev.service \
150 ; do \
151 ln -srf $(DESTDIR)$(pkglibdir)/modules.d/98dracut-systemd/$$i $(DESTDIR)$(systemdsystemunitdir); \
152 ln -s ../$$i \
153 $(DESTDIR)$(systemdsystemunitdir)/initrd.target.wants/$$i; \
154 done \
156 if [ -f install/dracut-install ]; then \
157 install -m 0755 install/dracut-install $(DESTDIR)$(pkglibdir)/dracut-install; \
159 if [ -f skipcpio/skipcpio ]; then \
160 install -m 0755 skipcpio/skipcpio $(DESTDIR)$(pkglibdir)/skipcpio; \
162 mkdir -p $(DESTDIR)${prefix}/lib/kernel/install.d
163 install -m 0755 50-dracut.install $(DESTDIR)${prefix}/lib/kernel/install.d/50-dracut.install
164 install -m 0755 51-dracut-rescue.install $(DESTDIR)${prefix}/lib/kernel/install.d/51-dracut-rescue.install
165 mkdir -p $(DESTDIR)${bashcompletiondir}
166 install -m 0644 dracut-bash-completion.sh $(DESTDIR)${bashcompletiondir}/dracut
167 install -m 0644 lsinitrd-bash-completion.sh $(DESTDIR)${bashcompletiondir}/lsinitrd
168 mkdir -p $(DESTDIR)${pkgconfigdatadir}
169 install -m 0644 dracut.pc $(DESTDIR)${pkgconfigdatadir}/dracut.pc
171 dracut-version.sh:
172 @echo "DRACUT_VERSION=$(VERSION)$(GITVERSION)" > dracut-version.sh
174 clean:
175 $(RM) *~
176 $(RM) */*~
177 $(RM) */*/*~
178 $(RM) $(manpages:%=%.xml) dracut.xml
179 $(RM) test-*.img
180 $(RM) dracut-*.rpm dracut-*.tar.bz2 dracut-*.tar.xz
181 $(RM) dracut-version.sh
182 $(RM) dracut-install install/dracut-install $(DRACUT_INSTALL_OBJECTS)
183 $(RM) skipcpio/skipcpio $(SKIPCPIO_OBJECTS)
184 $(RM) $(manpages) dracut.html
185 $(MAKE) -C test clean
187 dist: dracut-$(VERSION).tar.xz
189 dracut-$(VERSION).tar.xz: doc syncheck
190 @echo "DRACUT_VERSION=$(VERSION)" > dracut-version.sh
191 git archive --format=tar $(VERSION) --prefix=dracut-$(VERSION)/ > dracut-$(VERSION).tar
192 mkdir -p dracut-$(VERSION)
193 for i in $(manpages) dracut.html dracut-version.sh; do [ "$${i%/*}" != "$$i" ] && mkdir -p "dracut-$(VERSION)/$${i%/*}"; cp "$$i" "dracut-$(VERSION)/$$i"; done
194 tar --owner=root --group=root -rf dracut-$(VERSION).tar $$(find dracut-$(VERSION) -type f)
195 rm -fr -- dracut-$(VERSION).tar.xz dracut-$(VERSION)
196 xz -9 dracut-$(VERSION).tar
197 rm -f -- dracut-$(VERSION).tar
199 rpm: dracut-$(VERSION).tar.xz syncheck
200 rpmbuild=$$(mktemp -d -t rpmbuild-dracut.XXXXXX); src=$$(pwd); \
201 cp dracut-$(VERSION).tar.xz "$$rpmbuild"; \
202 LC_MESSAGES=C $$src/git2spec.pl $(VERSION) "$$rpmbuild" < dracut.spec > $$rpmbuild/dracut.spec; \
203 (cd "$$rpmbuild"; \
204 wget https://www.gnu.org/licenses/lgpl-2.1.txt; \
205 rpmbuild --define "_topdir $$PWD" --define "_sourcedir $$PWD" \
206 --define "_specdir $$PWD" --define "_srcrpmdir $$PWD" \
207 --define "_rpmdir $$PWD" -ba dracut.spec; ) && \
208 ( mv "$$rpmbuild"/$$(arch)/*.rpm .; mv "$$rpmbuild"/*.src.rpm .;rm -fr -- "$$rpmbuild"; ls *.rpm )
210 syncheck:
211 @ret=0;for i in dracut-initramfs-restore.sh modules.d/*/*.sh; do \
212 [ "$${i##*/}" = "module-setup.sh" ] && continue; \
213 read line < "$$i"; [ "$${line#*bash*}" != "$$line" ] && continue; \
214 [ $$V ] && echo "posix syntax check: $$i"; bash --posix -n "$$i" ; ret=$$(($$ret+$$?)); \
215 [ $$V ] && echo "checking for [[: $$i"; if grep -Fq '[[ ' "$$i" ; then ret=$$(($$ret+1)); echo "$$i contains [["; fi \
216 done;exit $$ret
217 @ret=0;for i in *.sh mkinitrd-dracut.sh modules.d/*/*.sh \
218 modules.d/*/module-setup.sh; do \
219 [ $$V ] && echo "bash syntax check: $$i"; bash -n "$$i" ; ret=$$(($$ret+$$?)); \
220 done;exit $$ret
222 check: all syncheck rpm
223 @[ "$$EUID" == "0" ] || { echo "'check' must be run as root! Please use 'sudo'."; exit 1; }
224 @$(MAKE) -C test check
226 testimage: all
227 ./dracut.sh -N -l -a debug -f test-$(shell uname -r).img $(shell uname -r)
228 @echo wrote test-$(shell uname -r).img
230 debugtestimage: all
231 ./dracut.sh --debug -l -a debug -f test-$(shell uname -r).img $(shell uname -r)
232 @echo wrote test-$(shell uname -r).img
234 testimages: all
235 ./dracut.sh -l -a debug --kernel-only -f test-kernel-$(shell uname -r).img $(shell uname -r)
236 @echo wrote test-$(shell uname -r).img
237 ./dracut.sh -l -a debug --no-kernel -f test-dracut.img $(shell uname -r)
238 @echo wrote test-dracut.img
240 debughostimage: all
241 ./dracut.sh --debug -H -l -f test-$(shell uname -r).img $(shell uname -r)
242 @echo wrote test-$(shell uname -r).img
244 hostimage: all
245 ./dracut.sh -H -l -f test-$(shell uname -r).img $(shell uname -r)
246 @echo wrote test-$(shell uname -r).img
248 AUTHORS:
249 git shortlog --numbered --summary -e |while read a rest || [ -n "$$rest" ]; do echo $$rest;done > AUTHORS
251 dracut.html.sign: dracut-$(VERSION).tar.xz dracut.html
252 gpg-sign-all dracut-$(VERSION).tar.xz dracut.html
254 upload: dracut.html.sign
255 kup put dracut-$(VERSION).tar.xz dracut-$(VERSION).tar.sign /pub/linux/utils/boot/dracut/
256 kup put dracut.html dracut.html.sign /pub/linux/utils/boot/dracut/