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 ad development debug messages
26 # Set this to include Security-Enhanced Linux support.
29 # Set this to comile with the local version of klibc instead of glibc.
32 # Set this to create statically linked binaries.
35 # To build any of the extras programs, run with:
36 # make EXTRAS="extras/a extras/b"
39 # make the build silent. Set this to something else to make it noisy again.
49 INSTALL_DIR = /usr/local/bin
50 RELEASE_NAME = $(ROOT)-$(VERSION)
51 LOCAL_CFG_DIR = etc/udev
52 HOTPLUG_EXEC = $(ROOT)
54 KERNEL_DIR = /lib/modules/${shell uname -r}/build
56 # override this to make udev look in a different location for it's config files
58 exec_prefix = ${prefix}
59 etcdir = ${prefix}/etc
60 sbindir = ${exec_prefix}/sbin
61 usrbindir = ${exec_prefix}/usr/bin
62 mandir = ${prefix}/usr/share/man
63 hotplugdir = ${etcdir}/hotplug.d/default
64 configdir = ${etcdir}/udev
65 initdir = ${etcdir}/init.d
66 dev_ddir = ${etcdir}/dev.d
69 INSTALL = /usr/bin/install -c
70 INSTALL_PROGRAM = ${INSTALL}
71 INSTALL_DATA = ${INSTALL} -m 644
72 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
74 # place to put our device nodes
75 udevdir = ${prefix}/udev
76 udevdb = ${udevdir}/.udevdb
78 # set up PWD so that older versions of make will work with our build.
81 # If you are running a cross compiler, you may want to set this
82 # to something more interesting, like "arm-linux-". If you want
83 # to compile vs uClibc, that can be done here as well.
84 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
89 RANLIB = $(CROSS)ranlib
92 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0
94 # code taken from uClibc to determine the current arch
95 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
96 -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
98 # code taken from uClibc to determine the gcc include dir
99 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
101 # code taken from uClibc to determine the libgcc.a filename
102 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
104 # use '-Os' optimization if available, else use -O2
105 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
106 then echo "-Os"; else echo "-O2" ; fi}
108 # check if compiler option is supported
109 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
111 WARNINGS := -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith -Wstrict-prototypes -Wsign-compare
112 WARNINGS += $(call cc-supports,-Wno-pointer-sign)
113 WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
125 udev_libc_wrapper.h \
130 libsysfs/sysfs_class.o \
131 libsysfs/sysfs_device.o \
132 libsysfs/sysfs_dir.o \
133 libsysfs/sysfs_driver.o \
134 libsysfs/sysfs_utils.o \
154 SYSFS = $(PWD)/libsysfs/sysfs.a
156 CFLAGS += -I$(PWD)/libsysfs/sysfs \
159 ifeq ($(strip $(USE_LOG)),true)
163 # if DEBUG is enabled, then we do not strip or optimize
164 ifeq ($(strip $(DEBUG)),true)
165 CFLAGS += -O1 -g -DDEBUG -D_GNU_SOURCE
166 LDFLAGS += -Wl,-warn-common
167 STRIPCMD = /bin/true -Since_we_are_debugging
169 CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
170 LDFLAGS += -s -Wl,-warn-common
171 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
174 # If we are using our version of klibc, then we need to build, link it, and then
175 # link udev against it statically. Otherwise, use glibc and link dynamically.
176 ifeq ($(strip $(USE_KLIBC)),true)
177 KLIBC_BASE = $(PWD)/klibc
178 KLIBC_DIR = $(KLIBC_BASE)/klibc
179 INCLUDE_DIR := $(KLIBC_BASE)/include
180 LINUX_INCLUDE_DIR := $(KERNEL_DIR)/include
181 include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
182 ARCH_LIB_OBJS = $(KLIBC_DIR)/libc.a
183 CRT0 = $(KLIBC_DIR)/crt0.o
184 LIBC = $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
185 CFLAGS += $(WARNINGS) -nostdinc \
186 $(OPTFLAGS) $(REQFLAGS) \
187 -D__KLIBC__ -fno-builtin-printf \
189 -I$(INCLUDE_DIR)/arch/$(ARCH) \
190 -I$(INCLUDE_DIR)/bits$(BITSIZE) \
192 -I$(LINUX_INCLUDE_DIR)
194 LDFLAGS = -static -nostdlib -nostartfiles -nodefaultlibs
196 WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
199 CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
203 ifeq ($(strip $(USE_SELINUX)),true)
204 UDEV_OBJS += udev_selinux.o
205 LIB_OBJS += -lselinux
206 CFLAGS += -DUSE_SELINUX
209 ifeq ($(strip $(USE_STATIC)),true)
210 CFLAGS += -DUSE_STATIC
214 ifeq ($(strip $(V)),false)
222 # config files automatically generated
223 GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf
225 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(GEN_CONFIGS)
226 @extras="$(EXTRAS)" ; for target in $$extras ; do \
228 $(MAKE) prefix=$(prefix) \
231 KERNEL_DIR="$(KERNEL_DIR)" \
236 $(ARCH_LIB_OBJS) : $(CRT0)
239 @if [ ! -r klibc/linux ]; then \
240 ln -f -s $(KERNEL_DIR) klibc/linux; \
242 $(MAKE) -C klibc SUBDIRS=klibc TESTS=
246 $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
247 $(QUIET) $(RANLIB) $@
249 libsysfs/sysfs.a: $(SYSFS_OBJS)
251 $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
252 $(QUIET) $(RANLIB) $@
254 # header files automatically generated
255 GEN_HEADERS = udev_version.h
258 @echo "Building ccdv"
259 @$(HOSTCC) -O1 ccdv.c -o ccdv
261 # Rules on how to create the generated header files
263 @echo "Creating udev_version.h"
264 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
265 @echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
266 @echo \#define UDEV_DB \"$(udevdb)\" >> $@
267 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
268 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
269 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
270 @echo \#define UDEV_LOG_DEFAULT \"yes\" >> $@
271 @echo \#define UDEV_BIN \"$(DESTDIR)$(sbindir)/udev\" >> $@
272 @echo \#define UDEVD_BIN \"$(DESTDIR)$(sbindir)/udevd\" >> $@
274 # Rules on how to create the generated config files
275 $(LOCAL_CFG_DIR)/udev.conf:
276 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
278 GEN_MANPAGES = udev.8
279 GEN_MANPAGESIN = udev.8.in
280 # Rules on how to create the man pages
281 $(GEN_MANPAGES): $(GEN_MANPAGESIN)
282 sed -e "s:@udevdir@:$(udevdir):" < $@.in > $@
284 $(UDEV_OBJS): $(GEN_HEADERS) $(HOST_PROGS)
285 $(SYSFS_OBJS): $(HOST_PROGS)
286 $(OBJS): $(GEN_HEADERS) $(HOST_PROGS)
287 $(ROOT).o: $(GEN_HEADERS) $(HOST_PROGS)
288 $(TESTER).o: $(GEN_HEADERS) $(HOST_PROGS)
289 $(INFO).o: $(GEN_HEADERS) $(HOST_PROGS)
290 $(DAEMON).o: $(GEN_HEADERS) $(HOST_PROGS)
291 $(SENDER).o: $(GEN_HEADERS) $(HOST_PROGS)
292 $(STARTER).o: $(GEN_HEADERS) $(HOST_PROGS)
294 $(ROOT): $(LIBC) $(ROOT).o $(OBJS) $(HEADERS) $(GEN_MANPAGES)
295 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(ROOT).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
296 $(QUIET) $(STRIPCMD) $@
298 $(TESTER): $(LIBC) $(TESTER).o $(OBJS) $(HEADERS)
299 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(TESTER).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
300 $(QUIET) $(STRIPCMD) $@
302 $(INFO): $(LIBC) $(INFO).o $(OBJS) $(HEADERS)
303 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(INFO).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
304 $(QUIET) $(STRIPCMD) $@
306 $(DAEMON): $(LIBC) $(DAEMON).o $(OBJS) udevd.h
307 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(DAEMON).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
308 $(QUIET) $(STRIPCMD) $@
310 $(SENDER): $(LIBC) $(SENDER).o $(OBJS) udevd.h
311 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(SENDER).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
312 $(QUIET) $(STRIPCMD) $@
315 $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
319 -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
321 -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) $(SENDER) $(TESTER)
323 $(MAKE) -C klibc SUBDIRS=klibc clean
324 @extras="$(EXTRAS)" ; for target in $$extras ; do \
326 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
331 $(MAKE) -C klibc SUBDIRS=klibc spotless
334 DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v -e CVS -e "\.tar\.gz" -e "\/\." -e releases -e BitKeeper -e SCCS -e test/sys | sort )
335 DISTDIR := $(RELEASE_NAME)
341 bk export -w $(DISTDIR)
342 tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
344 @echo "$(RELEASE_NAME).tar.gz created"
347 small_release: $(DISTFILES) spotless
351 @-chmod 777 $(DISTDIR)
352 @for file in $(DISTFILES); do \
353 if test -d $$file; then \
354 mkdir $(DISTDIR)/$$file; \
356 cp -p $$file $(DISTDIR)/$$file; \
359 @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
361 @echo "Built $(RELEASE_NAME).tar.gz"
364 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
365 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
366 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
367 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
369 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
370 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
371 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
375 $(INSTALL) -d $(DESTDIR)$(dev_ddir)/default
376 $(INSTALL_PROGRAM) -D etc/dev.d/net/hotplug.dev $(DESTDIR)$(dev_ddir)/net/hotplug.dev
379 - rm $(dev_ddir)/net/hotplug.dev
380 - rmdir $(dev_ddir)/net
381 - rmdir $(dev_ddir)/default
385 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
386 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
387 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
388 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
389 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
390 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
393 - rm $(mandir)/man8/udev.8
394 - rm $(mandir)/man8/udevinfo.8
395 - rm $(mandir)/man8/udevtest.8
396 - rm $(mandir)/man8/udevstart.8
397 - rm $(mandir)/man8/udevd.8
398 - rm $(mandir)/man8/udevsend.8
400 install: install-config install-man install-dev.d all
401 $(INSTALL) -d $(DESTDIR)$(udevdir)
402 $(INSTALL) -d $(DESTDIR)$(hotplugdir)
403 $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
404 $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
405 $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
406 $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
407 $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
408 - ln -f -s $(sbindir)/udev $(DESTDIR)$(sbindir)/$(STARTER)
409 - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/10-udev.hotplug
414 @extras="$(EXTRAS)" ; for target in $$extras ; do \
416 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
420 uninstall: uninstall-man uninstall-dev.d
421 - rm $(hotplugdir)/10-udev.hotplug
422 - rm $(configdir)/rules.d/50-udev.rules
423 - rm $(configdir)/udev.conf
424 - rmdir $(configdir)/rules.d
426 - rm $(sbindir)/$(ROOT)
427 - rm $(sbindir)/$(DAEMON)
428 - rm $(sbindir)/$(SENDER)
429 - rm $(sbindir)/$(STARTER)
430 - rm $(usrbindir)/$(INFO)
431 - rm $(usrbindir)/$(TESTER)
432 - rmdir $(hotplugdir)
436 @extras="$(EXTRAS)" ; for target in $$extras ; do \
438 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
443 @ cd test && ./udev-test.pl