3 # Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 # Set the following to control the use of syslog
20 # Set it to `false' to remove all logging
23 # Set the following to `true' to log the debug
24 # and make a unstripped, unoptimized binary.
25 # Leave this set to `false' for production use.
28 # Set this to compile with Security-Enhanced Linux support.
38 INSTALL_DIR = /usr/local/bin
39 RELEASE_NAME = $(ROOT)-$(VERSION)
40 LOCAL_CFG_DIR = etc/udev
41 HOTPLUG_EXEC = $(ROOT)
45 KERNEL_DIR = /lib/modules/${shell uname -r}/build
47 # override this to make udev look in a different location for it's config files
49 exec_prefix = ${prefix}
50 etcdir = ${prefix}/etc
51 sbindir = ${exec_prefix}/sbin
52 usrbindir = ${exec_prefix}/usr/bin
53 mandir = ${prefix}/usr/share/man
54 hotplugdir = ${etcdir}/hotplug.d/default
55 configdir = ${etcdir}/udev
56 initdir = ${etcdir}/init.d
57 dev_ddir = ${etcdir}/dev.d
60 INSTALL = /usr/bin/install -c
61 INSTALL_PROGRAM = ${INSTALL}
62 INSTALL_DATA = ${INSTALL} -m 644
63 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
65 # To build any of the extras programs, run with:
66 # make EXTRAS="extras/a extras/b"
69 # place to put our device nodes
70 udevdir = ${prefix}/udev
71 udevdb = ${udevdir}/.udevdb
73 # Comment out this line to build with something other
74 # than the local version of klibc
77 # make the build silent (well, at least the udev part) Set this
78 # to something else to make it noisy again.
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 ARCH_LIB_OBJS CRT0
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 # use '-Os' optimization if available, else use -O2
108 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
109 then echo "-Os"; else echo "-O2" ; fi}
111 # check if compiler option is supported
112 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
114 WARNINGS := -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith -Wstrict-prototypes -Wsign-compare
115 WARNINGS += $(call cc-supports,-Wno-pointer-sign)
116 WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
128 udev_libc_wrapper.h \
133 libsysfs/sysfs_class.o \
134 libsysfs/sysfs_device.o \
135 libsysfs/sysfs_dir.o \
136 libsysfs/sysfs_driver.o \
137 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 -D_GNU_SOURCE
169 LDFLAGS += -Wl,-warn-common
170 STRIPCMD = /bin/true -Since_we_are_debugging
172 CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
173 LDFLAGS += -s -Wl,-warn-common
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_BASE = $(PWD)/klibc
181 KLIBC_DIR = $(KLIBC_BASE)/klibc
182 INCLUDE_DIR := $(KLIBC_BASE)/include
183 LINUX_INCLUDE_DIR := $(KERNEL_DIR)/include
184 include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
185 # arch specific objects
186 ARCH_LIB_OBJS = $(KLIBC_DIR)/libc.a
189 CRT0 = $(KLIBC_DIR)/crt0.o
190 LIBC = $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
191 CFLAGS += $(WARNINGS) -nostdinc \
192 $(OPTFLAGS) $(REQFLAGS) \
193 -D__KLIBC__ -fno-builtin-printf \
195 -I$(INCLUDE_DIR)/arch/$(ARCH) \
196 -I$(INCLUDE_DIR)/bits$(BITSIZE) \
198 -I$(LINUX_INCLUDE_DIR)
200 LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
203 WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
206 CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
210 ifeq ($(strip $(USE_SELINUX)),true)
211 UDEV_OBJS += udev_selinux.o
212 LIB_OBJS += -lselinux
213 CFLAGS += -DUSE_SELINUX
216 ifeq ($(strip $(V)),false)
224 # config files automatically generated
225 GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf
227 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(GEN_CONFIGS)
228 @extras="$(EXTRAS)" ; for target in $$extras ; do \
230 $(MAKE) prefix=$(prefix) \
233 KERNEL_DIR="$(KERNEL_DIR)" \
238 $(ARCH_LIB_OBJS) : $(CRT0)
241 @if [ ! -r klibc/linux ]; then \
242 ln -f -s $(KERNEL_DIR) klibc/linux; \
244 $(MAKE) -C klibc SUBDIRS=klibc TESTS=
248 $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
249 $(QUIET) $(RANLIB) $@
251 libsysfs/sysfs.a: $(SYSFS_OBJS)
253 $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
254 $(QUIET) $(RANLIB) $@
256 # header files automatically generated
257 GEN_HEADERS = udev_version.h
260 @echo "Building ccdv"
261 @$(HOSTCC) -O1 ccdv.c -o ccdv
263 # Rules on how to create the generated header files
265 @echo "Creating udev_version.h"
266 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
267 @echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
268 @echo \#define UDEV_DB \"$(udevdb)\" >> $@
269 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
270 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
271 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
272 @echo \#define UDEV_LOG_DEFAULT \"yes\" >> $@
273 @echo \#define UDEV_BIN \"$(DESTDIR)$(sbindir)/udev\" >> $@
274 @echo \#define UDEVD_BIN \"$(DESTDIR)$(sbindir)/udevd\" >> $@
276 # Rules on how to create the generated config files
277 $(LOCAL_CFG_DIR)/udev.conf:
278 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
280 GEN_MANPAGES = udev.8
281 GEN_MANPAGESIN = udev.8.in
282 # Rules on how to create the man pages
283 $(GEN_MANPAGES): $(GEN_MANPAGESIN)
284 sed -e "s:@udevdir@:$(udevdir):" < $@.in > $@
286 $(UDEV_OBJS): $(GEN_HEADERS) $(HOST_PROGS)
287 $(SYSFS_OBJS): $(HOST_PROGS)
288 $(OBJS): $(GEN_HEADERS) $(HOST_PROGS)
289 $(ROOT).o: $(GEN_HEADERS) $(HOST_PROGS)
290 $(TESTER).o: $(GEN_HEADERS) $(HOST_PROGS)
291 $(INFO).o: $(GEN_HEADERS) $(HOST_PROGS)
292 $(DAEMON).o: $(GEN_HEADERS) $(HOST_PROGS)
293 $(SENDER).o: $(GEN_HEADERS) $(HOST_PROGS)
294 $(STARTER).o: $(GEN_HEADERS) $(HOST_PROGS)
296 $(ROOT): $(LIBC) $(ROOT).o $(OBJS) $(HEADERS) $(GEN_MANPAGES)
297 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(ROOT).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
298 $(QUIET) $(STRIPCMD) $@
300 $(TESTER): $(LIBC) $(TESTER).o $(OBJS) $(HEADERS)
301 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(TESTER).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
302 $(QUIET) $(STRIPCMD) $@
304 $(INFO): $(LIBC) $(INFO).o $(OBJS) $(HEADERS)
305 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(INFO).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
306 $(QUIET) $(STRIPCMD) $@
308 $(DAEMON): $(LIBC) $(DAEMON).o $(OBJS) udevd.h
309 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(DAEMON).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
310 $(QUIET) $(STRIPCMD) $@
312 $(SENDER): $(LIBC) $(SENDER).o $(OBJS) udevd.h
313 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(SENDER).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
314 $(QUIET) $(STRIPCMD) $@
317 $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
321 -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
323 -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) $(SENDER) $(TESTER)
325 $(MAKE) -C klibc SUBDIRS=klibc clean
326 @extras="$(EXTRAS)" ; for target in $$extras ; do \
328 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
333 $(MAKE) -C klibc SUBDIRS=klibc spotless
336 DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v -e CVS -e "\.tar\.gz" -e "\/\." -e releases -e BitKeeper -e SCCS -e test/sys | sort )
337 DISTDIR := $(RELEASE_NAME)
343 bk export -w $(DISTDIR)
344 tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
346 @echo "$(RELEASE_NAME).tar.gz created"
349 small_release: $(DISTFILES) spotless
353 @-chmod 777 $(DISTDIR)
354 @for file in $(DISTFILES); do \
355 if test -d $$file; then \
356 mkdir $(DISTDIR)/$$file; \
358 cp -p $$file $(DISTDIR)/$$file; \
361 @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
363 @echo "Built $(RELEASE_NAME).tar.gz"
366 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
367 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
368 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
369 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
371 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
372 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
373 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
377 $(INSTALL) -d $(DESTDIR)$(dev_ddir)/default
378 $(INSTALL_PROGRAM) -D etc/dev.d/net/hotplug.dev $(DESTDIR)$(dev_ddir)/net/hotplug.dev
381 - rm $(dev_ddir)/net/hotplug.dev
382 - rmdir $(dev_ddir)/net
383 - rmdir $(dev_ddir)/default
387 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
388 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
389 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
390 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
391 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
392 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
395 - rm $(mandir)/man8/udev.8
396 - rm $(mandir)/man8/udevinfo.8
397 - rm $(mandir)/man8/udevtest.8
398 - rm $(mandir)/man8/udevstart.8
399 - rm $(mandir)/man8/udevd.8
400 - rm $(mandir)/man8/udevsend.8
402 install: install-config install-man install-dev.d all
403 $(INSTALL) -d $(DESTDIR)$(udevdir)
404 $(INSTALL) -d $(DESTDIR)$(hotplugdir)
405 $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
406 $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
407 $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
408 $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
409 $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
410 - ln -f -s $(sbindir)/udev $(DESTDIR)$(sbindir)/$(STARTER)
411 - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/10-udev.hotplug
416 @extras="$(EXTRAS)" ; for target in $$extras ; do \
418 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
422 uninstall: uninstall-man uninstall-dev.d
423 - rm $(hotplugdir)/10-udev.hotplug
424 - rm $(configdir)/rules.d/50-udev.rules
425 - rm $(configdir)/udev.conf
426 - rmdir $(configdir)/rules.d
428 - rm $(sbindir)/$(ROOT)
429 - rm $(sbindir)/$(DAEMON)
430 - rm $(sbindir)/$(SENDER)
431 - rm $(sbindir)/$(STARTER)
432 - rm $(usrbindir)/$(INFO)
433 - rm $(usrbindir)/$(TESTER)
434 - rmdir $(hotplugdir)
438 @extras="$(EXTRAS)" ; for target in $$extras ; do \
440 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
445 @ cd test && ./udev-test.pl