3 # Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
4 # Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 of the License.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 # set this to make use of syslog
25 # compile-in development debug messages
26 # (export UDEV_LOG="debug" or set udev_log="debug" in udev.conf
27 # to print the debug messages to syslog)
30 # compile with gcc's code coverage option
33 # include Security-Enhanced Linux support
36 # comile with klibc instead of glibc
39 # set this to create statically linked binaries
42 # to build any of the extras programs pass:
43 # make EXTRAS="extras/<extra1> extras/<extra2>"
46 # make the build silent
98 etcdir = ${prefix}/etc
99 sbindir = ${prefix}/sbin
100 usrbindir = ${prefix}/usr/bin
101 usrsbindir = ${prefix}/usr/sbin
102 libudevdir = ${prefix}/lib/udev
103 mandir = ${prefix}/usr/share/man
104 configdir = ${etcdir}/udev
108 INSTALL = /usr/bin/install -c
109 INSTALL_PROGRAM = ${INSTALL}
110 INSTALL_DATA = ${INSTALL} -m 644
111 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
115 CC = $(CROSS_COMPILE)gcc
116 LD = $(CROSS_COMPILE)gcc
117 AR = $(CROSS_COMPILE)ar
118 RANLIB = $(CROSS_COMPILE)ranlib
121 CFLAGS = -g -Wall -pipe -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
122 WARNINGS = -Wstrict-prototypes -Wsign-compare -Wshadow \
123 -Wchar-subscripts -Wmissing-declarations -Wnested-externs \
124 -Wpointer-arith -Wcast-align -Wsign-compare -Wmissing-prototypes
125 CFLAGS += $(WARNINGS)
127 LDFLAGS = -Wl,-warn-common
130 CFLAGS += $(OPTFLAGS)
132 ifeq ($(strip $(USE_LOG)),true)
136 # if DEBUG is enabled, then we do not strip
137 ifeq ($(strip $(DEBUG)),true)
141 ifeq ($(strip $(USE_GCOV)),true)
142 CFLAGS += -fprofile-arcs -ftest-coverage
143 LDFLAGS += -fprofile-arcs
146 ifeq ($(strip $(USE_KLIBC)),true)
147 KLCC = /usr/bin/$(CROSS_COMPILE)klcc
152 ifeq ($(strip $(USE_SELINUX)),true)
153 UDEV_OBJS += udev_selinux.o
154 LIB_OBJS += -lselinux -lsepol
155 CFLAGS += -DUSE_SELINUX
158 ifeq ($(strip $(USE_STATIC)),true)
159 CFLAGS += -DUSE_STATIC
163 ifeq ($(strip $(V)),)
172 all: $(PROGRAMS) $(MAN_PAGES)
173 $(Q) extras="$(EXTRAS)"; for target in $$extras; do \
177 LDFLAGS="$(LDFLAGS)" \
178 LIB_OBJS="$(LIB_OBJS)" \
179 LIBUDEV="$(PWD)/$(LIBUDEV)" \
180 -C $$target $@ || exit 1; \
185 # clear implicit rules
189 %.o: %.c $(HEADERS) $(GEN_HEADERS)
191 $(Q) $(CC) -c $(CFLAGS) $< -o $@
193 # "Static Pattern Rule" to build all programs
194 $(PROGRAMS): %: $(HEADERS) $(GEN_HEADERS) $(LIBUDEV) %.o
196 $(Q) $(LD) $(LDFLAGS) $@.o -o $@ $(LIBUDEV) $(LIB_OBJS)
198 $(LIBUDEV): $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
201 $(Q) $(AR) cq $@ $(UDEV_OBJS)
207 $(Q) echo "/* Generated by make. */" > $@
208 $(Q) echo \#define UDEV_VERSION \"$(VERSION)\" >> $@
209 $(Q) echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
210 $(Q) echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
211 $(Q) echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
221 $(Q) - find . -type f -name '*.orig' -print0 | xargs -0r rm -f
222 $(Q) - find . -type f -name '*.rej' -print0 | xargs -0r rm -f
223 $(Q) - find . -type f -name '*~' -print0 | xargs -0r rm -f
224 $(Q) - find . -type f -name '*.[oas]' -print0 | xargs -0r rm -f
225 $(Q) - find . -type f -name "*.gcno" -print0 | xargs -0r rm -f
226 $(Q) - find . -type f -name "*.gcda" -print0 | xargs -0r rm -f
227 $(Q) - find . -type f -name "*.gcov" -print0 | xargs -0r rm -f
228 $(Q) - rm -f udev_gcov.txt
229 $(Q) - rm -f core $(PROGRAMS) $(GEN_HEADERS)
230 $(Q) - rm -f udev-$(VERSION).tar.gz
231 $(Q) - rm -f udev-$(VERSION).tar.bz2
232 @ extras="$(EXTRAS)"; for target in $$extras; do \
233 $(MAKE) -C $$target $@ || exit 1; \
238 git-tar-tree HEAD udev-$(VERSION) | gzip -9v > udev-$(VERSION).tar.gz
239 git-tar-tree HEAD udev-$(VERSION) | bzip2 -9v > udev-$(VERSION).tar.bz2
243 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
244 @ if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
245 $(INSTALL_DATA) etc/udev/udev.conf $(DESTDIR)$(configdir); \
247 @ if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
249 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
252 @ extras="$(EXTRAS)"; for target in $$extras; do \
253 $(MAKE) -C $$target $@ || exit 1; \
255 .PHONY: install-config
258 $(INSTALL_DATA) -D udev.7 $(DESTDIR)$(mandir)/man7/udev.7
259 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
260 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
261 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
262 $(INSTALL_DATA) -D udevtrigger.8 $(DESTDIR)$(mandir)/man8/udevtrigger.8
263 $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
264 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
265 @extras="$(EXTRAS)"; for target in $$extras; do \
266 $(MAKE) -C $$target $@ || exit 1; \
271 - rm -f $(DESTDIR)$(mandir)/man7/udev.7
272 - rm -f $(DESTDIR)$(mandir)/man8/udevinfo.8
273 - rm -f $(DESTDIR)$(mandir)/man8/udevtest.8
274 - rm -f $(DESTDIR)$(mandir)/man8/udevd.8
275 - rm -f $(DESTDIR)$(mandir)/man8/udevtrigger.8
276 - rm -f $(DESTDIR)$(mandir)/man8/udevmonitor.8
277 - rm -f $(DESTDIR)$(mandir)/man8/udevcontrol.8
278 @ extras="$(EXTRAS)"; for target in $$extras; do \
279 $(MAKE) -C $$target $@ || exit 1; \
281 .PHONY: uninstall-man
284 $(INSTALL) -d $(DESTDIR)$(udevdir)
285 $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
286 $(INSTALL_PROGRAM) -D udevtrigger $(DESTDIR)$(sbindir)/udevtrigger
287 $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
288 $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
289 $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
290 $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
291 @extras="$(EXTRAS)"; for target in $$extras; do \
292 $(MAKE) -C $$target $@ || exit 1; \
297 - $(sbindir)/udevd --daemon
302 - rm -f $(DESTDIR)$(sbindir)/udevd
303 - rm -f $(DESTDIR)$(sbindir)/udevtrigger
304 - rm -f $(DESTDIR)$(sbindir)/udevcontrol
305 - rm -f $(DESTDIR)$(usrsbindir)/udevmonitor
306 - rm -f $(DESTDIR)$(usrbindir)/udevinfo
307 - rm -f $(DESTDIR)$(usrbindir)/udevtest
312 @extras="$(EXTRAS)"; for target in $$extras; do \
313 $(MAKE) -C $$target $@ || exit 1; \
315 .PHONY: uninstall-bin
317 install: all install-bin install-config install-man
320 uninstall: uninstall-bin uninstall-man
324 @ cd test && ./udev-test.pl
325 @ cd test && ./udevstart-test.pl
329 test/simple-build-check.sh
334 @ echo "Summary of changes from v$(shell printf '%03i' $$(expr $(VERSION) - 1)) to v$(VERSION)" >> $@
335 @ echo "============================================" >> $@
337 @ git log --pretty=short $(shell printf '%03i' $$(expr $(VERSION) - 1))..HEAD | git shortlog >> $@
344 $(MAKE) clean all USE_GCOV=true
346 @ echo "binaries built with gcov support."
347 @ echo "run the tests and analyze with 'make udev_gcov.txt'"
350 # see docs/README-gcov_for_udev
351 udev_gcov.txt: $(wildcard *.gcda) $(wildcard *.gcno)
352 for file in `find -maxdepth 1 -name "*.gcno"`; do \
353 name=`basename $$file .gcno`; \
354 echo "################" >> $@; \
355 echo "$$name.c" >> $@; \
356 echo "################" >> $@; \
357 if [ -e "$$name.gcda" ]; then \
358 gcov -l "$$name.c" >> $@ 2>&1; \
360 echo "code for $$name.c was never executed" >> $@ 2>&1; \
364 echo "view $@ for the result"