3 # Copyright (C) 2003 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.
37 INSTALL_DIR = /usr/local/bin
38 RELEASE_NAME = $(ROOT)-$(VERSION)
39 LOCAL_CFG_DIR = etc/udev
40 HOTPLUG_EXEC = $(ROOT)
44 KERNEL_DIR = /lib/modules/${shell uname -r}/build
46 # override this to make udev look in a different location for it's config files
48 exec_prefix = ${prefix}
49 etcdir = ${prefix}/etc
50 sbindir = ${exec_prefix}/sbin
51 usrbindir = ${exec_prefix}/usr/bin
52 mandir = ${prefix}/usr/share/man
53 hotplugdir = ${etcdir}/hotplug.d/default
54 configdir = ${etcdir}/udev/
55 initdir = ${etcdir}/init.d/
56 dev_ddir = ${etcdir}/dev.d/
59 INSTALL = /usr/bin/install -c
60 INSTALL_PROGRAM = ${INSTALL}
61 INSTALL_DATA = ${INSTALL} -m 644
62 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
64 # To build any of the extras programs, run with:
65 # make EXTRAS="extras/a extras/b"
68 # place to put our device nodes
69 udevdir = ${prefix}/udev
71 # Comment out this line to build with something other
72 # than the local version of klibc
75 # set up PWD so that older versions of make will work with our build.
78 # If you are running a cross compiler, you may want to set this
79 # to something more interesting, like "arm-linux-". If you want
80 # to compile vs uClibc, that can be done here as well.
81 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
86 RANLIB = $(CROSS)ranlib
88 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0
90 # code taken from uClibc to determine the current arch
91 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
92 -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
94 # code taken from uClibc to determine the gcc include dir
95 GCCINCDIR := ${shell $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
97 # code taken from uClibc to determine the libgcc.a filename
98 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
100 # use '-Os' optimization if available, else use -O2
101 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
102 then echo "-Os"; else echo "-O2" ; fi}
104 # add -Wredundant-decls when libsysfs gets cleaned up
107 # Some nice architecture specific optimizations
108 ifeq ($(strip $(TARGET_ARCH)),arm)
109 OPTIMIZATION+=-fstrict-aliasing
111 ifeq ($(strip $(TARGET_ARCH)),i386)
112 OPTIMIZATION+=-march=i386
113 OPTIMIZATION += ${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \
114 /dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi}
115 OPTIMIZATION += ${shell if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \
116 /dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi}
122 ifeq ($(strip $(USE_LOG)),true)
126 # if DEBUG is enabled, then we do not strip or optimize
127 ifeq ($(strip $(DEBUG)),true)
128 CFLAGS += -O1 -g -DDEBUG -D_GNU_SOURCE
129 LDFLAGS += -Wl,-warn-common
130 STRIPCMD = /bin/true -Since_we_are_debugging
132 CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
133 LDFLAGS += -s -Wl,-warn-common
134 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
137 # If we are using our version of klibc, then we need to build, link it, and then
138 # link udev against it statically.
139 # Otherwise, use glibc and link dynamically.
140 ifeq ($(strip $(USE_KLIBC)),true)
141 KLIBC_BASE = $(PWD)/klibc
142 KLIBC_DIR = $(KLIBC_BASE)/klibc
143 INCLUDE_DIR := $(KLIBC_DIR)/include
144 LINUX_INCLUDE_DIR := $(KERNEL_DIR)/include
145 # LINUX_INCLUDE_DIR := $(KLIBC_BASE)/linux/include
146 include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
147 # arch specific objects
152 CRT0 = $(KLIBC_DIR)/crt0.o
153 LIBC = $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
154 CFLAGS += $(WARNINGS) -nostdinc \
156 -D__KLIBC__ -fno-builtin-printf \
158 -I$(KLIBC_DIR)/arch/$(ARCH)/include \
159 -I$(INCLUDE_DIR)/bits$(BITSIZE) \
161 -I$(LINUX_INCLUDE_DIR)
163 LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
165 WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
168 CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
173 CFLAGS += -I$(PWD)/libsysfs
175 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(STARTER)
176 @extras="$(EXTRAS)" ; for target in $$extras ; do \
178 $(MAKE) prefix=$(prefix) \
181 KERNEL_DIR="$(KERNEL_DIR)" \
185 $(ARCH_LIB_OBJS) : $(CRT0)
188 $(MAKE) -C klibc KERNEL_DIR=$(KERNEL_DIR)
193 SYSFS = $(PWD)/libsysfs/sysfs_bus.o \
194 $(PWD)/libsysfs/sysfs_class.o \
195 $(PWD)/libsysfs/sysfs_device.o \
196 $(PWD)/libsysfs/sysfs_dir.o \
197 $(PWD)/libsysfs/sysfs_driver.o \
198 $(PWD)/libsysfs/sysfs_utils.o \
199 $(PWD)/libsysfs/dlist.o
221 ifeq ($(strip $(USE_KLIBC)),true)
222 OBJS += klibc_fixups.o
225 # header files automatically generated
226 GEN_HEADERS = udev_version.h
228 # Rules on how to create the generated header files
230 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
231 @echo \#define UDEV_ROOT \"$(udevdir)/\" >> $@
232 @echo \#define UDEV_DB \"$(udevdir)/\.udev.tdb\" >> $@
233 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
234 @echo \#define UDEV_CONFIG_FILE \"$(configdir)\udev.conf\" >> $@
235 @echo \#define UDEV_RULES_FILE \"$(configdir)\udev.rules\" >> $@
236 @echo \#define UDEV_PERMISSION_FILE \"$(configdir)\udev.permissions\" >> $@
237 @echo \#define UDEV_LOG_DEFAULT \"yes\" >> $@
238 @echo \#define UDEV_BIN \"$(DESTDIR)$(sbindir)/udev\" >> $@
239 @echo \#define UDEVD_BIN \"$(DESTDIR)$(sbindir)/udevd\" >> $@
241 # config files automatically generated
242 GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf
244 # Rules on how to create the generated config files
245 $(LOCAL_CFG_DIR)/udev.conf:
246 sed -e "s:@udevdir@:$(udevdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
249 $(OBJS): $(GEN_HEADERS)
250 $(ROOT).o: $(GEN_HEADERS)
251 $(TESTER).o: $(GEN_HEADERS)
252 $(INFO).o: $(GEN_HEADERS)
253 $(DAEMON).o: $(GEN_HEADERS)
254 $(SENDER).o: $(GEN_HEADERS)
255 $(STARTER).o: $(GEN_HEADERS)
257 $(ROOT): $(ROOT).o $(OBJS) $(HEADERS) $(LIBC)
258 $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
261 $(TESTER): $(TESTER).o $(OBJS) $(HEADERS) $(LIBC)
262 $(LD) $(LDFLAGS) -o $@ $(CRT0) udevtest.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
265 $(INFO): $(INFO).o $(OBJS) $(HEADERS) $(LIBC)
266 $(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_lib.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
269 $(DAEMON): $(DAEMON).o udevd.h $(LIBC)
270 $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
273 $(SENDER): $(SENDER).o udevd.h $(LIBC)
274 $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o udev_lib.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
277 $(STARTER): $(STARTER).o $(HEADERS) $(LIBC)
278 $(LD) $(LDFLAGS) -o $@ $(CRT0) udevstart.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
281 $(RULER): $(RULER).o $(OBJS) $(HEADERS) $(LIBC)
282 $(LD) $(LDFLAGS) -o $@ $(CRT0) udevruler.o udev_lib.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS) -lnewt
286 -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
288 -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(INFO) $(DAEMON) $(SENDER) $(TESTER) $(STARTER) $(RULER)
289 $(MAKE) -C klibc clean
290 @extras="$(EXTRAS)" ; for target in $$extras ; do \
292 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
297 $(MAKE) -C klibc spotless
299 DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v -e CVS -e "\.tar\.gz$" -e "\/\." -e releases -e BitKeeper -e SCCS -e "\.tdb$" -e test/sys | sort )
300 DISTDIR := $(RELEASE_NAME)
307 tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
309 @echo "$(RELEASE_NAME).tar.gz created"
312 small_release: $(DISTFILES) clean
316 @-chmod 777 $(DISTDIR)
317 @for file in $(DISTFILES); do \
318 if test -d $$file; then \
319 mkdir $(DISTDIR)/$$file; \
321 cp -p $$file $(DISTDIR)/$$file; \
324 @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
326 @echo "Built $(RELEASE_NAME).tar.gz"
329 install-initscript: etc/init.d/udev etc/init.d/udev.debian etc/init.d/udev.init.LSB
330 @if [ -f /etc/redhat-release ]; then \
331 $(INSTALL_DATA) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev; \
332 elif [ -f /etc/SuSE-release ]; then \
333 $(INSTALL_DATA) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev; \
334 elif [ -f /etc/debian_version ]; then \
335 $(INSTALL_DATA) -D etc/init.d/udev.debian $(DESTDIR)$(initdir)/udev; \
338 install-config: $(GEN_CONFIGS)
339 $(INSTALL) -d $(DESTDIR)$(configdir)
340 @if [ ! -r $(DESTDIR)$(configdir)udev.conf ]; then \
341 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
342 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
344 @if [ ! -r $(DESTDIR)$(configdir)udev.rules ]; then \
345 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
346 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
348 @if [ ! -r $(DESTDIR)$(configdir)udev.permissions ]; then \
349 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
350 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
354 $(INSTALL) -d $(DESTDIR)$(dev_ddir)
355 $(INSTALL) -d $(DESTDIR)$(dev_ddir)default/
357 install: install-initscript install-config install-dev.d all
358 $(INSTALL) -d $(DESTDIR)$(udevdir)
359 $(INSTALL) -d $(DESTDIR)$(hotplugdir)
360 $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
361 $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
362 $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
363 $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
364 $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
365 $(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
366 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
367 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
368 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
369 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
370 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
371 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
372 - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/$(ROOT).hotplug
375 - rm -f $(udevdir)/.udev.tdb
377 @extras="$(EXTRAS)" ; for target in $$extras ; do \
379 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
384 - rm $(hotplugdir)/udev.hotplug
385 - rm $(configdir)/udev.permissions
386 - rm $(configdir)/udev.rules
387 - rm $(configdir)/udev.conf
389 - rm $(mandir)/man8/udev.8
390 - rm $(mandir)/man8/udevinfo.8
391 - rm $(mandir)/man8/udevtest.8
392 - rm $(mandir)/man8/udevstart.8
393 - rm $(mandir)/man8/udevd.8
394 - rm $(mandir)/man8/udevsend.8
395 - rm $(sbindir)/$(ROOT)
396 - rm $(sbindir)/$(DAEMON)
397 - rm $(sbindir)/$(SENDER)
398 - rm $(usrbindir)/$(INFO)
399 - rmdir $(hotplugdir)
401 - rmdir $(dev_ddir)default
403 - rm $(udevdir)/.udev.tdb
405 @extras="$(EXTRAS)" ; for target in $$extras ; do \
407 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \