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.
98 libsysfs/sysfs_class.o \
99 libsysfs/sysfs_device.o \
100 libsysfs/sysfs_dir.o \
101 libsysfs/sysfs_driver.o \
102 libsysfs/sysfs_utils.o \
104 LIBSYSFS = libsysfs/libsysfs.a
106 # config files automatically generated
108 $(LOCAL_CFG_DIR)/udev.conf
113 # override this to make udev look in a different location for it's config files
115 exec_prefix = ${prefix}
116 etcdir = ${prefix}/etc
117 sbindir = ${exec_prefix}/sbin
118 usrbindir = ${exec_prefix}/usr/bin
119 usrsbindir = ${exec_prefix}/usr/sbin
120 mandir = ${prefix}/usr/share/man
121 configdir = ${etcdir}/udev
123 udevdb = ${udevdir}/.udevdb
124 LOCAL_CFG_DIR = etc/udev
127 INSTALL = /usr/bin/install -c
128 INSTALL_PROGRAM = ${INSTALL}
129 INSTALL_DATA = ${INSTALL} -m 644
130 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
137 RANLIB = $(CROSS)ranlib
139 STRIP = $(CROSS)strip
140 STRIPCMD = $(STRIP) -s
142 # check if compiler option is supported
143 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;}
145 CFLAGS = -g -Wall -pipe -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
146 WARNINGS = -Wstrict-prototypes -Wsign-compare -Wshadow \
147 -Wchar-subscripts -Wmissing-declarations -Wnested-externs \
148 -Wpointer-arith -Wcast-align -Wsign-compare -Wmissing-prototypes
149 WARNINGS += $(call cc-supports, -Wdeclaration-after-statement, )
150 CFLAGS += $(WARNINGS)
152 LDFLAGS = -Wl,-warn-common
154 # use -Os optimization if available, else use -O2
155 OPTFLAGS := $(call cc-supports, -Os, -O2)
156 CFLAGS += $(OPTFLAGS)
158 # include our local copy of libsysfs
159 CFLAGS += -I$(PWD)/libsysfs/sysfs \
162 ifeq ($(strip $(USE_LOG)),true)
166 # if DEBUG is enabled, then we do not strip
167 ifeq ($(strip $(DEBUG)),true)
172 ifeq ($(strip $(USE_GCOV)),true)
173 CFLAGS += -fprofile-arcs -ftest-coverage
174 LDFLAGS += -fprofile-arcs
177 # if our own version of klibc is used, we need to build it
178 ifeq ($(strip $(USE_KLIBC)),true)
179 KLCC = /usr/bin/$(CROSS)klcc
185 ifeq ($(strip $(USE_SELINUX)),true)
186 UDEV_OBJS += udev_selinux.o
187 LIB_OBJS += -lselinux -lsepol
188 CFLAGS += -DUSE_SELINUX
191 ifeq ($(strip $(USE_STATIC)),true)
192 CFLAGS += -DUSE_STATIC
196 ifeq ($(strip $(V)),false)
204 all: $(PROGRAMS) $(MAN_PAGES)
205 @extras="$(EXTRAS)"; for target in $$extras; do \
210 LDFLAGS="$(LDFLAGS)" \
211 STRIPCMD="$(STRIPCMD)" \
212 LIB_OBJS="$(LIB_OBJS)" \
213 LIBUDEV="$(PWD)/$(LIBUDEV)" \
214 LIBSYSFS="$(PWD)/$(LIBSYSFS)" \
221 # clear implicit rules
225 %.o: %.c $(GEN_HEADERS)
226 $(QUIET) $(CC) -c $(CFLAGS) $< -o $@
228 # "Static Pattern Rule" to build all programs
229 $(PROGRAMS): %: $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(LIBSYSFS) $(LIBUDEV) %.o
230 $(QUIET) $(LD) $(LDFLAGS) $@.o -o $@ $(LIBUDEV) $(LIBSYSFS) $(LIB_OBJS)
232 $(QUIET) $(STRIPCMD) $@
236 $(LIBUDEV): $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
238 $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
239 $(QUIET) $(RANLIB) $@
242 $(LIBSYSFS): $(HOST_PROGS) $(SYSFS_OBJS)
244 $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
245 $(QUIET) $(RANLIB) $@
247 # generate config files
249 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $@.in > $@
251 # generate config header file
253 @echo "Creating udev_version.h"
254 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
255 @echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
256 @echo \#define UDEV_DB \"$(udevdb)\" >> $@
257 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
258 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
259 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
260 @echo \#define UDEVD_BIN \"$(sbindir)/udevd\" >> $@
268 @$(HOSTCC) -O1 ccdv.c -o ccdv
272 - find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print0 | xargs -0rt rm -f
273 - find -name "*.gcno" -print0 | xargs -0rt rm -f
274 - find -name "*.gcda" -print0 | xargs -0rt rm -f
275 - find -name "*.gcov" -print0 | xargs -0rt rm -f
276 - rm -f udev_gcov.txt
277 - rm -f core $(PROGRAMS) $(GEN_HEADERS) $(GEN_CONFIGS)
278 - rm -f udev-$(VERSION).tar.gz
279 @extras="$(EXTRAS)"; for target in $$extras; do \
281 $(MAKE) -C $$target $@; \
286 git-tar-tree HEAD udev-$(VERSION) | gzip -9v > udev-$(VERSION).tar.gz
287 @echo "udev-$(VERSION).tar.gz created"
290 install-config: $(GEN_CONFIGS)
291 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
292 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
293 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
294 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
296 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
298 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
301 @extras="$(EXTRAS)"; for target in $$extras; do \
303 $(MAKE) -C $$target $@; \
305 .PHONY: install-config
308 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
309 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
310 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
311 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
312 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
313 $(INSTALL_DATA) -D udevsend.8 $(DESTDIR)$(mandir)/man8/udevsend.8
314 $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
315 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
316 @extras="$(EXTRAS)"; for target in $$extras; do \
318 $(MAKE) -C $$target $@; \
323 - rm -f $(DESTDIR)$(mandir)/man8/udev.8
324 - rm -f $(DESTDIR)$(mandir)/man8/udevinfo.8
325 - rm -f $(DESTDIR)$(mandir)/man8/udevtest.8
326 - rm -f $(DESTDIR)$(mandir)/man8/udevstart.8
327 - rm -f $(DESTDIR)$(mandir)/man8/udevd.8
328 - rm -f $(DESTDIR)$(mandir)/man8/udevmonitor.8
329 - rm -f $(DESTDIR)$(mandir)/man8/udevsend.8
330 - rm -f $(DESTDIR)$(mandir)/man8/udevcontrol.8
331 @extras="$(EXTRAS)"; for target in $$extras; do \
333 $(MAKE) -C $$target $@; \
335 .PHONY: uninstall-man
338 $(INSTALL) -d $(DESTDIR)$(udevdir)
339 $(INSTALL_PROGRAM) -D udev $(DESTDIR)$(sbindir)/udev
340 $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
341 $(INSTALL_PROGRAM) -D udevsend $(DESTDIR)$(sbindir)/udevsend
342 $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
343 $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
344 $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
345 $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
346 $(INSTALL_PROGRAM) -D udevstart $(DESTDIR)$(sbindir)/udevstart
347 @extras="$(EXTRAS)"; for target in $$extras; do \
349 $(MAKE) -C $$target $@; \
354 - $(sbindir)/udevd --daemon
359 - rm -f $(DESTDIR)$(sbindir)/udev
360 - rm -f $(DESTDIR)$(sbindir)/udevd
361 - rm -f $(DESTDIR)$(sbindir)/udevsend
362 - rm -f $(DESTDIR)$(sbindir)/udeveventrecoreder
363 - rm -f $(DESTDIR)$(sbindir)/udevcontrol
364 - rm -f $(DESTDIR)$(sbindir)/udevstart
365 - rm -f $(DESTDIR)$(usrsbindir)/udevmonitor
366 - rm -f $(usrbindir)/udevinfo
367 - rm -f $(DESTDIR)$(DESTDIR)$(usrbindir)/udevtest
372 @extras="$(EXTRAS)"; for target in $$extras; do \
374 $(MAKE) -C $$target $@; \
376 .PHONY: uninstall-bin
378 install: all install-bin install-config install-man
381 uninstall: uninstall-bin uninstall-man
385 @ cd test && ./udev-test.pl
386 @ cd test && ./udevstart-test.pl
390 ./test/simple-build-check.sh
394 $(MAKE) clean all STRIPCMD= USE_GCOV=true
396 @echo "binaries built with gcov support."
397 @echo "run the tests and analyze with 'make udev_gcov.txt'"
400 # see docs/README-gcov_for_udev
401 udev_gcov.txt: $(wildcard *.gcda) $(wildcard *.gcno)
402 for file in `find -maxdepth 1 -name "*.gcno"`; do \
403 name=`basename $$file .gcno`; \
404 echo "################" >> $@; \
405 echo "$$name.c" >> $@; \
406 echo "################" >> $@; \
407 if [ -e "$$name.gcda" ]; then \
408 gcov -l "$$name.c" >> $@ 2>&1; \
410 echo "code for $$name.c was never executed" >> $@ 2>&1; \
414 echo "view $@ for the result"