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.
40 INSTALL_DIR
= /usr
/local
/bin
41 RELEASE_NAME
= $(ROOT
)-$(VERSION
)
42 LOCAL_CFG_DIR
= etc
/udev
43 HOTPLUG_EXEC
= $(ROOT
)
47 KERNEL_DIR
= /lib
/modules
/${shell uname
-r
}/build
49 # override this to make udev look in a different location for it's config files
51 exec_prefix = ${prefix}
52 etcdir
= ${prefix}/etc
53 sbindir
= ${exec_prefix}/sbin
54 usrbindir
= ${exec_prefix}/usr
/bin
55 mandir = ${prefix}/usr
/share
/man
56 hotplugdir
= ${etcdir}/hotplug.d
/default
57 configdir
= ${etcdir}/udev
58 initdir
= ${etcdir}/init.d
59 dev_ddir
= ${etcdir}/dev.d
62 INSTALL
= /usr
/bin
/install -c
63 INSTALL_PROGRAM
= ${INSTALL}
64 INSTALL_DATA
= ${INSTALL} -m
644
65 INSTALL_SCRIPT
= ${INSTALL_PROGRAM}
67 # To build any of the extras programs, run with:
68 # make EXTRAS="extras/a extras/b"
71 # place to put our device nodes
72 udevdir
= ${prefix}/udev
74 # Comment out this line to build with something other
75 # than the local version of klibc
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
91 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0
93 # code taken from uClibc to determine the current arch
94 ARCH
:= ${shell $(CC
) -dumpmachine | sed
-e s
'/-.*//' -e
's/i.86/i386/' -e
's/sparc.*/sparc/' \
95 -e
's/arm.*/arm/g' -e
's/m68k.*/m68k/' -e
's/powerpc/ppc/g'}
97 # code taken from uClibc to determine the gcc include dir
98 GCCINCDIR
:= ${shell LC_ALL
=C
$(CC
) -print-search-dirs | sed
-ne
"s/install: \(.*\)/\1include/gp"}
100 # code taken from uClibc to determine the libgcc.a filename
101 GCC_LIB
:= $(shell $(CC
) -print-libgcc-file-name
)
103 # use '-Os' optimization if available, else use -O2
104 OPTIMIZATION
:= ${shell if
$(CC
) -Os
-S
-o
/dev
/null
-xc
/dev
/null
>/dev
/null
2>&1; \
105 then echo
"-Os"; else echo
"-O2" ; fi
}
107 # add -Wredundant-decls when libsysfs gets cleaned up
110 # Some nice architecture specific optimizations
111 ifeq ($(strip $(TARGET_ARCH
)),arm
)
112 OPTIMIZATION
+=-fstrict-aliasing
114 ifeq ($(strip $(TARGET_ARCH
)),i386
)
115 OPTIMIZATION
+=-march
=i386
116 OPTIMIZATION
+= ${shell if
$(CC
) -mpreferred-stack-boundary
=2 -S
-o
/dev
/null
-xc \
117 /dev
/null
>/dev
/null
2>&1; then echo
"-mpreferred-stack-boundary=2"; fi
}
118 OPTIMIZATION
+= ${shell if
$(CC
) -malign-functions
=0 -malign-jumps
=0 -S
-o
/dev
/null
-xc \
119 /dev
/null
>/dev
/null
2>&1; then echo
"-malign-functions=0 -malign-jumps=0"; fi
}
120 CFLAGS
+=-pipe
-Dasmlinkage
=__attribute__
((regparm
(0)))
122 CFLAGS
+=-pipe
-Dasmlinkage
=
125 ifeq ($(strip $(USE_LOG
)),true
)
129 # if DEBUG is enabled, then we do not strip or optimize
130 ifeq ($(strip $(DEBUG
)),true
)
131 CFLAGS
+= -O1
-g
-DDEBUG
-D_GNU_SOURCE
132 LDFLAGS
+= -Wl
,-warn-common
133 STRIPCMD
= /bin
/true
-Since_we_are_debugging
135 CFLAGS
+= $(OPTIMIZATION
) -fomit-frame-pointer
-D_GNU_SOURCE
136 LDFLAGS
+= -s
-Wl
,-warn-common
137 STRIPCMD
= $(STRIP
) -s
--remove-section
=.note
--remove-section
=.comment
140 # If we are using our version of klibc, then we need to build, link it, and then
141 # link udev against it statically.
142 # Otherwise, use glibc and link dynamically.
143 ifeq ($(strip $(USE_KLIBC
)),true
)
144 KLIBC_BASE
= $(PWD
)/klibc
145 KLIBC_DIR
= $(KLIBC_BASE
)/klibc
146 INCLUDE_DIR
:= $(KLIBC_BASE
)/include
147 LINUX_INCLUDE_DIR
:= $(KERNEL_DIR
)/include
148 include $(KLIBC_DIR
)/arch
/$(ARCH
)/MCONFIG
149 # arch specific objects
154 CRT0
= $(KLIBC_DIR
)/crt0.o
155 LIBC
= $(ARCH_LIB_OBJS
) $(LIB_OBJS
) $(CRT0
)
156 CFLAGS
+= $(WARNINGS
) -nostdinc \
158 -D__KLIBC__
-fno-builtin-printf \
160 -I
$(INCLUDE_DIR
)/arch
/$(ARCH
) \
161 -I
$(INCLUDE_DIR
)/bits
$(BITSIZE
) \
163 -I
$(LINUX_INCLUDE_DIR
)
165 LDFLAGS
= --static
--nostdlib
-nostartfiles
-nodefaultlibs
167 WARNINGS
+= -Wshadow
-Wstrict-prototypes
-Wmissing-prototypes
-Wmissing-declarations
170 CFLAGS
+= $(WARNINGS
) -I
$(GCCINCDIR
)
175 ifeq ($(strip $(USE_SELINUX
)),true
)
176 CFLAGS
+= -DUSE_SELINUX
177 LIB_OBJS
+= -lselinux
180 CFLAGS
+= -I
$(PWD
)/libsysfs
182 # config files automatically generated
183 GEN_CONFIGS
= $(LOCAL_CFG_DIR
)/udev.conf
185 all: $(ROOT
) $(SENDER
) $(DAEMON
) $(INFO
) $(TESTER
) $(WAIT
) $(GEN_CONFIGS
)
186 @extras
="$(EXTRAS)" ; for target in
$$extras ; do \
188 $(MAKE
) prefix=$(prefix) \
191 KERNEL_DIR
="$(KERNEL_DIR)" \
195 $(ARCH_LIB_OBJS
) : $(CRT0
)
198 @if
[ ! -r klibc
/linux
]; then \
199 ln
-f
-s
$(KERNEL_DIR
) klibc
/linux
; \
201 $(MAKE
) -C klibc SUBDIRS
=klibc
206 SYSFS
= $(PWD
)/libsysfs
/sysfs_bus.o \
207 $(PWD
)/libsysfs
/sysfs_class.o \
208 $(PWD
)/libsysfs
/sysfs_device.o \
209 $(PWD
)/libsysfs
/sysfs_dir.o \
210 $(PWD
)/libsysfs
/sysfs_driver.o \
211 $(PWD
)/libsysfs
/sysfs_utils.o \
212 $(PWD
)/libsysfs
/dlist.o
235 ifeq ($(strip $(USE_KLIBC
)),true
)
236 OBJS
+= klibc_fixups.o
237 KLIBC_FIXUP
= klibc_fixups.o
240 # header files automatically generated
241 GEN_HEADERS
= udev_version.h
243 # Rules on how to create the generated header files
245 @echo \
#define UDEV_VERSION \"$(VERSION)\" > $@
246 @echo \
#define UDEV_ROOT \"$(udevdir)/\" >> $@
247 @echo \
#define UDEV_DB \"$(udevdir)/.udev.tdb\" >> $@
248 @echo \
#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
249 @echo \
#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
250 @echo \
#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
251 @echo \
#define UDEV_PERMISSION_FILE \"$(configdir)/permissions.d\" >> $@
252 @echo \
#define UDEV_LOG_DEFAULT \"yes\" >> $@
253 @echo \
#define UDEV_BIN \"$(DESTDIR)$(sbindir)/udev\" >> $@
254 @echo \
#define UDEVD_BIN \"$(DESTDIR)$(sbindir)/udevd\" >> $@
256 # Rules on how to create the generated config files
257 $(LOCAL_CFG_DIR
)/udev.conf
:
258 sed
-e
"s:@udevdir@:$(udevdir):" -e
"s:@configdir@:$(configdir):" < $(LOCAL_CFG_DIR
)/udev.conf.in
> $@
260 GEN_MANPAGES
= udev
.8
261 GEN_MANPAGESIN
= udev
.8.in
262 # Rules on how to create the man pages
263 $(GEN_MANPAGES
): $(GEN_MANPAGESIN
)
264 sed
-e
"s:@udevdir@:$(udevdir):" < $@.in
> $@
267 $(OBJS
): $(GEN_HEADERS
)
268 $(ROOT
).o
: $(GEN_HEADERS
)
269 $(TESTER
).o
: $(GEN_HEADERS
)
270 $(INFO
).o
: $(GEN_HEADERS
)
271 $(DAEMON
).o
: $(GEN_HEADERS
)
272 $(SENDER
).o
: $(GEN_HEADERS
)
273 $(STARTER
).o
: $(GEN_HEADERS
)
275 $(ROOT
): $(LIBC
) $(ROOT
).o
$(STARTER
).o
$(OBJS
) $(HEADERS
) $(GEN_MANPAGES
)
276 $(LD
) $(LDFLAGS
) -o
$@
$(CRT0
) udev.o udevstart.o
$(OBJS
) $(LIB_OBJS
) $(ARCH_LIB_OBJS
)
279 $(TESTER
): $(LIBC
) $(TESTER
).o
$(OBJS
) $(HEADERS
)
280 $(LD
) $(LDFLAGS
) -o
$@
$(CRT0
) udevtest.o
$(OBJS
) $(LIB_OBJS
) $(ARCH_LIB_OBJS
)
283 $(INFO
): $(LIBC
) $(INFO
).o
$(OBJS
) $(HEADERS
)
284 $(LD
) $(LDFLAGS
) -o
$@
$(CRT0
) udevinfo.o udev_lib.o udev_config.o udevdb.o
$(SYSFS
) $(TDB
) $(LIB_OBJS
) $(ARCH_LIB_OBJS
)
287 $(DAEMON
): $(LIBC
) $(DAEMON
).o
$(OBJS
) udevd.h
288 $(LD
) $(LDFLAGS
) -o
$@
$(CRT0
) udevd.o udev_lib.o
$(KLIBC_FIXUP
) $(LIB_OBJS
) $(ARCH_LIB_OBJS
)
291 $(SENDER
): $(LIBC
) $(SENDER
).o
$(OBJS
) udevd.h
292 $(LD
) $(LDFLAGS
) -o
$@
$(CRT0
) udevsend.o udev_lib.o
$(LIB_OBJS
) $(ARCH_LIB_OBJS
)
295 $(RULER
): $(LIBC
) $(RULER
).o
$(OBJS
) $(HEADERS
)
296 $(LD
) $(LDFLAGS
) -o
$@
$(CRT0
) udevruler.o udev_lib.o udev_config.o udevdb.o
$(SYSFS
) $(TDB
) $(LIB_OBJS
) $(ARCH_LIB_OBJS
) -lnewt
299 $(WAIT
): $(WAIT
).o
$(OBJS
) $(HEADERS
) $(LIBC
)
300 $(LD
) $(LDFLAGS
) -o
$@
$(CRT0
) $(WAIT
).o
$(SYSFS
) $(LIB_OBJS
) $(ARCH_LIB_OBJS
)
304 -find . \
( -not
-type d \
) -and \
( -name
'*~' -o
-name
'*.[oas]' \
) -type f
-print \
306 -rm -f core
$(ROOT
) $(GEN_HEADERS
) $(GEN_CONFIGS
) $(GEN_MANPAGES
) $(INFO
) $(DAEMON
) $(SENDER
) $(TESTER
) $(RULER
) $(WAIT
)
307 $(MAKE
) -C klibc
clean
308 @extras
="$(EXTRAS)" ; for target in
$$extras ; do \
310 $(MAKE
) prefix=$(prefix) LD
="$(LD)" SYSFS
="$(SYSFS)" \
315 $(MAKE
) -C klibc spotless
318 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 )
319 DISTDIR
:= $(RELEASE_NAME
)
326 tar -c
$(DISTDIR
) | gzip
-9 > $(RELEASE_NAME
).
tar.gz
328 @echo
"$(RELEASE_NAME).tar.gz created"
331 small_release
: $(DISTFILES
) clean
335 @
-chmod
777 $(DISTDIR
)
336 @for file in
$(DISTFILES
); do \
337 if
test -d
$$file; then \
338 mkdir
$(DISTDIR
)/$$file; \
340 cp
-p
$$file $(DISTDIR
)/$$file; \
343 @
tar -c
$(DISTDIR
) | gzip
-9 > $(RELEASE_NAME
).
tar.gz
345 @echo
"Built $(RELEASE_NAME).tar.gz"
348 install-initscript
: etc
/init.d
/udev etc
/init.d
/udev.debian etc
/init.d
/udev.init.LSB
349 @if
[ -f
/etc
/redhat-release
]; then \
350 $(INSTALL_DATA
) -D etc
/init.d
/udev
$(DESTDIR
)$(initdir
)/udev
; \
351 elif
[ -f
/etc
/SuSE-release
]; then \
352 $(INSTALL_DATA
) -D etc
/init.d
/udev.init.LSB
$(DESTDIR
)$(initdir
)/udev
; \
353 elif
[ -f
/etc
/debian_version
]; then \
354 $(INSTALL_DATA
) -D etc
/init.d
/udev.debian
$(DESTDIR
)$(initdir
)/udev
; \
358 $(INSTALL
) -d
$(DESTDIR
)$(configdir
)/rules.d
359 $(INSTALL
) -d
$(DESTDIR
)$(configdir
)/permissions.d
360 @if
[ ! -r
$(DESTDIR
)$(configdir
)/udev.conf
]; then \
361 echo
$(INSTALL_DATA
) $(LOCAL_CFG_DIR
)/udev.conf
$(DESTDIR
)$(configdir
); \
362 $(INSTALL_DATA
) $(LOCAL_CFG_DIR
)/udev.conf
$(DESTDIR
)$(configdir
); \
364 @if
[ ! -r
$(DESTDIR
)$(configdir
)/rules.d
/50-udev.rules
]; then \
365 echo
$(INSTALL_DATA
) $(LOCAL_CFG_DIR
)/udev.rules
$(DESTDIR
)$(configdir
)/rules.d
/50-udev.rules
; \
366 $(INSTALL_DATA
) $(LOCAL_CFG_DIR
)/udev.rules
$(DESTDIR
)$(configdir
)/rules.d
/50-udev.rules
; \
368 @if
[ ! -r
$(DESTDIR
)$(configdir
)/permissions.d
/50-udev.permissions
]; then \
369 echo
$(INSTALL_DATA
) $(LOCAL_CFG_DIR
)/udev.permissions
$(DESTDIR
)$(configdir
)/permissions.d
/50-udev.permissions
; \
370 $(INSTALL_DATA
) $(LOCAL_CFG_DIR
)/udev.permissions
$(DESTDIR
)$(configdir
)/permissions.d
/50-udev.permissions
; \
374 $(INSTALL
) -d
$(DESTDIR
)$(dev_ddir
)/default
375 $(INSTALL_PROGRAM
) -D etc
/dev.d
/net
/hotplug.dev
$(DESTDIR
)$(dev_ddir
)/net
/hotplug.dev
378 - rm $(dev_ddir
)/net
/hotplug.dev
379 - rmdir
$(dev_ddir
)/net
380 - rmdir
$(dev_ddir
)/default
384 $(INSTALL_DATA
) -D udev
.8 $(DESTDIR
)$(mandir)/man8
/udev
.8
385 $(INSTALL_DATA
) -D udevinfo
.8 $(DESTDIR
)$(mandir)/man8
/udevinfo
.8
386 $(INSTALL_DATA
) -D udevtest
.8 $(DESTDIR
)$(mandir)/man8
/udevtest
.8
387 $(INSTALL_DATA
) -D udevstart
.8 $(DESTDIR
)$(mandir)/man8
/udevstart
.8
388 $(INSTALL_DATA
) -D udevd
.8 $(DESTDIR
)$(mandir)/man8
/udevd
.8
389 - ln
-f
-s udevd
.8 $(DESTDIR
)$(mandir)/man8
/udevsend
.8
392 - rm $(mandir)/man8
/udev
.8
393 - rm $(mandir)/man8
/udevinfo
.8
394 - rm $(mandir)/man8
/udevtest
.8
395 - rm $(mandir)/man8
/udevstart
.8
396 - rm $(mandir)/man8
/udevd
.8
397 - rm $(mandir)/man8
/udevsend
.8
399 install: install-initscript install-config install-man install-dev.d
all
400 $(INSTALL
) -d
$(DESTDIR
)$(udevdir
)
401 $(INSTALL
) -d
$(DESTDIR
)$(hotplugdir
)
402 $(INSTALL_PROGRAM
) -D
$(ROOT
) $(DESTDIR
)$(sbindir
)/$(ROOT
)
403 $(INSTALL_PROGRAM
) -D
$(DAEMON
) $(DESTDIR
)$(sbindir
)/$(DAEMON
)
404 $(INSTALL_PROGRAM
) -D
$(SENDER
) $(DESTDIR
)$(sbindir
)/$(SENDER
)
405 $(INSTALL_PROGRAM
) -D
$(INFO
) $(DESTDIR
)$(usrbindir
)/$(INFO
)
406 $(INSTALL_PROGRAM
) -D
$(TESTER
) $(DESTDIR
)$(usrbindir
)/$(TESTER
)
407 $(INSTALL_PROGRAM
) -D
$(WAIT
) $(DESTDIR
)$(sbindir
)/$(WAIT
)
408 - ln
-f
-s
$(sbindir
)/udev
$(DESTDIR
)$(sbindir
)/$(STARTER
)
409 - ln
-f
-s
$(sbindir
)/$(SENDER
) $(DESTDIR
)$(hotplugdir
)/10-udev.hotplug
410 - ln
-f
-s
$(sbindir
)/$(WAIT
) $(DESTDIR
)$(hotplugdir
)/00-wait_for_sysfs.hotplug
413 - rm -f
$(udevdir
)/.udev.tdb
415 @extras
="$(EXTRAS)" ; for target in
$$extras ; do \
417 $(MAKE
) prefix=$(prefix) LD
="$(LD)" SYSFS
="$(SYSFS)" \
421 uninstall: uninstall-man uninstall-dev.d
422 - rm $(hotplugdir
)/10-udev.hotplug
423 - rm $(hotplugdir
)/00-wait_for_sysfs.hotplug
424 - rm $(configdir
)/rules.d
/50-udev.rules
425 - rm $(configdir
)/permissions.d
/50-udev.permissions
426 - rm $(configdir
)/udev.conf
427 - rmdir
$(configdir
)/rules.d
428 - rmdir
$(configdir
)/permissions.d
431 - rm $(sbindir
)/$(ROOT
)
432 - rm $(sbindir
)/$(DAEMON
)
433 - rm $(sbindir
)/$(SENDER
)
434 - rm $(sbindir
)/$(STARTER
)
435 - rm $(usrbindir
)/$(INFO
)
436 - rm $(usrbindir
)/$(TESTER
)
437 - rm $(usrbindir
)/$(WAIT
)
438 - rmdir
$(hotplugdir
)
439 - rm $(udevdir
)/.udev.tdb
441 @extras
="$(EXTRAS)" ; for target in
$$extras ; do \
443 $(MAKE
) prefix=$(prefix) LD
="$(LD)" SYSFS
="$(SYSFS)" \