chiark / gitweb /
[PATCH] udevd - cleanup and better timeout handling
[elogind.git] / Makefile
1 # Makefile for udev
2 #
3 # Copyright (C) 2003  Greg Kroah-Hartman <greg@kroah.com>
4 #
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.
8 #
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.
13 #
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
17 #
18
19 # Set the following to control the use of syslog
20 # Set it to `false' to remove all logging
21 USE_LOG = true
22
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.
26 DEBUG = false
27
28 # Set the following to `true' to make udev emit a D-BUS signal when a
29 # new node is created.
30 USE_DBUS = false
31
32
33 ROOT =          udev
34 DAEMON =        udevd
35 SENDER =        udevsend
36 VERSION =       014_bk
37 INSTALL_DIR =   /usr/local/bin
38 RELEASE_NAME =  $(ROOT)-$(VERSION)
39 LOCAL_CFG_DIR = etc/udev
40
41 DESTDIR =
42 # override this to make udev look in a different location for it's config files
43 prefix =
44 exec_prefix =   ${prefix}
45 etcdir =        ${prefix}/etc
46 sbindir =       ${exec_prefix}/sbin
47 mandir =        ${prefix}/usr/share/man
48 hotplugdir =    ${etcdir}/hotplug.d/default
49 dbusdir =       ${etcdir}/dbus-1/system.d
50 configdir =     ${etcdir}/udev/
51 initdir =       ${etcdir}/init.d/
52 srcdir = .
53
54 INSTALL = /usr/bin/install -c
55 INSTALL_PROGRAM = ${INSTALL}
56 INSTALL_DATA  = ${INSTALL} -m 644
57 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
58
59 # To build any of the extras programs, run with:
60 #       make EXTRAS="extras/a extras/b" 
61 EXTRAS=
62
63 # place to put our device nodes
64 udevdir = ${prefix}/udev
65
66 # Comment out this line to build with something other 
67 # than the local version of klibc
68 #USE_KLIBC = true
69
70 # If you are running a cross compiler, you may want to set this
71 # to something more interesting, like "arm-linux-".  If you want
72 # to compile vs uClibc, that can be done here as well.
73 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
74 CC = $(CROSS)gcc
75 LD = $(CROSS)gcc
76 AR = $(CROSS)ar
77 STRIP = $(CROSS)strip
78 RANLIB = $(CROSS)ranlib
79
80 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0
81
82 # code taken from uClibc to determine the current arch
83 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
84         -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
85
86 # code taken from uClibc to determine the gcc include dir
87 GCCINCDIR := ${shell $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
88
89 # code taken from uClibc to determine the libgcc.a filename
90 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
91
92 # use '-Os' optimization if available, else use -O2
93 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
94                 then echo "-Os"; else echo "-O2" ; fi}
95
96 # add -Wredundant-decls when libsysfs gets cleaned up
97 WARNINGS := -Wall 
98
99 # Some nice architecture specific optimizations
100 ifeq ($(strip $(TARGET_ARCH)),arm)
101         OPTIMIZATION+=-fstrict-aliasing
102 endif
103 ifeq ($(strip $(TARGET_ARCH)),i386)
104         OPTIMIZATION+=-march=i386
105         OPTIMIZATION += ${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \
106                 /dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi}
107         OPTIMIZATION += ${shell if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \
108                 /dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi}
109         CFLAGS+=-pipe
110 else
111         CFLAGS+=-pipe
112 endif
113
114 ifeq ($(strip $(USE_LOG)),true)
115         CFLAGS  += -DLOG
116 endif
117
118 # if DEBUG is enabled, then we do not strip or optimize
119 ifeq ($(strip $(DEBUG)),true)
120         CFLAGS  += -O1 -g -DDEBUG -D_GNU_SOURCE
121         LDFLAGS += -Wl,-warn-common
122         STRIPCMD = /bin/true -Since_we_are_debugging
123 else
124         CFLAGS  += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
125         LDFLAGS += -s -Wl,-warn-common
126         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
127 endif
128
129 # If we are using our version of klibc, then we need to build, link it, and then
130 # link udev against it statically.
131 # Otherwise, use glibc and link dynamically.
132 ifeq ($(strip $(USE_KLIBC)),true)
133         KLIBC_BASE      = $(PWD)/klibc
134         KLIBC_DIR       = $(KLIBC_BASE)/klibc
135         INCLUDE_DIR     := $(KLIBC_DIR)/include
136         LINUX_INCLUDE_DIR       := $(KLIBC_BASE)/linux/include
137         include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
138         # arch specific objects
139         ARCH_LIB_OBJS = \
140                         $(KLIBC_DIR)/libc.a
141
142
143         CRT0 = $(KLIBC_DIR)/crt0.o
144         LIBC =  $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
145         CFLAGS += $(WARNINGS) -nostdinc                 \
146                 -D__KLIBC__ -fno-builtin-printf         \
147                 -I$(INCLUDE_DIR)                        \
148                 -I$(KLIBC_DIR)/arch/$(ARCH)/include     \
149                 -I$(INCLUDE_DIR)/bits$(BITSIZE)         \
150                 -I$(GCCINCDIR)                          \
151                 -I$(LINUX_INCLUDE_DIR)
152         LIB_OBJS =
153         LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
154         UDEVD =
155 else
156         WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
157         CRT0 =
158         LIBC = 
159         CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
160         LIB_OBJS = -lc
161         LDFLAGS =
162         UDEVD = $(DAEMON) $(SENDER)
163 endif
164
165 CFLAGS += -I$(PWD)/libsysfs
166
167 all: $(ROOT) $(UDEVD)
168         @extras="$(EXTRAS)" ; for target in $$extras ; do \
169                 echo $$target ; \
170                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
171                         -C $$target $@ ; \
172         done ; \
173
174 $(ROOT): $(LIBC)
175
176 $(ARCH_LIB_OBJS) : $(CRT0)
177
178 $(CRT0):
179         $(MAKE) -C klibc
180
181 TDB =   tdb/tdb.o       \
182         tdb/spinlock.o
183
184 SYSFS = $(PWD)/libsysfs/sysfs_bus.o     \
185         $(PWD)/libsysfs/sysfs_class.o   \
186         $(PWD)/libsysfs/sysfs_device.o  \
187         $(PWD)/libsysfs/sysfs_dir.o     \
188         $(PWD)/libsysfs/sysfs_driver.o  \
189         $(PWD)/libsysfs/sysfs_utils.o   \
190         $(PWD)/libsysfs/dlist.o
191
192 OBJS =  udev.o          \
193         udev_config.o   \
194         udev-add.o      \
195         udev-remove.o   \
196         udevdb.o        \
197         logging.o       \
198         namedev.o       \
199         namedev_parse.o \
200         $(SYSFS)        \
201         $(TDB)
202
203 ifeq ($(strip $(USE_KLIBC)),true)
204         OBJS += klibc_fixups.o
205 endif
206
207 ifeq ($(USE_DBUS), true)
208         CFLAGS += -DUSE_DBUS
209         CFLAGS += $(shell pkg-config --cflags dbus-1)
210         LDFLAGS += $(shell pkg-config --libs dbus-1)
211         OBJS += udev_dbus.o
212 endif
213
214 # header files automatically generated
215 GEN_HEADERS =   udev_version.h
216
217 # Rules on how to create the generated header files
218 udev_version.h:
219         @echo \#define UDEV_VERSION     \"$(VERSION)\" > $@
220         @echo \#define UDEV_ROOT        \"$(udevdir)/\" >> $@
221         @echo \#define UDEV_DB          \"$(udevdir)/\.udev.tdb\" >> $@
222         @echo \#define UDEV_CONFIG_DIR  \"$(configdir)\" >> $@
223         @echo \#define UDEV_CONFIG_FILE \"$(configdir)\udev.conf\" >> $@
224         @echo \#define UDEV_RULES_FILE  \"$(configdir)\udev.rules\" >> $@
225         @echo \#define UDEV_PERMISSION_FILE     \"$(configdir)\udev.permissions\" >> $@
226
227 # config files automatically generated
228 GEN_CONFIGS =   $(LOCAL_CFG_DIR)/udev.conf
229
230 # Rules on how to create the generated config files
231 $(LOCAL_CFG_DIR)/udev.conf:
232         sed -e "s:@udevdir@:$(udevdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
233
234
235 $(OBJS): $(GEN_HEADERS)
236
237 $(ROOT): $(OBJS) udev.h namedev.h udev_version.h udev_dbus.h udevdb.h klibc_fixups.h logging.h list.h
238         $(LD) $(LDFLAGS) -o $(ROOT) $(CRT0) $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
239         $(STRIPCMD) $(ROOT)
240
241 $(DAEMON): udevd.h udevd.o udevd.o logging.o
242         $(LD) $(LDFLAGS) -o $(DAEMON) $(CRT0) udevd.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
243         $(STRIPCMD) $(ROOT)
244
245 $(SENDER): udevd.h udevsend.o udevd.o logging.o
246         $(LD) $(LDFLAGS) -o $(SENDER) $(CRT0) udevsend.o logging.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
247         $(STRIPCMD) $(ROOT)
248
249 clean:
250         -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
251          | xargs rm -f 
252         -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(DAEMON) $(SENDER)
253         $(MAKE) -C klibc clean
254         @extras="$(EXTRAS)" ; for target in $$extras ; do \
255                 echo $$target ; \
256                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
257                         -C $$target $@ ; \
258         done ; \
259
260 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 )
261 DISTDIR := $(RELEASE_NAME)
262 srcdir = .
263 release: clean
264         @echo "--------------------------cut here------------------------"
265         @echo "cd .."
266         @echo "rm -rf $(DISTDIR)"
267         @echo "mkdir $(DISTDIR)"
268         @echo "chmod 777 $(DISTDIR)"
269         @echo "cp -avr udev/* $(DISTDIR)"
270         @echo "tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz"
271         @echo "rm -rf $(DISTDIR)"
272         @echo "--------------------------cut here------------------------"
273
274
275 small_release: $(DISTFILES) clean
276 #       @echo $(DISTFILES)
277         @-rm -rf $(DISTDIR)
278         @mkdir $(DISTDIR)
279         @-chmod 777 $(DISTDIR)
280         @for file in $(DISTFILES); do                   \
281                 if test -d $$file; then                 \
282                         mkdir $(DISTDIR)/$$file;        \
283                 else                                    \
284                         cp -p $$file $(DISTDIR)/$$file; \
285                 fi;                                     \
286         done
287         @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
288         @rm -rf $(DISTDIR)
289         @echo "Built $(RELEASE_NAME).tar.gz"
290
291
292 ifeq ($(USE_DBUS), true)
293 install-dbus-policy:
294         $(INSTALL) -d $(DESTDIR)$(dbusdir)
295         $(INSTALL_DATA) etc/dbus-1/system.d/udev_sysbus_policy.conf $(DESTDIR)$(dbusdir)
296
297 uninstall-dbus-policy:
298         - rm $(DESTDIR)$(dbusdir)/udev_sysbus_policy.conf
299 else
300 install-dbus-policy:
301         -
302 uninstall-dbus-policy:
303         -
304 endif
305
306 install-config: $(GEN_CONFIGS)
307         $(INSTALL) -d $(DESTDIR)$(configdir)
308         @if [ ! -r $(DESTDIR)$(configdir)udev.conf ]; then \
309                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
310                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
311         fi
312         @if [ ! -r $(DESTDIR)$(configdir)udev.rules ]; then \
313                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
314                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
315         fi
316         @if [ ! -r $(DESTDIR)$(configdir)udev.permissions ]; then \
317                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
318                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
319         fi
320
321 install: install-config install-dbus-policy all
322         $(INSTALL) -d $(DESTDIR)$(udevdir)
323         $(INSTALL) -d $(DESTDIR)$(hotplugdir)
324         $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
325         @if [ "x$(USE_LSB)" = "xtrue" ]; then \
326                 $(INSTALL_PROGRAM) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev; \
327                 ln -s $(DESTDIR)$(initdir)/udev $(sbin_dir)/rcudev; \
328         else \
329                 $(INSTALL_PROGRAM) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev; \
330         fi
331         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
332         - rm -f $(DESTDIR)$(hotplugdir)/udev.hotplug
333         - ln -f -s $(sbindir)/$(ROOT) $(DESTDIR)$(hotplugdir)/udev.hotplug
334         @extras="$(EXTRAS)" ; for target in $$extras ; do \
335                 echo $$target ; \
336                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
337                         -C $$target $@ ; \
338         done ; \
339
340 uninstall: uninstall-dbus-policy
341         - rm $(hotplugdir)/udev.hotplug
342         - rm $(configdir)/udev.permissions
343         - rm $(configdir)/udev.rules
344         - rm $(configdir)/udev.conf
345         - rm $(initdir)/udev
346         - rm $(mandir)/man8/udev.8
347         - rm $(sbindir)/$(ROOT)
348         - rmdir $(hotplugdir)
349         - rmdir $(configdir)
350         - rmdir $(udevdir)
351         @extras="$(EXTRAS)" ; for target in $$extras ; do \
352                 echo $$target ; \
353                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
354                         -C $$target $@ ; \
355         done ; \