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.
100 libsysfs/sysfs_class.o \
101 libsysfs/sysfs_device.o \
102 libsysfs/sysfs_dir.o \
103 libsysfs/sysfs_driver.o \
104 libsysfs/sysfs_utils.o \
106 LIBSYSFS = libsysfs/libsysfs.a
108 # config files automatically generated
110 $(LOCAL_CFG_DIR)/udev.conf
115 # override this to make udev look in a different location for it's config files
117 exec_prefix = ${prefix}
118 etcdir = ${prefix}/etc
119 sbindir = ${exec_prefix}/sbin
120 usrbindir = ${exec_prefix}/usr/bin
121 usrsbindir = ${exec_prefix}/usr/sbin
122 mandir = ${prefix}/usr/share/man
123 configdir = ${etcdir}/udev
125 udevdb = ${udevdir}/.udevdb
126 LOCAL_CFG_DIR = etc/udev
127 KERNEL_DIR = /lib/modules/${shell uname -r}/build
130 RELEASE_NAME = udev-$(VERSION)
132 INSTALL = /usr/bin/install -c
133 INSTALL_PROGRAM = ${INSTALL}
134 INSTALL_DATA = ${INSTALL} -m 644
135 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
142 RANLIB = $(CROSS)ranlib
144 STRIP = $(CROSS)strip
145 STRIPCMD = $(STRIP) -s
147 # check if compiler option is supported
148 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;}
150 CFLAGS = -g -Wall -pipe -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
151 WARNINGS = -Wstrict-prototypes -Wsign-compare -Wshadow \
152 -Wchar-subscripts -Wmissing-declarations -Wnested-externs \
153 -Wpointer-arith -Wcast-align -Wsign-compare -Wmissing-prototypes
154 WARNINGS += $(call cc-supports, -Wdeclaration-after-statement, )
155 CFLAGS += $(WARNINGS)
157 LDFLAGS = -Wl,-warn-common
159 # use -Os optimization if available, else use -O2
160 OPTFLAGS := $(call cc-supports, -Os, -O2)
161 CFLAGS += $(OPTFLAGS)
163 # include our local copy of libsysfs
164 CFLAGS += -I$(PWD)/libsysfs/sysfs \
167 ifeq ($(strip $(USE_LOG)),true)
171 # if DEBUG is enabled, then we do not strip
172 ifeq ($(strip $(DEBUG)),true)
174 STRIPCMD = /bin/true unstripped binary
177 ifeq ($(strip $(USE_GCOV)),true)
178 CFLAGS += -fprofile-arcs -ftest-coverage
179 LDFLAGS += -fprofile-arcs
182 # if our own version of klibc is used, we need to build it
183 ifeq ($(strip $(USE_KLIBC)),true)
184 KLIBC_INSTALL = $(PWD)/klibc/.install
185 KLCC = $(KLIBC_INSTALL)/bin/$(CROSS)klcc
191 ifeq ($(strip $(USE_SELINUX)),true)
192 UDEV_OBJS += udev_selinux.o
193 LIB_OBJS += -lselinux -lsepol
194 CFLAGS += -DUSE_SELINUX
197 ifeq ($(strip $(USE_STATIC)),true)
198 CFLAGS += -DUSE_STATIC
202 ifeq ($(strip $(V)),false)
210 all: $(KLCC) $(PROGRAMS) $(MAN_PAGES)
211 @extras="$(EXTRAS)"; for target in $$extras; do \
216 LDFLAGS="$(LDFLAGS)" \
217 STRIPCMD="$(STRIPCMD)" \
218 LIB_OBJS="$(LIB_OBJS)" \
219 LIBUDEV="$(PWD)/$(LIBUDEV)" \
220 LIBSYSFS="$(PWD)/$(LIBSYSFS)" \
221 KERNEL_DIR="$(KERNEL_DIR)" \
228 # clear implicit rules
232 %.o: %.c $(GEN_HEADERS)
233 $(QUIET) $(CC) -c $(CFLAGS) $< -o $@
235 # "Static Pattern Rule" to build all programs
236 $(PROGRAMS): %: $(HOST_PROGS) $(KLCC) $(HEADERS) $(GEN_HEADERS) $(LIBSYSFS) $(LIBUDEV) %.o
237 $(QUIET) $(LD) $(LDFLAGS) $@.o -o $@ $(LIBUDEV) $(LIBSYSFS) $(LIB_OBJS)
238 $(QUIET) $(STRIPCMD) $@
240 # our own copy of klibc, it is not used if KLCC is given
242 $(MAKE) -C klibc KRNLSRC=$(KERNEL_DIR) SUBDIRS=klibc TESTS= \
243 SHLIBDIR=$(KLIBC_INSTALL)/lib \
244 INSTALLDIR=$(KLIBC_INSTALL) \
245 bindir=$(KLIBC_INSTALL)/bin \
246 mandir=$(KLIBC_INSTALL)/man all install
247 .NOTPARALLEL: $(KLCC)
249 $(UDEV_OBJS): $(KLCC)
250 $(LIBUDEV): $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
252 $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
253 $(QUIET) $(RANLIB) $@
255 $(SYSFS_OBJS): $(KLCC)
256 $(LIBSYSFS): $(HOST_PROGS) $(SYSFS_OBJS)
258 $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
259 $(QUIET) $(RANLIB) $@
261 # generate config files
263 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $@.in > $@
265 # generate config header file
267 @echo "Creating udev_version.h"
268 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
269 @echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
270 @echo \#define UDEV_DB \"$(udevdb)\" >> $@
271 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
272 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
273 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
274 @echo \#define UDEV_BIN \"$(sbindir)/udev\" >> $@
275 @echo \#define UDEVD_BIN \"$(sbindir)/udevd\" >> $@
283 @$(HOSTCC) -O1 ccdv.c -o ccdv
287 - find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print0 | xargs -0rt rm -f
288 - find -name "*.gcno" -print0 | xargs -0rt rm -f
289 - find -name "*.gcda" -print0 | xargs -0rt rm -f
290 - find -name "*.gcov" -print0 | xargs -0rt rm -f
291 - rm -f udev_gcov.txt
292 - rm -f core $(PROGRAMS) $(GEN_HEADERS) $(GEN_CONFIGS)
293 $(MAKE) -C klibc SUBDIRS=klibc clean
294 @extras="$(EXTRAS)"; for target in $$extras; do \
296 $(MAKE) -C $$target $@; \
298 $(MAKE) -C klibc SUBDIRS=klibc spotless
299 rm -rf klibc/.install
303 git-tar-tree HEAD $(RELEASE_NAME) | gzip -9v > $(RELEASE_NAME).tar.gz
304 @echo "$(RELEASE_NAME).tar.gz created"
307 install-config: $(GEN_CONFIGS)
308 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
309 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
310 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
311 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
313 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
315 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
318 @extras="$(EXTRAS)"; for target in $$extras; do \
320 $(MAKE) -C $$target $@; \
322 .PHONY: install-config
325 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
326 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
327 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
328 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
329 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
330 $(INSTALL_DATA) -D udevsend.8 $(DESTDIR)$(mandir)/man8/udevsend.8
331 $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
332 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
333 @extras="$(EXTRAS)"; for target in $$extras; do \
335 $(MAKE) -C $$target $@; \
340 - rm -f $(DESTDIR)$(mandir)/man8/udev.8
341 - rm -f $(DESTDIR)$(mandir)/man8/udevinfo.8
342 - rm -f $(DESTDIR)$(mandir)/man8/udevtest.8
343 - rm -f $(DESTDIR)$(mandir)/man8/udevstart.8
344 - rm -f $(DESTDIR)$(mandir)/man8/udevd.8
345 - rm -f $(DESTDIR)$(mandir)/man8/udevmonitor.8
346 - rm -f $(DESTDIR)$(mandir)/man8/udevsend.8
347 - rm -f $(DESTDIR)$(mandir)/man8/udevcontrol.8
348 @extras="$(EXTRAS)"; for target in $$extras; do \
350 $(MAKE) -C $$target $@; \
352 .PHONY: uninstall-man
355 $(INSTALL) -d $(DESTDIR)$(udevdir)
356 $(INSTALL_PROGRAM) -D udev $(DESTDIR)$(sbindir)/udev
357 $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
358 $(INSTALL_PROGRAM) -D udevsend $(DESTDIR)$(sbindir)/udevsend
359 $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
360 $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
361 $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
362 $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
363 $(INSTALL_PROGRAM) -D udevstart $(DESTDIR)$(sbindir)/udevstart
364 @extras="$(EXTRAS)"; for target in $$extras; do \
366 $(MAKE) -C $$target $@; \
371 - $(sbindir)/udevd --daemon
376 - rm -f $(DESTDIR)$(sbindir)/udev
377 - rm -f $(DESTDIR)$(sbindir)/udevd
378 - rm -f $(DESTDIR)$(sbindir)/udevsend
379 - rm -f $(DESTDIR)$(sbindir)/udevinitsend
380 - rm -f $(DESTDIR)$(sbindir)/udeveventrecoreder
381 - rm -f $(DESTDIR)$(sbindir)/udevcontrol
382 - rm -f $(DESTDIR)$(sbindir)/udevstart
383 - rm -f $(DESTDIR)$(usrsbindir)/udevmonitor
384 - rm -f $(usrbindir)/udevinfo
385 - rm -f $(DESTDIR)$(DESTDIR)$(usrbindir)/udevtest
390 @extras="$(EXTRAS)"; for target in $$extras; do \
392 $(MAKE) -C $$target $@; \
394 .PHONY: uninstall-bin
396 install: all install-bin install-config install-man
399 uninstall: uninstall-bin uninstall-man
403 @ cd test && ./udev-test.pl
404 @ cd test && ./udevstart-test.pl
408 ./test/simple-build-check.sh
412 $(MAKE) clean all STRIPCMD= USE_GCOV=true
414 @echo "binaries built with gcov support."
415 @echo "run the tests and analyze with 'make udev_gcov.txt'"
418 # see docs/README-gcov_for_udev
419 udev_gcov.txt: $(wildcard *.gcda) $(wildcard *.gcno)
420 for file in `find -maxdepth 1 -name "*.gcno"`; do \
421 name=`basename $$file .gcno`; \
422 echo "################" >> $@; \
423 echo "$$name.c" >> $@; \
424 echo "################" >> $@; \
425 if [ -e "$$name.gcda" ]; then \
426 gcov -l "$$name.c" >> $@ 2>&1; \
428 echo "code for $$name.c was never executed" >> $@ 2>&1; \
432 echo "view $@ for the result"