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 mandir = ${prefix}/usr/share/man
68 configdir = ${etcdir}/udev
71 INSTALL = /usr/bin/install -c
72 INSTALL_PROGRAM = ${INSTALL}
73 INSTALL_DATA = ${INSTALL} -m 644
74 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
76 # place to put our device nodes
78 udevdb = ${udevdir}/.udevdb
80 # set up PWD so that older versions of make will work with our build.
83 # If you are running a cross compiler, you may want to set this
84 # to something more interesting, like "arm-linux-". If you want
85 # to compile vs uClibc, that can be done here as well.
86 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
91 RANLIB = $(CROSS)ranlib
94 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
96 # code taken from uClibc to determine the current arch
97 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
98 -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
100 # code taken from uClibc to determine the gcc include dir
101 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
103 # code taken from uClibc to determine the libgcc.a filename
104 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
106 # check if compiler option is supported
107 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;}
109 CFLAGS += -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith \
110 -Wstrict-prototypes -Wsign-compare
111 CFLAGS += $(call cc-supports, -Wdeclaration-after-statement, )
113 CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
115 # use '-Os' optimization if available, else use -O2
116 OPTFLAGS := $(call cc-supports, -Os, -O2)
126 udev_libc_wrapper.h \
131 libsysfs/sysfs_class.o \
132 libsysfs/sysfs_device.o \
133 libsysfs/sysfs_dir.o \
134 libsysfs/sysfs_driver.o \
135 libsysfs/sysfs_utils.o \
157 SYSFS = $(PWD)/libsysfs/sysfs.a
159 CFLAGS += -I$(PWD)/libsysfs/sysfs \
162 ifeq ($(strip $(USE_LOG)),true)
166 # if DEBUG is enabled, then we do not strip or optimize
167 ifeq ($(strip $(DEBUG)),true)
168 CFLAGS += -O1 -g -DDEBUG
170 STRIPCMD = /bin/true -Since_we_are_debugging
172 CFLAGS += $(OPTFLAGS) -fomit-frame-pointer
174 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
177 # If we are using our version of klibc, then we need to build, link it, and then
178 # link udev against it statically. Otherwise, use glibc and link dynamically.
179 ifeq ($(strip $(USE_KLIBC)),true)
180 KLIBC_INSTALL = $(PWD)/klibc/.install
181 KLCC = $(KLIBC_INSTALL)/bin/$(CROSS)klcc
185 CFLAGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
188 ifeq ($(strip $(USE_SELINUX)),true)
189 UDEV_OBJS += udev_selinux.o
190 LIB_OBJS += -lselinux
191 CFLAGS += -DUSE_SELINUX
194 ifeq ($(strip $(USE_STATIC)),true)
195 CFLAGS += -DUSE_STATIC
199 ifeq ($(strip $(V)),false)
207 # config files automatically generated
208 GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf
210 all: $(ROOT) $(SENDER) $(COMPILE) $(INITSENDER) $(RECORDER) $(CONTROL) $(MONITOR)\
211 $(DAEMON) $(COMPILE) $(INFO) $(TESTER) $(STARTER) $(GEN_CONFIGS) $(KLCC)
212 @extras="$(EXTRAS)" ; for target in $$extras ; do \
214 $(MAKE) prefix=$(prefix) \
217 KERNEL_DIR="$(KERNEL_DIR)" \
223 $(MAKE) -j1 -C klibc KRNLSRC=$(KERNEL_DIR) SUBDIRS=klibc TESTS= \
224 SHLIBDIR=$(KLIBC_INSTALL)/lib \
225 INSTALLDIR=$(KLIBC_INSTALL) \
226 bindir=$(KLIBC_INSTALL)/bin \
227 mandir=$(KLIBC_INSTALL)/man all install
228 -find $(KLIBC_INSTALL)/include -name SCCS -print| xargs rm -rf
232 $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
233 $(QUIET) $(RANLIB) $@
235 libsysfs/sysfs.a: $(SYSFS_OBJS)
237 $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
238 $(QUIET) $(RANLIB) $@
240 # header files automatically generated
241 GEN_HEADERS = udev_version.h
244 @echo "Building ccdv"
245 @$(HOSTCC) -O1 ccdv.c -o ccdv
247 # Rules on how to create the generated header files
249 @echo "Creating udev_version.h"
250 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
251 @echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
252 @echo \#define UDEV_DB \"$(udevdb)\" >> $@
253 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
254 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
255 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
256 @echo \#define UDEV_BIN \"$(sbindir)/udev\" >> $@
257 @echo \#define UDEVD_BIN \"$(sbindir)/udevd\" >> $@
259 # Rules on how to create the generated config files
260 $(LOCAL_CFG_DIR)/udev.conf:
261 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
263 GEN_MANPAGES = udev.8
264 GEN_MANPAGESIN = udev.8.in
265 # Rules on how to create the man pages
266 $(GEN_MANPAGES): $(GEN_MANPAGESIN)
267 sed -e "s:@udevdir@:$(udevdir):" < $@.in > $@
269 $(UDEV_OBJS): $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
270 $(SYSFS_OBJS): $(HEADERS) $(HOST_PROGS) $(KLCC)
271 $(OBJS): $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
272 $(ROOT).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
273 $(TESTER).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
274 $(INFO).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
275 $(DAEMON).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
276 $(SENDER).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
277 $(COMPILE).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
278 $(INITSENDER).o: $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
279 $(RECORDER).o: $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
280 $(CONTROL).o: $(HEADERS) $( $(HEADERS)GEN_HEADERS) $(HOST_PROGS) $(KLCC)
281 $(MONITOR).o: $(HEADERS) $( $(HEADERS)GEN_HEADERS) $(HOST_PROGS) $(KLCC)
282 $(STARTER).o: $(HEADERS) $(GEN_HEADERS) $(HOST_PROGS) $(KLCC)
284 $(ROOT): $(KLCC) $(ROOT).o $(OBJS) $(HEADERS) $(GEN_MANPAGES)
285 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(ROOT).o $(OBJS) $(LIB_OBJS)
286 $(QUIET) $(STRIPCMD) $@
288 $(TESTER): $(KLCC) $(TESTER).o $(OBJS) $(HEADERS)
289 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(TESTER).o $(OBJS) $(LIB_OBJS)
290 $(QUIET) $(STRIPCMD) $@
292 $(INFO): $(KLCC) $(INFO).o $(OBJS) $(HEADERS)
293 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(INFO).o $(OBJS) $(LIB_OBJS)
294 $(QUIET) $(STRIPCMD) $@
296 $(DAEMON): $(KLCC) $(DAEMON).o $(OBJS) udevd.h
297 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(DAEMON).o $(OBJS) $(LIB_OBJS)
298 $(QUIET) $(STRIPCMD) $@
300 $(SENDER): $(KLCC) $(SENDER).o $(OBJS) udevd.h
301 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(SENDER).o $(OBJS) $(LIB_OBJS)
302 $(QUIET) $(STRIPCMD) $@
304 $(COMPILE): $(KLCC) $(COMPILE).o $(OBJS)
305 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(COMPILE).o $(OBJS) $(LIB_OBJS)
306 $(QUIET) $(STRIPCMD) $@
308 $(INITSENDER): $(KLCC) $(INITSENDER).o $(OBJS) udevd.h
309 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(INITSENDER).o $(OBJS) $(LIB_OBJS)
310 $(QUIET) $(STRIPCMD) $@
312 $(RECORDER): $(KLCC) $(RECORDER).o $(OBJS) udevd.h
313 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(RECORDER).o $(OBJS) $(LIB_OBJS)
314 $(QUIET) $(STRIPCMD) $@
316 $(CONTROL): $(KLCC) $(CONTROL).o $(OBJS) udevd.h
317 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CONTROL).o $(OBJS) $(LIB_OBJS)
318 $(QUIET) $(STRIPCMD) $@
320 $(MONITOR): $(KLCC) $(MONITOR).o $(OBJS) udevd.h
321 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(MONITOR).o $(OBJS) $(LIB_OBJS)
322 $(QUIET) $(STRIPCMD) $@
324 $(STARTER): $(KLCC) $(STARTER).o $(OBJS)
325 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(STARTER).o $(OBJS) $(LIB_OBJS)
326 $(QUIET) $(STRIPCMD) $@
329 $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
332 -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
334 -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) \
335 $(SENDER) $(COMPILE) $(INITSENDER) $(RECORDER) $(CONTROL) $(MONITOR) $(TESTER) $(STARTER)
337 $(MAKE) -C klibc SUBDIRS=klibc clean
338 @extras="$(EXTRAS)" ; for target in $$extras ; do \
340 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
345 $(MAKE) -C klibc SUBDIRS=klibc spotless
346 rm -rf klibc/.install
349 git-tar-tree HEAD $(RELEASE_NAME) | gzip -9v > $(RELEASE_NAME).tar.gz
350 @echo "$(RELEASE_NAME).tar.gz created"
353 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
354 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
355 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
356 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
358 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
360 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
365 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
366 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
367 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
368 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
369 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
370 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
373 - rm $(mandir)/man8/udev.8
374 - rm $(mandir)/man8/udevinfo.8
375 - rm $(mandir)/man8/udevtest.8
376 - rm $(mandir)/man8/udevstart.8
377 - rm $(mandir)/man8/udevd.8
378 - rm $(mandir)/man8/udevsend.8
380 install: install-config install-man all
381 $(INSTALL) -d $(DESTDIR)$(udevdir)
382 $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
383 $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
384 $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
385 $(INSTALL_PROGRAM) -D $(CONTROL) $(DESTDIR)$(sbindir)/$(CONTROL)
386 $(INSTALL_PROGRAM) -D $(MONITOR) $(DESTDIR)$(sbindir)/$(MONITOR)
387 $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
388 $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
389 $(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
393 - $(sbindir)/$(DAEMON) --daemon
395 @extras="$(EXTRAS)" ; for target in $$extras ; do \
397 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
401 uninstall: uninstall-man
402 - rm $(configdir)/rules.d/50-udev.rules
403 - rm $(configdir)/udev.conf
404 - rmdir $(configdir)/rules.d
406 - rm $(sbindir)/$(ROOT)
407 - rm $(sbindir)/$(DAEMON)
408 - rm $(sbindir)/$(SENDER)
409 - rm $(sbindir)/$(INITSENDER)
410 - rm $(sbindir)/$(RECORDER)
411 - rm $(sbindir)/$(CONTROL)
412 - rm $(sbindir)/$(MONITOR)
413 - rm $(sbindir)/$(STARTER)
414 - rm $(usrbindir)/$(INFO)
415 - rm $(usrbindir)/$(TESTER)
419 @extras="$(EXTRAS)" ; for target in $$extras ; do \
421 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
426 @ cd test && ./udev-test.pl
427 @ cd test && ./udevstart-test.pl