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.
51 INSTALL_DIR = /usr/local/bin
52 RELEASE_NAME = $(ROOT)-$(VERSION)
53 LOCAL_CFG_DIR = etc/udev
54 HOTPLUG_EXEC = $(ROOT)
56 KERNEL_DIR = /lib/modules/${shell uname -r}/build
58 # override this to make udev look in a different location for it's config files
60 exec_prefix = ${prefix}
61 etcdir = ${prefix}/etc
62 sbindir = ${exec_prefix}/sbin
63 usrbindir = ${exec_prefix}/usr/bin
64 mandir = ${prefix}/usr/share/man
65 hotplugdir = ${etcdir}/hotplug.d/default
66 configdir = ${etcdir}/udev
67 initdir = ${etcdir}/init.d
68 dev_ddir = ${etcdir}/dev.d
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
77 udevdir = ${prefix}/udev
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 # use '-Os' optimization if available, else use -O2
107 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
108 then echo "-Os"; else echo "-O2" ; fi}
110 # check if compiler option is supported
111 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
113 CFLAGS += -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith -Wstrict-prototypes -Wsign-compare
114 CFLAGS += $(call cc-supports,-Wno-pointer-sign)
115 CFLAGS += $(call cc-supports,-Wdeclaration-after-statement)
117 CFLAGS += -D_GNU_SOURCE
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 \
155 SYSFS = $(PWD)/libsysfs/sysfs.a
157 CFLAGS += -I$(PWD)/libsysfs/sysfs \
160 ifeq ($(strip $(USE_LOG)),true)
164 # if DEBUG is enabled, then we do not strip or optimize
165 ifeq ($(strip $(DEBUG)),true)
166 CFLAGS += -O1 -g -DDEBUG
168 STRIPCMD = /bin/true -Since_we_are_debugging
170 CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer
172 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
175 # If we are using our version of klibc, then we need to build, link it, and then
176 # link udev against it statically. Otherwise, use glibc and link dynamically.
177 ifeq ($(strip $(USE_KLIBC)),true)
178 KLIBC_INSTALL = $(PWD)/klibc/.install
179 KLCC = $(KLIBC_INSTALL)/bin/klcc
184 CFLAGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
187 ifeq ($(strip $(USE_SELINUX)),true)
188 UDEV_OBJS += udev_selinux.o
189 LIB_OBJS += -lselinux
190 CFLAGS += -DUSE_SELINUX
193 ifeq ($(strip $(USE_STATIC)),true)
194 CFLAGS += -DUSE_STATIC
198 ifeq ($(strip $(V)),false)
206 # config files automatically generated
207 GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf
209 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(STARTER) $(GEN_CONFIGS) $(KLCC)
210 @extras="$(EXTRAS)" ; for target in $$extras ; do \
212 $(MAKE) prefix=$(prefix) \
215 KERNEL_DIR="$(KERNEL_DIR)" \
221 $(MAKE) -C klibc KRNLSRC=$(KERNEL_DIR) SUBDIRS=klibc TESTS= \
222 SHLIBDIR=$(KLIBC_INSTALL)/lib \
223 INSTALLDIR=$(KLIBC_INSTALL) \
224 bindir=$(KLIBC_INSTALL)/bin \
225 mandir=$(KLIBC_INSTALL)/man all install
226 -find $(KLIBC_INSTALL)/include -name SCCS -print| xargs rm -rf
230 $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
231 $(QUIET) $(RANLIB) $@
233 libsysfs/sysfs.a: $(SYSFS_OBJS)
235 $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
236 $(QUIET) $(RANLIB) $@
238 # header files automatically generated
239 GEN_HEADERS = udev_version.h
242 @echo "Building ccdv"
243 @$(HOSTCC) -O1 ccdv.c -o ccdv
245 # Rules on how to create the generated header files
247 @echo "Creating udev_version.h"
248 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
249 @echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
250 @echo \#define UDEV_DB \"$(udevdb)\" >> $@
251 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
252 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
253 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
254 @echo \#define UDEV_BIN \"$(DESTDIR)$(sbindir)/udev\" >> $@
255 @echo \#define UDEVD_BIN \"$(DESTDIR)$(sbindir)/udevd\" >> $@
257 # Rules on how to create the generated config files
258 $(LOCAL_CFG_DIR)/udev.conf:
259 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
261 GEN_MANPAGES = udev.8
262 GEN_MANPAGESIN = udev.8.in
263 # Rules on how to create the man pages
264 $(GEN_MANPAGES): $(GEN_MANPAGESIN)
265 sed -e "s:@udevdir@:$(udevdir):" < $@.in > $@
267 $(UDEV_OBJS): $(GEN_HEADERS) $(HOST_PROGS)
268 $(SYSFS_OBJS): $(HOST_PROGS)
269 $(OBJS): $(GEN_HEADERS) $(HOST_PROGS)
270 $(ROOT).o: $(GEN_HEADERS) $(HOST_PROGS)
271 $(TESTER).o: $(GEN_HEADERS) $(HOST_PROGS)
272 $(INFO).o: $(GEN_HEADERS) $(HOST_PROGS)
273 $(DAEMON).o: $(GEN_HEADERS) $(HOST_PROGS)
274 $(SENDER).o: $(GEN_HEADERS) $(HOST_PROGS)
275 $(STARTER).o: $(GEN_HEADERS) $(HOST_PROGS)
277 $(ROOT): $(KLCC) $(ROOT).o $(OBJS) $(HEADERS) $(GEN_MANPAGES)
278 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(ROOT).o $(OBJS) $(LIB_OBJS)
279 $(QUIET) $(STRIPCMD) $@
281 $(TESTER): $(KLCC) $(TESTER).o $(OBJS) $(HEADERS)
282 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(TESTER).o $(OBJS) $(LIB_OBJS)
283 $(QUIET) $(STRIPCMD) $@
285 $(INFO): $(KLCC) $(INFO).o $(OBJS) $(HEADERS)
286 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(INFO).o $(OBJS) $(LIB_OBJS)
287 $(QUIET) $(STRIPCMD) $@
289 $(DAEMON): $(KLCC) $(DAEMON).o $(OBJS) udevd.h
290 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(DAEMON).o $(OBJS) $(LIB_OBJS)
291 $(QUIET) $(STRIPCMD) $@
293 $(SENDER): $(KLCC) $(SENDER).o $(OBJS) udevd.h
294 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(SENDER).o $(OBJS) $(LIB_OBJS)
295 $(QUIET) $(STRIPCMD) $@
297 $(STARTER): $(KLCC) $(STARTER).o $(OBJS)
298 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(STARTER).o $(OBJS) $(LIB_OBJS)
299 $(QUIET) $(STRIPCMD) $@
302 $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
305 -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
307 -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) \
308 $(SENDER) $(TESTER) $(STARTER)
310 $(MAKE) -C klibc SUBDIRS=klibc clean
311 @extras="$(EXTRAS)" ; for target in $$extras ; do \
313 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
318 $(MAKE) -C klibc SUBDIRS=klibc spotless
319 rm -rf klibc/.install
321 DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v -e CVS -e "\.tar\.gz" -e "\/\." -e releases -e BitKeeper -e SCCS -e test/sys | sort )
322 DISTDIR := $(RELEASE_NAME)
328 bk export -w $(DISTDIR)
329 tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
331 @echo "$(RELEASE_NAME).tar.gz created"
334 small_release: $(DISTFILES) spotless
338 @-chmod 777 $(DISTDIR)
339 @for file in $(DISTFILES); do \
340 if test -d $$file; then \
341 mkdir $(DISTDIR)/$$file; \
343 cp -p $$file $(DISTDIR)/$$file; \
346 @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
348 @echo "Built $(RELEASE_NAME).tar.gz"
351 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
352 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
353 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
354 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
356 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
357 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
358 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
362 $(INSTALL) -d $(DESTDIR)$(dev_ddir)/default
363 $(INSTALL_PROGRAM) -D etc/dev.d/net/hotplug.dev $(DESTDIR)$(dev_ddir)/net/hotplug.dev
366 - rm $(dev_ddir)/net/hotplug.dev
367 - rmdir $(dev_ddir)/net
368 - rmdir $(dev_ddir)/default
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 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
380 - rm $(mandir)/man8/udev.8
381 - rm $(mandir)/man8/udevinfo.8
382 - rm $(mandir)/man8/udevtest.8
383 - rm $(mandir)/man8/udevstart.8
384 - rm $(mandir)/man8/udevd.8
385 - rm $(mandir)/man8/udevsend.8
387 install: install-config install-man install-dev.d all
388 $(INSTALL) -d $(DESTDIR)$(udevdir)
389 $(INSTALL) -d $(DESTDIR)$(hotplugdir)
390 $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
391 $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
392 $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
393 $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
394 $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
395 $(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
396 - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/10-udev.hotplug
401 @extras="$(EXTRAS)" ; for target in $$extras ; do \
403 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
407 uninstall: uninstall-man uninstall-dev.d
408 - rm $(hotplugdir)/10-udev.hotplug
409 - rm $(configdir)/rules.d/50-udev.rules
410 - rm $(configdir)/udev.conf
411 - rmdir $(configdir)/rules.d
413 - rm $(sbindir)/$(ROOT)
414 - rm $(sbindir)/$(DAEMON)
415 - rm $(sbindir)/$(SENDER)
416 - rm $(sbindir)/$(STARTER)
417 - rm $(usrbindir)/$(INFO)
418 - rm $(usrbindir)/$(TESTER)
419 - rmdir $(hotplugdir)
423 @extras="$(EXTRAS)" ; for target in $$extras ; do \
425 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
430 @ cd test && ./udev-test.pl