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
22 # set this to make use of syslog
25 # compile-in development debug messages
26 # (export UDEV_LOG="debug" or set udev_log="debug" in udev.conf
27 # to print the debug messages to syslog)
30 # include Security-Enhanced Linux support
33 # comile with klibc instead of glibc
36 # set this to create statically linked binaries
39 # to build any of the extras programs pass:
40 # make EXTRAS="extras/<extra1> extras/<extra2>"
43 # make the build silent. Set this to something else to make it noisy again.
97 libsysfs/sysfs_class.o \
98 libsysfs/sysfs_device.o \
99 libsysfs/sysfs_dir.o \
100 libsysfs/sysfs_driver.o \
101 libsysfs/sysfs_utils.o \
103 LIBSYSFS = libsysfs/libsysfs.a
105 # config files automatically generated
107 $(LOCAL_CFG_DIR)/udev.conf
112 # override this to make udev look in a different location for it's config files
114 exec_prefix = ${prefix}
115 etcdir = ${prefix}/etc
116 sbindir = ${exec_prefix}/sbin
117 usrbindir = ${exec_prefix}/usr/bin
118 usrsbindir = ${exec_prefix}/usr/sbin
119 mandir = ${prefix}/usr/share/man
120 configdir = ${etcdir}/udev
122 udevdb = ${udevdir}/.udevdb
123 LOCAL_CFG_DIR = etc/udev
124 KERNEL_DIR = /lib/modules/${shell uname -r}/build
127 RELEASE_NAME = udev-$(VERSION)
129 INSTALL = /usr/bin/install -c
130 INSTALL_PROGRAM = ${INSTALL}
131 INSTALL_DATA = ${INSTALL} -m 644
132 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
135 # If you are running a cross compiler, you may want to set this
136 # to something more interesting, like "arm-linux-". If you want
137 # to compile vs uClibc, that can be done here as well.
138 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
142 STRIP = $(CROSS)strip
143 RANLIB = $(CROSS)ranlib
146 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
148 # code taken from uClibc to determine the current arch
149 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
150 -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
152 # determine the gcc include dir
153 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
155 # determine the libgcc.a filename
156 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
158 # check if compiler option is supported
159 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;}
161 CFLAGS += -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith \
162 -Wstrict-prototypes -Wsign-compare
163 CFLAGS += $(call cc-supports, -Wdeclaration-after-statement, )
165 CFLAGS += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
167 # use '-Os' optimization if available, else use -O2
168 OPTFLAGS := $(call cc-supports, -Os, -O2)
170 # include our local copy of libsysfs
171 CFLAGS += -I$(PWD)/libsysfs/sysfs \
174 ifeq ($(strip $(USE_LOG)),true)
178 # if DEBUG is enabled, then we do not strip or optimize
179 ifeq ($(strip $(DEBUG)),true)
180 CFLAGS += -O1 -g -DDEBUG
182 STRIPCMD = /bin/true -Since_we_are_debugging
184 CFLAGS += $(OPTFLAGS) -fomit-frame-pointer
186 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
189 # if our own version of klibc is used, we need to build it
190 ifeq ($(strip $(USE_KLIBC)),true)
191 KLIBC_INSTALL = $(PWD)/klibc/.install
192 KLCC = $(KLIBC_INSTALL)/bin/$(CROSS)klcc
196 CFLAGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
199 ifeq ($(strip $(USE_SELINUX)),true)
200 UDEV_OBJS += udev_selinux.o
201 LIB_OBJS += -lselinux
202 CFLAGS += -DUSE_SELINUX
205 ifeq ($(strip $(USE_STATIC)),true)
206 CFLAGS += -DUSE_STATIC
210 ifeq ($(strip $(V)),false)
218 all: $(KLCC) $(PROGRAMS) $(MAN_PAGES)
219 @extras="$(EXTRAS)"; for target in $$extras; do \
221 $(MAKE) prefix=$(prefix) \
223 LIBUDEV="$(PWD)/$(LIBUDEV)" \
224 LIBSYSFS="$(PWD)/$(LIBSYSFS)" \
225 KERNEL_DIR="$(KERNEL_DIR)" \
231 # clear implicit rules
236 $(QUIET) $(CC) -c $(CFLAGS) $< -o $@
238 # "Static Pattern Rule" to build all programs
239 $(PROGRAMS): %: $(HOST_PROGS) $(KLCC) $(HEADERS) $(GEN_HEADERS) $(LIBSYSFS) $(LIBUDEV) %.o
240 $(QUIET) $(LD) $(LDFLAGS) $@.o -o $@ $(LIBUDEV) $(LIBSYSFS) $(LIB_OBJS)
241 $(QUIET) $(STRIPCMD) $@
243 # our own copy of klibc, it is not used if KLCC is given
245 $(MAKE) -C klibc KRNLSRC=$(KERNEL_DIR) SUBDIRS=klibc TESTS= \
246 SHLIBDIR=$(KLIBC_INSTALL)/lib \
247 INSTALLDIR=$(KLIBC_INSTALL) \
248 bindir=$(KLIBC_INSTALL)/bin \
249 mandir=$(KLIBC_INSTALL)/man all install
250 -find $(KLIBC_INSTALL)/include -name SCCS -print| xargs rm -rf
251 .NOTPARALLEL: $(KLCC)
253 $(UDEV_OBJS): $(KLCC)
254 $(LIBUDEV): $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
256 $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
257 $(QUIET) $(RANLIB) $@
259 $(SYSFS_OBJS): $(KLCC)
260 $(LIBSYSFS): $(HOST_PROGS) $(SYSFS_OBJS)
262 $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
263 $(QUIET) $(RANLIB) $@
265 # generate config files
267 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $@.in > $@
269 # generate config header file
271 @echo "Creating udev_version.h"
272 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
273 @echo \#define UDEV_ROOT \"$(udevdir)\" >> $@
274 @echo \#define UDEV_DB \"$(udevdb)\" >> $@
275 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
276 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
277 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
278 @echo \#define UDEV_BIN \"$(sbindir)/udev\" >> $@
279 @echo \#define UDEVD_BIN \"$(sbindir)/udevd\" >> $@
287 @$(HOSTCC) -O1 ccdv.c -o ccdv
291 -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print | xargs rm -f
292 -rm -f core $(PROGRAMS) $(GEN_HEADERS) $(GEN_CONFIGS)
293 $(MAKE) -C klibc SUBDIRS=klibc clean
294 @extras="$(EXTRAS)"; for target in $$extras; do \
296 $(MAKE) prefix=$(prefix) -C $$target $@; \
301 $(MAKE) -C klibc SUBDIRS=klibc spotless
302 rm -rf klibc/.install
306 git-tar-tree HEAD $(RELEASE_NAME) | gzip -9v > $(RELEASE_NAME).tar.gz
307 @echo "$(RELEASE_NAME).tar.gz created"
310 install-config: $(GEN_CONFIGS)
311 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
312 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
313 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
314 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
316 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
318 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
321 .PHONY: install-config
324 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
325 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
326 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
327 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
328 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
329 $(INSTALL_DATA) -D udevsend.8 $(DESTDIR)$(mandir)/man8/udevsend.8
330 $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
331 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
335 - rm $(mandir)/man8/udev.8
336 - rm $(mandir)/man8/udevinfo.8
337 - rm $(mandir)/man8/udevtest.8
338 - rm $(mandir)/man8/udevstart.8
339 - rm $(mandir)/man8/udevd.8
340 - rm $(mandir)/man8/udevmonitor.8
341 - rm $(mandir)/man8/udevsend.8
342 - rm $(mandir)/man8/udevcontrol.8
343 .PHONY: uninstall-man
345 install: install-config install-man all
346 $(INSTALL) -d $(DESTDIR)$(udevdir)
347 $(INSTALL_PROGRAM) -D udev $(DESTDIR)$(sbindir)/udev
348 $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
349 $(INSTALL_PROGRAM) -D udevsend $(DESTDIR)$(sbindir)/udevsend
350 $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
351 $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
352 $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
353 $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
354 $(INSTALL_PROGRAM) -D udevstart $(DESTDIR)$(sbindir)/udevstart
358 - $(sbindir)/udevd --daemon
360 @extras="$(EXTRAS)"; for target in $$extras; do \
362 $(MAKE) prefix=$(prefix) -C $$target $@; \
366 uninstall: uninstall-man
367 - rm $(configdir)/rules.d/50-udev.rules
368 - rm $(configdir)/udev.conf
369 - rmdir $(configdir)/rules.d
372 - rm $(sbindir)/udevd
373 - rm $(sbindir)/udevsend
374 - rm $(sbindir)/udevinitsend
375 - rm $(sbindir)/udeveventrecoreder
376 - rm $(sbindir)/udevcontrol
377 - rm $(sbindir)/udevstart
378 - rm $(usrsbindir)/udevmonitor
379 - rm $(usrbindir)/udevinfo
380 - rm $(usrbindir)/udevtest
384 @extras="$(EXTRAS)"; for target in $$extras; do \
386 $(MAKE) prefix=$(prefix) -C $$target $@; \
388 .PHONY: uninstall-man
391 @ cd test && ./udev-test.pl
392 @ cd test && ./udevstart-test.pl