3 # Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
4 # Copyright (C) 2004-2005 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. Set this to something else to make it noisy again.
92 # config files automatically generated
94 $(LOCAL_CFG_DIR)/udev.conf
100 etcdir = ${prefix}/etc
101 sbindir = ${prefix}/sbin
102 usrbindir = ${prefix}/usr/bin
103 usrsbindir = ${prefix}/usr/sbin
104 libudevdir = ${prefix}/lib/udev
105 mandir = ${prefix}/usr/share/man
106 configdir = ${etcdir}/udev
108 LOCAL_CFG_DIR = etc/udev
111 INSTALL = /usr/bin/install -c
112 INSTALL_PROGRAM = ${INSTALL}
113 INSTALL_DATA = ${INSTALL} -m 644
114 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
121 RANLIB = $(CROSS)ranlib
123 STRIP = $(CROSS)strip
124 STRIPCMD = $(STRIP) -s
126 CFLAGS = -g -Wall -pipe -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
127 WARNINGS = -Wstrict-prototypes -Wsign-compare -Wshadow \
128 -Wchar-subscripts -Wmissing-declarations -Wnested-externs \
129 -Wpointer-arith -Wcast-align -Wsign-compare -Wmissing-prototypes
130 CFLAGS += $(WARNINGS)
132 LDFLAGS = -Wl,-warn-common
135 CFLAGS += $(OPTFLAGS)
137 ifeq ($(strip $(USE_LOG)),true)
141 # if DEBUG is enabled, then we do not strip
142 ifeq ($(strip $(DEBUG)),true)
147 ifeq ($(strip $(USE_GCOV)),true)
148 CFLAGS += -fprofile-arcs -ftest-coverage
149 LDFLAGS += -fprofile-arcs
152 # if our own version of klibc is used, we need to build it
153 ifeq ($(strip $(USE_KLIBC)),true)
154 KLCC = /usr/bin/$(CROSS)klcc
160 ifeq ($(strip $(USE_SELINUX)),true)
161 UDEV_OBJS += udev_selinux.o
162 LIB_OBJS += -lselinux -lsepol
163 CFLAGS += -DUSE_SELINUX
166 ifeq ($(strip $(USE_STATIC)),true)
167 CFLAGS += -DUSE_STATIC
171 ifeq ($(strip $(V)),false)
179 all: $(PROGRAMS) $(MAN_PAGES)
180 @extras="$(EXTRAS)"; for target in $$extras; do \
185 LDFLAGS="$(LDFLAGS)" \
186 STRIPCMD="$(STRIPCMD)" \
187 LIB_OBJS="$(LIB_OBJS)" \
188 LIBUDEV="$(PWD)/$(LIBUDEV)" \
190 -C $$target $@ || exit 1; \
195 # clear implicit rules
199 %.o: %.c $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS)
200 $(QUIET) $(CC) -c $(CFLAGS) $< -o $@
202 # "Static Pattern Rule" to build all programs
203 $(PROGRAMS): %: $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(LIBUDEV) %.o
204 $(QUIET) $(LD) $(LDFLAGS) $@.o -o $@ $(LIBUDEV) $(LIB_OBJS)
206 $(QUIET) $(STRIPCMD) $@
209 $(LIBUDEV): $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
211 $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
212 $(QUIET) $(RANLIB) $@
214 # generate config files
216 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $@.in > $@
218 # generate config header file
220 @echo "Creating udev_version.h"
221 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
222 @echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
223 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
224 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
232 @$(HOSTCC) -O1 ccdv.c -o ccdv
236 - rm -f $(HOST_PROGS)
237 - find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print0 | xargs -0rt rm -f
238 - find -name "*.gcno" -print0 | xargs -0rt rm -f
239 - find -name "*.gcda" -print0 | xargs -0rt rm -f
240 - find -name "*.gcov" -print0 | xargs -0rt rm -f
241 - rm -f udev_gcov.txt
242 - rm -f core $(PROGRAMS) $(GEN_HEADERS) $(GEN_CONFIGS)
243 - rm -f udev-$(VERSION).tar.gz
244 @extras="$(EXTRAS)"; for target in $$extras; do \
246 $(MAKE) -C $$target $@ || exit 1; \
251 git-tar-tree HEAD udev-$(VERSION) | gzip -9v > udev-$(VERSION).tar.gz
252 @echo "udev-$(VERSION).tar.gz created"
255 install-config: $(GEN_CONFIGS)
256 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
257 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
258 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
259 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
261 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
263 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
266 @extras="$(EXTRAS)"; for target in $$extras; do \
268 $(MAKE) -C $$target $@ || exit 1; \
270 .PHONY: install-config
273 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
274 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
275 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
276 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
277 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
278 $(INSTALL_DATA) -D udevsend.8 $(DESTDIR)$(mandir)/man8/udevsend.8
279 $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
280 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
281 @extras="$(EXTRAS)"; for target in $$extras; do \
283 $(MAKE) -C $$target $@ || exit 1; \
288 - rm -f $(DESTDIR)$(mandir)/man8/udev.8
289 - rm -f $(DESTDIR)$(mandir)/man8/udevinfo.8
290 - rm -f $(DESTDIR)$(mandir)/man8/udevtest.8
291 - rm -f $(DESTDIR)$(mandir)/man8/udevstart.8
292 - rm -f $(DESTDIR)$(mandir)/man8/udevd.8
293 - rm -f $(DESTDIR)$(mandir)/man8/udevmonitor.8
294 - rm -f $(DESTDIR)$(mandir)/man8/udevsend.8
295 - rm -f $(DESTDIR)$(mandir)/man8/udevcontrol.8
296 @extras="$(EXTRAS)"; for target in $$extras; do \
298 $(MAKE) -C $$target $@ || exit 1; \
300 .PHONY: uninstall-man
303 $(INSTALL) -d $(DESTDIR)$(udevdir)
304 $(INSTALL_PROGRAM) -D udev $(DESTDIR)$(sbindir)/udev
305 $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
306 $(INSTALL_PROGRAM) -D udevsend $(DESTDIR)$(sbindir)/udevsend
307 $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
308 $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
309 $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
310 $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
311 $(INSTALL_PROGRAM) -D udevstart $(DESTDIR)$(sbindir)/udevstart
312 @extras="$(EXTRAS)"; for target in $$extras; do \
314 $(MAKE) -C $$target $@ || exit 1; \
319 - $(sbindir)/udevd --daemon
324 - rm -f $(DESTDIR)$(sbindir)/udev
325 - rm -f $(DESTDIR)$(sbindir)/udevd
326 - rm -f $(DESTDIR)$(sbindir)/udevsend
327 - rm -f $(DESTDIR)$(sbindir)/udevcontrol
328 - rm -f $(DESTDIR)$(sbindir)/udevstart
329 - rm -f $(DESTDIR)$(usrsbindir)/udevmonitor
330 - rm -f $(usrbindir)/udevinfo
331 - rm -f $(DESTDIR)$(DESTDIR)$(usrbindir)/udevtest
336 @extras="$(EXTRAS)"; for target in $$extras; do \
338 $(MAKE) -C $$target $@ || exit 1; \
340 .PHONY: uninstall-bin
342 install: all install-bin install-config install-man
345 uninstall: uninstall-bin uninstall-man
349 @ cd test && ./udev-test.pl
350 @ cd test && ./udevstart-test.pl
354 test/simple-build-check.sh
359 @ echo "Summary of changes from v$(shell printf '%03i' $$(expr $(VERSION) - 1)) to v$(VERSION)" >> $@
360 @ echo "============================================" >> $@
362 @ git log --pretty=short $(shell printf '%03i' $$(expr $(VERSION) - 1))..HEAD | git shortlog >> $@
369 $(MAKE) clean all STRIPCMD= USE_GCOV=true
371 @echo "binaries built with gcov support."
372 @echo "run the tests and analyze with 'make udev_gcov.txt'"
375 # see docs/README-gcov_for_udev
376 udev_gcov.txt: $(wildcard *.gcda) $(wildcard *.gcno)
377 for file in `find -maxdepth 1 -name "*.gcno"`; do \
378 name=`basename $$file .gcno`; \
379 echo "################" >> $@; \
380 echo "$$name.c" >> $@; \
381 echo "################" >> $@; \
382 if [ -e "$$name.gcda" ]; then \
383 gcov -l "$$name.c" >> $@ 2>&1; \
385 echo "code for $$name.c was never executed" >> $@ 2>&1; \
389 echo "view $@ for the result"