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
31 # (use it with DEBUG, works only with glibc)
34 # include Security-Enhanced Linux support
37 # comile with klibc instead of glibc
40 # set this to create statically linked binaries
43 # to build any of the extras programs pass:
44 # make EXTRAS="extras/<extra1> extras/<extra2>"
47 # make the build silent. Set this to something else to make it noisy again.
101 libsysfs
/sysfs_class.o \
102 libsysfs
/sysfs_device.o \
103 libsysfs
/sysfs_dir.o \
104 libsysfs
/sysfs_driver.o \
105 libsysfs
/sysfs_utils.o \
107 LIBSYSFS
= libsysfs
/libsysfs.a
109 # config files automatically generated
111 $(LOCAL_CFG_DIR
)/udev.conf
116 # override this to make udev look in a different location for it's config files
118 exec_prefix = ${prefix}
119 etcdir
= ${prefix}/etc
120 sbindir
= ${exec_prefix}/sbin
121 usrbindir
= ${exec_prefix}/usr
/bin
122 usrsbindir
= ${exec_prefix}/usr
/sbin
123 mandir = ${prefix}/usr
/share
/man
124 configdir
= ${etcdir}/udev
126 udevdb
= ${udevdir}/.udevdb
127 LOCAL_CFG_DIR
= etc
/udev
128 KERNEL_DIR
= /lib
/modules
/${shell uname
-r
}/build
131 RELEASE_NAME
= udev-
$(VERSION
)
133 INSTALL
= /usr
/bin
/install -c
134 INSTALL_PROGRAM
= ${INSTALL}
135 INSTALL_DATA
= ${INSTALL} -m
644
136 INSTALL_SCRIPT
= ${INSTALL_PROGRAM}
139 # If you are running a cross compiler, you may want to set this
140 # to something more interesting, like "arm-linux-". If you want
141 # to compile vs uClibc, that can be done here as well.
142 CROSS
= #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
146 STRIP
= $(CROSS
)strip
147 RANLIB
= $(CROSS
)ranlib
150 # code taken from uClibc to determine the current arch
151 ARCH
:= ${shell $(CC
) -dumpmachine | sed
-e s
'/-.*//' -e
's/i.86/i386/' -e
's/sparc.*/sparc/' \
152 -e
's/arm.*/arm/g' -e
's/m68k.*/m68k/' -e
's/powerpc/ppc/g'}
154 # determine the gcc include dir
155 GCCINCDIR
:= ${shell LC_ALL
=C
$(CC
) -print-search-dirs | sed
-ne
"s/install: \(.*\)/\1include/gp"}
157 # determine the libgcc.a filename
158 GCC_LIB
:= $(shell $(CC
) -print-libgcc-file-name
)
160 # check if compiler option is supported
161 cc-supports
= ${shell if
$(CC
) ${1} -S
-o
/dev
/null
-xc
/dev
/null
> /dev
/null
2>&1; then echo
"$(1)"; else echo
"$(2)"; fi
;}
163 CFLAGS
+= -Wall
-fno-builtin
-Wchar-subscripts
-Wpointer-arith \
164 -Wstrict-prototypes
-Wsign-compare
165 CFLAGS
+= $(call cc-supports
, -Wdeclaration-after-statement
, )
167 CFLAGS
+= -D_GNU_SOURCE
-D_FILE_OFFSET_BITS
=64
169 # use '-Os' optimization if available, else use -O2
170 OPTFLAGS
:= $(call cc-supports
, -Os
, -O2
)
172 # include our local copy of libsysfs
173 CFLAGS
+= -I
$(PWD
)/libsysfs
/sysfs \
176 ifeq ($(strip $(USE_LOG
)),true
)
180 # if DEBUG is enabled, then we do not strip or optimize
181 ifeq ($(strip $(DEBUG
)),true
)
182 CFLAGS
+= -O1
-g
-DDEBUG
184 STRIPCMD
= /bin
/true
-Since_we_are_debugging
186 CFLAGS
+= $(OPTFLAGS
) -fomit-frame-pointer
188 STRIPCMD
= $(STRIP
) -s
--remove-section
=.note
--remove-section
=.comment
191 ifeq ($(strip $(USE_GCOV
)),true
)
192 CFLAGS
+= -fprofile-arcs
-ftest-coverage
193 LDFLAGS
= -fprofile-arcs
196 # if our own version of klibc is used, we need to build it
197 ifeq ($(strip $(USE_KLIBC
)),true
)
198 KLIBC_INSTALL
= $(PWD
)/klibc
/.
install
199 KLCC
= $(KLIBC_INSTALL
)/bin
/$(CROSS
)klcc
203 CFLAGS
+= -Wshadow
-Wstrict-prototypes
-Wmissing-prototypes
-Wmissing-declarations
204 LDFLAGS
+= -Wl
,-warn-common
207 ifeq ($(strip $(USE_SELINUX
)),true
)
208 UDEV_OBJS
+= udev_selinux.o
209 LIB_OBJS
+= -lselinux
-lsepol
210 CFLAGS
+= -DUSE_SELINUX
213 ifeq ($(strip $(USE_STATIC
)),true
)
214 CFLAGS
+= -DUSE_STATIC
218 ifeq ($(strip $(V
)),false
)
226 all: $(KLCC
) $(PROGRAMS
) $(MAN_PAGES
)
227 @extras
="$(EXTRAS)"; for target in
$$extras; do \
229 $(MAKE
) prefix=$(prefix) \
233 LDFLAGS
="$(LDFLAGS)" \
234 STRIPCMD
="$(STRIPCMD)" \
235 LIB_OBJS
="$(LIB_OBJS)" \
236 LIBUDEV
="$(PWD)/$(LIBUDEV)" \
237 LIBSYSFS
="$(PWD)/$(LIBSYSFS)" \
238 KERNEL_DIR
="$(KERNEL_DIR)" \
245 # clear implicit rules
249 %.o
: %.c
$(GEN_HEADERS
)
250 $(QUIET
) $(CC
) -c
$(CFLAGS
) $< -o
$@
252 # "Static Pattern Rule" to build all programs
253 $(PROGRAMS
): %: $(HOST_PROGS
) $(KLCC
) $(HEADERS
) $(GEN_HEADERS
) $(LIBSYSFS
) $(LIBUDEV
) %.o
254 $(QUIET
) $(LD
) $(LDFLAGS
) $@.o
-o
$@
$(LIBUDEV
) $(LIBSYSFS
) $(LIB_OBJS
)
255 $(QUIET
) $(STRIPCMD
) $@
257 # our own copy of klibc, it is not used if KLCC is given
259 $(MAKE
) -C klibc KRNLSRC
=$(KERNEL_DIR
) SUBDIRS
=klibc TESTS
= \
260 SHLIBDIR
=$(KLIBC_INSTALL
)/lib \
261 INSTALLDIR
=$(KLIBC_INSTALL
) \
262 bindir=$(KLIBC_INSTALL
)/bin \
263 mandir=$(KLIBC_INSTALL
)/man
all install
264 -find
$(KLIBC_INSTALL
)/include -name SCCS
-print| xargs
rm -rf
265 .NOTPARALLEL
: $(KLCC
)
267 $(UDEV_OBJS
): $(KLCC
)
268 $(LIBUDEV
): $(HOST_PROGS
) $(HEADERS
) $(GEN_HEADERS
) $(UDEV_OBJS
)
270 $(QUIET
) $(AR
) cq
$@
$(UDEV_OBJS
)
271 $(QUIET
) $(RANLIB
) $@
273 $(SYSFS_OBJS
): $(KLCC
)
274 $(LIBSYSFS
): $(HOST_PROGS
) $(SYSFS_OBJS
)
276 $(QUIET
) $(AR
) cq
$@
$(SYSFS_OBJS
)
277 $(QUIET
) $(RANLIB
) $@
279 # generate config files
281 sed
-e
"s:@udevdir@:$(udevdir):" -e
"s:@configdir@:$(configdir):" < $@.in
> $@
283 # generate config header file
285 @echo
"Creating udev_version.h"
286 @echo \
#define UDEV_VERSION \"$(VERSION)\" > $@
287 @echo \
#define UDEV_ROOT \"$(udevdir)\" >> $@
288 @echo \
#define UDEV_DB \"$(udevdb)\" >> $@
289 @echo \
#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
290 @echo \
#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
291 @echo \
#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
292 @echo \
#define UDEV_BIN \"$(sbindir)/udev\" >> $@
293 @echo \
#define UDEVD_BIN \"$(sbindir)/udevd\" >> $@
301 @
$(HOSTCC
) -O1 ccdv.c
-o ccdv
305 - find . \
( -not
-type d \
) -and \
( -name
'*~' -o
-name
'*.[oas]' \
) -type f
-print0 | xargs
-0rt
rm -f
306 - find
-name
"*.gcno" -print0 | xargs
-0rt
rm -f
307 - find
-name
"*.gcda" -print0 | xargs
-0rt
rm -f
308 - find
-name
"*.gcov" -print0 | xargs
-0rt
rm -f
309 - rm -f udev_gcov.txt
310 - rm -f core
$(PROGRAMS
) $(GEN_HEADERS
) $(GEN_CONFIGS
)
311 $(MAKE
) -C klibc SUBDIRS
=klibc
clean
312 @extras
="$(EXTRAS)"; for target in
$$extras; do \
314 $(MAKE
) prefix=$(prefix) -C
$$target $@
; \
319 $(MAKE
) -C klibc SUBDIRS
=klibc spotless
320 rm -rf klibc
/.
install
324 git-tar-tree HEAD
$(RELEASE_NAME
) | gzip
-9v
> $(RELEASE_NAME
).
tar.gz
325 @echo
"$(RELEASE_NAME).tar.gz created"
328 install-config
: $(GEN_CONFIGS
)
329 $(INSTALL
) -d
$(DESTDIR
)$(configdir
)/rules.d
330 @if
[ ! -r
$(DESTDIR
)$(configdir
)/udev.conf
]; then \
331 echo
$(INSTALL_DATA
) $(LOCAL_CFG_DIR
)/udev.conf
$(DESTDIR
)$(configdir
); \
332 $(INSTALL_DATA
) $(LOCAL_CFG_DIR
)/udev.conf
$(DESTDIR
)$(configdir
); \
334 @if
[ ! -r
$(DESTDIR
)$(configdir
)/rules.d
/50-udev.rules
]; then \
336 echo
"pick a udev rules file from the etc/udev directory that matches your distribution"; \
339 @extras
="$(EXTRAS)"; for target in
$$extras; do \
341 $(MAKE
) prefix=$(prefix) -C
$$target $@
; \
343 .PHONY
: install-config
346 $(INSTALL_DATA
) -D udev
.8 $(DESTDIR
)$(mandir)/man8
/udev
.8
347 $(INSTALL_DATA
) -D udevinfo
.8 $(DESTDIR
)$(mandir)/man8
/udevinfo
.8
348 $(INSTALL_DATA
) -D udevtest
.8 $(DESTDIR
)$(mandir)/man8
/udevtest
.8
349 $(INSTALL_DATA
) -D udevstart
.8 $(DESTDIR
)$(mandir)/man8
/udevstart
.8
350 $(INSTALL_DATA
) -D udevd
.8 $(DESTDIR
)$(mandir)/man8
/udevd
.8
351 $(INSTALL_DATA
) -D udevsend
.8 $(DESTDIR
)$(mandir)/man8
/udevsend
.8
352 $(INSTALL_DATA
) -D udevmonitor
.8 $(DESTDIR
)$(mandir)/man8
/udevmonitor
.8
353 - ln
-f
-s udevd
.8 $(DESTDIR
)$(mandir)/man8
/udevcontrol
.8
354 @extras
="$(EXTRAS)"; for target in
$$extras; do \
356 $(MAKE
) prefix=$(prefix) -C
$$target $@
; \
361 - rm -f
$(mandir)/man8
/udev
.8
362 - rm -f
$(mandir)/man8
/udevinfo
.8
363 - rm -f
$(mandir)/man8
/udevtest
.8
364 - rm -f
$(mandir)/man8
/udevstart
.8
365 - rm -f
$(mandir)/man8
/udevd
.8
366 - rm -f
$(mandir)/man8
/udevmonitor
.8
367 - rm -f
$(mandir)/man8
/udevsend
.8
368 - rm -f
$(mandir)/man8
/udevcontrol
.8
369 @extras
="$(EXTRAS)"; for target in
$$extras; do \
371 $(MAKE
) prefix=$(prefix) -C
$$target $@
; \
373 .PHONY
: uninstall-man
376 $(INSTALL
) -d
$(DESTDIR
)$(udevdir
)
377 $(INSTALL_PROGRAM
) -D udev
$(DESTDIR
)$(sbindir
)/udev
378 $(INSTALL_PROGRAM
) -D udevd
$(DESTDIR
)$(sbindir
)/udevd
379 $(INSTALL_PROGRAM
) -D udevsend
$(DESTDIR
)$(sbindir
)/udevsend
380 $(INSTALL_PROGRAM
) -D udevcontrol
$(DESTDIR
)$(sbindir
)/udevcontrol
381 $(INSTALL_PROGRAM
) -D udevmonitor
$(DESTDIR
)$(usrsbindir
)/udevmonitor
382 $(INSTALL_PROGRAM
) -D udevinfo
$(DESTDIR
)$(usrbindir
)/udevinfo
383 $(INSTALL_PROGRAM
) -D udevtest
$(DESTDIR
)$(usrbindir
)/udevtest
384 $(INSTALL_PROGRAM
) -D udevstart
$(DESTDIR
)$(sbindir
)/udevstart
385 @extras
="$(EXTRAS)"; for target in
$$extras; do \
387 $(MAKE
) prefix=$(prefix) -C
$$target $@
; \
392 - $(sbindir
)/udevd
--daemon
397 - rm -f
$(sbindir
)/udev
398 - rm -f
$(sbindir
)/udevd
399 - rm -f
$(sbindir
)/udevsend
400 - rm -f
$(sbindir
)/udevinitsend
401 - rm -f
$(sbindir
)/udeveventrecoreder
402 - rm -f
$(sbindir
)/udevcontrol
403 - rm -f
$(sbindir
)/udevstart
404 - rm -f
$(usrsbindir
)/udevmonitor
405 - rm -f
$(usrbindir
)/udevinfo
406 - rm -f
$(usrbindir
)/udevtest
409 @extras
="$(EXTRAS)"; for target in
$$extras; do \
411 $(MAKE
) prefix=$(prefix) -C
$$target $@
; \
413 .PHONY
: uninstall-bin
415 install: all install-bin install-config install-man
418 uninstall: uninstall-bin uninstall-man
422 @ cd
test && .
/udev-test.pl
423 @ cd
test && .
/udevstart-test.pl
427 .
/test/simple-build-check.sh
431 $(MAKE
) clean all DEBUG
=true USE_GCOV
=true
433 @echo
"binaries built with gcov support."
434 @echo
"run the tests and analyze with 'make udev_gcov.txt'"
437 # see docs/README-gcov_for_udev
438 udev_gcov.txt
: $(wildcard *.gcda
) $(wildcard *.gcno
)
439 for file in
`find -maxdepth 1 -name "*.gcno"`; do \
440 name
=`basename $$file .gcno`; \
441 echo
"################" >> $@
; \
442 echo
"$$name.c" >> $@
; \
443 echo
"################" >> $@
; \
444 if
[ -e
"$$name.gcda" ]; then \
445 gcov
-l
"$$name.c" >> $@
2>&1; \
447 echo
"code for $$name.c was never executed" >> $@
2>&1; \
451 echo
"view $@ for the result"