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