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
20 # Set this to make use of syslog.
23 # Set this to compile-in development debug messages. Pass UDEV_LOG="debug"
24 # to the executed binary or set the value in the udev configuration file to
25 # let udev print the debug messages to syslog.
28 # Set this to include Security-Enhanced Linux support.
31 # Set this to comile with klibc instead of glibc.
34 # Set this to create statically linked binaries.
37 # To build any of the extras programs, run with:
38 # make EXTRAS="extras/a extras/b"
41 # make the build silent. Set this to something else to make it noisy again.
48 COMPILE = udevrulescompile
49 INITSENDER = udevinitsend
50 RECORDER = udeveventrecorder
56 RELEASE_NAME = $(ROOT)-$(VERSION)
57 LOCAL_CFG_DIR = etc/udev
59 KERNEL_DIR = /lib/modules/${shell uname -r}/build
61 # override this to make udev look in a different location for it's config files
63 exec_prefix = ${prefix}
64 etcdir = ${prefix}/etc
65 sbindir = ${exec_prefix}/sbin
66 usrbindir = ${exec_prefix}/usr/bin
67 usrsbindir = ${exec_prefix}/usr/sbin
68 mandir = ${prefix}/usr/share/man
69 configdir = ${etcdir}/udev
72 INSTALL = /usr/bin/install -c
73 INSTALL_PROGRAM = ${INSTALL}
74 INSTALL_DATA = ${INSTALL} -m 644
75 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
77 # place to put our device nodes
79 udevdb = ${udevdir}/.udevdb
81 # set up PWD so that older versions of make will work with our build.
84 # If you are running a cross compiler, you may want to set this
85 # to something more interesting, like "arm-linux-". If you want
86 # to compile vs uClibc, that can be done here as well.
87 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
92 RANLIB = $(CROSS)ranlib
95 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
97 # code taken from uClibc to determine the current arch
98 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
99 -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
101 # code taken from uClibc to determine the gcc include dir
102 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
104 # code taken from uClibc to determine the libgcc.a filename
105 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
107 # check if compiler option is supported
108 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;}
110 CFLAGS += -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith \
111 -Wstrict-prototypes -Wsign-compare
112 CFLAGS += $(call cc-supports, -Wdeclaration-after-statement, )
114 CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
116 # use '-Os' optimization if available, else use -O2
117 OPTFLAGS := $(call cc-supports, -Os, -O2)
127 udev_libc_wrapper.h \
132 libsysfs/sysfs_class.o \
133 libsysfs/sysfs_device.o \
134 libsysfs/sysfs_dir.o \
135 libsysfs/sysfs_driver.o \
136 libsysfs/sysfs_utils.o \
150 udev_utils_string.o \
159 SYSFS = $(PWD)/libsysfs/sysfs.a
168 CFLAGS += -I$(PWD)/libsysfs/sysfs \
171 ifeq ($(strip $(USE_LOG)),true)
175 # if DEBUG is enabled, then we do not strip or optimize
176 ifeq ($(strip $(DEBUG)),true)
177 CFLAGS += -O1 -g -DDEBUG
179 STRIPCMD = /bin/true -Since_we_are_debugging
181 CFLAGS += $(OPTFLAGS) -fomit-frame-pointer
183 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
186 # If we are using our version of klibc, then we need to build, link it, and then
187 # link udev against it statically. Otherwise, use glibc and link dynamically.
188 ifeq ($(strip $(USE_KLIBC)),true)
189 KLIBC_INSTALL = $(PWD)/klibc/.install
190 KLCC = $(KLIBC_INSTALL)/bin/$(CROSS)klcc
194 CFLAGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
197 ifeq ($(strip $(USE_SELINUX)),true)
198 UDEV_OBJS += udev_selinux.o
199 LIB_OBJS += -lselinux
200 CFLAGS += -DUSE_SELINUX
203 ifeq ($(strip $(USE_STATIC)),true)
204 CFLAGS += -DUSE_STATIC
208 ifeq ($(strip $(V)),false)
216 # config files automatically generated
217 GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf
219 all: $(ROOT) $(SENDER) $(COMPILE) $(INITSENDER) $(RECORDER) $(CONTROL) $(MONITOR)\
220 $(DAEMON) $(COMPILE) $(INFO) $(TESTER) $(STARTER) $(GEN_CONFIGS) $(KLCC)
221 @extras="$(EXTRAS)" ; for target in $$extras ; do \
223 $(MAKE) prefix=$(prefix) \
226 KERNEL_DIR="$(KERNEL_DIR)" \
232 $(MAKE) -j1 -C klibc KRNLSRC=$(KERNEL_DIR) SUBDIRS=klibc TESTS= \
233 SHLIBDIR=$(KLIBC_INSTALL)/lib \
234 INSTALLDIR=$(KLIBC_INSTALL) \
235 bindir=$(KLIBC_INSTALL)/bin \
236 mandir=$(KLIBC_INSTALL)/man all install
237 -find $(KLIBC_INSTALL)/include -name SCCS -print| xargs rm -rf
241 $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
242 $(QUIET) $(RANLIB) $@
244 libsysfs/sysfs.a: $(SYSFS_OBJS)
246 $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
247 $(QUIET) $(RANLIB) $@
249 # header files automatically generated
250 GEN_HEADERS = udev_version.h
253 @echo "Building ccdv"
254 @$(HOSTCC) -O1 ccdv.c -o ccdv
256 # Rules on how to create the generated header files
258 @echo "Creating udev_version.h"
259 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
260 @echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
261 @echo \#define UDEV_DB \"$(udevdb)\" >> $@
262 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
263 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
264 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
265 @echo \#define UDEV_BIN \"$(sbindir)/udev\" >> $@
266 @echo \#define UDEVD_BIN \"$(sbindir)/udevd\" >> $@
268 # Rules on how to create the generated config files
269 $(LOCAL_CFG_DIR)/udev.conf:
270 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
276 $(UDEV_OBJS): $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
277 $(SYSFS_OBJS): $(HEADERS) $(HOST_PROGS) $(KLCC)
278 $(OBJS): $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
279 $(ROOT).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
280 $(TESTER).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
281 $(INFO).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
282 $(DAEMON).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
283 $(SENDER).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
284 $(COMPILE).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
285 $(INITSENDER).o: $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
286 $(RECORDER).o: $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
287 $(CONTROL).o: $(HEADERS) $( $(HEADERS)GEN_HEADERS) $(HOST_PROGS) $(KLCC)
288 $(MONITOR).o: $(HEADERS) $( $(HEADERS)GEN_HEADERS) $(HOST_PROGS) $(KLCC)
289 $(STARTER).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
291 $(ROOT): $(KLCC) $(ROOT).o $(OBJS) $(HEADERS) $(MAN_PAGES)
292 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(ROOT).o $(OBJS) $(LIB_OBJS)
293 $(QUIET) $(STRIPCMD) $@
295 $(TESTER): $(KLCC) $(TESTER).o $(OBJS) $(HEADERS)
296 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(TESTER).o $(OBJS) $(LIB_OBJS)
297 $(QUIET) $(STRIPCMD) $@
299 $(INFO): $(KLCC) $(INFO).o $(OBJS) $(HEADERS)
300 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(INFO).o $(OBJS) $(LIB_OBJS)
301 $(QUIET) $(STRIPCMD) $@
303 $(DAEMON): $(KLCC) $(DAEMON).o $(OBJS) udevd.h
304 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(DAEMON).o $(OBJS) $(LIB_OBJS)
305 $(QUIET) $(STRIPCMD) $@
307 $(SENDER): $(KLCC) $(SENDER).o $(OBJS) udevd.h
308 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(SENDER).o $(OBJS) $(LIB_OBJS)
309 $(QUIET) $(STRIPCMD) $@
311 $(COMPILE): $(KLCC) $(COMPILE).o $(OBJS)
312 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(COMPILE).o $(OBJS) $(LIB_OBJS)
313 $(QUIET) $(STRIPCMD) $@
315 $(INITSENDER): $(KLCC) $(INITSENDER).o $(OBJS) udevd.h
316 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(INITSENDER).o $(OBJS) $(LIB_OBJS)
317 $(QUIET) $(STRIPCMD) $@
319 $(RECORDER): $(KLCC) $(RECORDER).o $(OBJS) udevd.h
320 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(RECORDER).o $(OBJS) $(LIB_OBJS)
321 $(QUIET) $(STRIPCMD) $@
323 $(CONTROL): $(KLCC) $(CONTROL).o $(OBJS) udevd.h
324 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CONTROL).o $(OBJS) $(LIB_OBJS)
325 $(QUIET) $(STRIPCMD) $@
327 $(MONITOR): $(KLCC) $(MONITOR).o $(OBJS) udevd.h
328 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(MONITOR).o $(OBJS) $(LIB_OBJS)
329 $(QUIET) $(STRIPCMD) $@
331 $(STARTER): $(KLCC) $(STARTER).o $(OBJS)
332 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(STARTER).o $(OBJS) $(LIB_OBJS)
333 $(QUIET) $(STRIPCMD) $@
336 $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
339 -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
341 -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(INFO) $(DAEMON) \
342 $(SENDER) $(COMPILE) $(INITSENDER) $(RECORDER) $(CONTROL) $(MONITOR) $(TESTER) $(STARTER)
344 $(MAKE) -C klibc SUBDIRS=klibc clean
345 @extras="$(EXTRAS)" ; for target in $$extras ; do \
347 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
352 $(MAKE) -C klibc SUBDIRS=klibc spotless
353 rm -rf klibc/.install
356 git-tar-tree HEAD $(RELEASE_NAME) | gzip -9v > $(RELEASE_NAME).tar.gz
357 @echo "$(RELEASE_NAME).tar.gz created"
360 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
361 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
362 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
363 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
365 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
367 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
372 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
373 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
374 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
375 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
376 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
377 $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
378 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
379 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
382 - rm $(mandir)/man8/udev.8
383 - rm $(mandir)/man8/udevinfo.8
384 - rm $(mandir)/man8/udevtest.8
385 - rm $(mandir)/man8/udevstart.8
386 - rm $(mandir)/man8/udevd.8
387 - rm $(mandir)/man8/udevmonitor.8
388 - rm $(mandir)/man8/udevsend.8
389 - rm $(mandir)/man8/udevcontrol.8
391 install: install-config install-man all
392 $(INSTALL) -d $(DESTDIR)$(udevdir)
393 $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
394 $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
395 $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
396 $(INSTALL_PROGRAM) -D $(CONTROL) $(DESTDIR)$(sbindir)/$(CONTROL)
397 $(INSTALL_PROGRAM) -D $(MONITOR) $(DESTDIR)$(usrsbindir)/$(MONITOR)
398 $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
399 $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
400 $(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
404 - $(sbindir)/$(DAEMON) --daemon
406 @extras="$(EXTRAS)" ; for target in $$extras ; do \
408 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
412 uninstall: uninstall-man
413 - rm $(configdir)/rules.d/50-udev.rules
414 - rm $(configdir)/udev.conf
415 - rmdir $(configdir)/rules.d
417 - rm $(sbindir)/$(ROOT)
418 - rm $(sbindir)/$(DAEMON)
419 - rm $(sbindir)/$(SENDER)
420 - rm $(sbindir)/$(INITSENDER)
421 - rm $(sbindir)/$(RECORDER)
422 - rm $(sbindir)/$(CONTROL)
423 - rm $(sbindir)/$(STARTER)
424 - rm $(usrsbindir)/$(MONITOR)
425 - rm $(usrbindir)/$(INFO)
426 - rm $(usrbindir)/$(TESTER)
430 @extras="$(EXTRAS)" ; for target in $$extras ; do \
432 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
437 @ cd test && ./udev-test.pl
438 @ cd test && ./udevstart-test.pl