]> git.ipfire.org Git - thirdparty/systemd.git/blob - Makefile
[PATCH] add cdsymlinks.sh support to gentoo rules file.
[thirdparty/systemd.git] / Makefile
1 # Makefile for udev
2 #
3 # Copyright (C) 2003,2004 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 this to compile with Security-Enhanced Linux support.
29 USE_SELINUX = false
30
31 ROOT = udev
32 DAEMON = udevd
33 SENDER = udevsend
34 INFO = udevinfo
35 TESTER = udevtest
36 STARTER = udevstart
37 WAIT = wait_for_sysfs
38 VERSION = 042
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 usrbindir = ${exec_prefix}/usr/bin
54 mandir = ${prefix}/usr/share/man
55 hotplugdir = ${etcdir}/hotplug.d/default
56 configdir = ${etcdir}/udev
57 initdir = ${etcdir}/init.d
58 dev_ddir = ${etcdir}/dev.d
59 srcdir = .
60
61 INSTALL = /usr/bin/install -c
62 INSTALL_PROGRAM = ${INSTALL}
63 INSTALL_DATA = ${INSTALL} -m 644
64 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
65
66 # To build any of the extras programs, run with:
67 # make EXTRAS="extras/a extras/b"
68 EXTRAS=
69
70 # place to put our device nodes
71 udevdir = ${prefix}/udev
72
73 # Comment out this line to build with something other
74 # than the local version of klibc
75 #USE_KLIBC = true
76
77 # make the build silent (well, at least the udev part) Set this
78 # to something else to make it noisy again.
79 V=false
80
81 # set up PWD so that older versions of make will work with our build.
82 PWD = $(shell pwd)
83
84 # If you are running a cross compiler, you may want to set this
85 # to something more interesting, like "arm-linux-". If you want
86 # to compile vs uClibc, that can be done here as well.
87 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
88 CC = $(CROSS)gcc
89 LD = $(CROSS)gcc
90 AR = $(CROSS)ar
91 STRIP = $(CROSS)strip
92 RANLIB = $(CROSS)ranlib
93 HOSTCC = gcc
94
95 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0
96
97 # code taken from uClibc to determine the current arch
98 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
99 -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
100
101 # code taken from uClibc to determine the gcc include dir
102 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
103
104 # code taken from uClibc to determine the libgcc.a filename
105 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
106
107 # use '-Os' optimization if available, else use -O2
108 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
109 then echo "-Os"; else echo "-O2" ; fi}
110
111 # add -Wredundant-decls when libsysfs gets cleaned up
112 WARNINGS := -Wall
113
114 CFLAGS := -pipe
115
116 # set up the proper tdb spinlock code if we can
117 ifeq ($(strip $(ARCH)),i386)
118 CFLAGS += -DUSE_SPINLOCKS -DINTEL_SPINLOCKS
119 endif
120
121 ifeq ($(strip $(USE_LOG)),true)
122 CFLAGS += -DLOG
123 endif
124
125 # if DEBUG is enabled, then we do not strip or optimize
126 ifeq ($(strip $(DEBUG)),true)
127 CFLAGS += -O1 -g -DDEBUG -D_GNU_SOURCE
128 LDFLAGS += -Wl,-warn-common
129 STRIPCMD = /bin/true -Since_we_are_debugging
130 else
131 CFLAGS += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
132 LDFLAGS += -s -Wl,-warn-common
133 STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
134 endif
135
136 # If we are using our version of klibc, then we need to build, link it, and then
137 # link udev against it statically.
138 # Otherwise, use glibc and link dynamically.
139 ifeq ($(strip $(USE_KLIBC)),true)
140 KLIBC_FIXUPS_DIR= $(PWD)/klibc_fixups
141 KLIBC_BASE = $(PWD)/klibc
142 KLIBC_DIR = $(KLIBC_BASE)/klibc
143 INCLUDE_DIR := $(KLIBC_BASE)/include
144 LINUX_INCLUDE_DIR := $(KERNEL_DIR)/include
145 include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
146 # arch specific objects
147 ARCH_LIB_OBJS = \
148 $(KLIBC_DIR)/libc.a
149
150
151 CRT0 = $(KLIBC_DIR)/crt0.o
152 LIBC = $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
153 CFLAGS += $(WARNINGS) -nostdinc \
154 $(OPTFLAGS) \
155 -D__KLIBC__ -fno-builtin-printf \
156 -I$(KLIBC_FIXUPS_DIR) \
157 -include $(KLIBC_FIXUPS_DIR)/klibc_fixups.h \
158 -I$(INCLUDE_DIR) \
159 -I$(INCLUDE_DIR)/arch/$(ARCH) \
160 -I$(INCLUDE_DIR)/bits$(BITSIZE) \
161 -I$(GCCINCDIR) \
162 -I$(LINUX_INCLUDE_DIR)
163 LIB_OBJS =
164 LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
165 else
166 WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
167 CRT0 =
168 LIBC =
169 CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
170 LIB_OBJS = -lc
171 LDFLAGS =
172 endif
173
174 ifeq ($(strip $(USE_SELINUX)),true)
175 CFLAGS += -DUSE_SELINUX
176 LIB_OBJS += -lselinux
177 endif
178
179 CFLAGS += -I$(PWD)/libsysfs/sysfs \
180 -I$(PWD)/libsysfs
181
182 # config files automatically generated
183 GEN_CONFIGS = $(LOCAL_CFG_DIR)/udev.conf
184
185 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(WAIT) $(GEN_CONFIGS)
186 @extras="$(EXTRAS)" ; for target in $$extras ; do \
187 echo $$target ; \
188 $(MAKE) prefix=$(prefix) \
189 LD="$(LD)" \
190 SYSFS="$(SYSFS)" \
191 KERNEL_DIR="$(KERNEL_DIR)" \
192 QUIET="@$(PWD)/ccdv" \
193 -C $$target $@ ; \
194 done ; \
195
196 $(ARCH_LIB_OBJS) : $(CRT0)
197
198 $(CRT0):
199 @if [ ! -r klibc/linux ]; then \
200 ln -f -s $(KERNEL_DIR) klibc/linux; \
201 fi
202 $(MAKE) -C klibc SUBDIRS=klibc
203
204 TDB = tdb/tdb.o \
205 tdb/spinlock.o
206
207 SYSFS = $(PWD)/libsysfs/sysfs_bus.o \
208 $(PWD)/libsysfs/sysfs_class.o \
209 $(PWD)/libsysfs/sysfs_device.o \
210 $(PWD)/libsysfs/sysfs_dir.o \
211 $(PWD)/libsysfs/sysfs_driver.o \
212 $(PWD)/libsysfs/sysfs_utils.o \
213 $(PWD)/libsysfs/dlist.o
214
215 OBJS = udev_lib.o \
216 udev_config.o \
217 udev_add.o \
218 udev_remove.o \
219 udev_sysfs.o \
220 udevdb.o \
221 namedev.o \
222 namedev_parse.o \
223 dev_d.o \
224 $(SYSFS) \
225 $(TDB)
226
227 HEADERS = udev.h \
228 udev_lib.h \
229 namedev.h \
230 udev_version.h \
231 udevdb.h \
232 udev_sysfs.h \
233 logging.h \
234 selinux.h \
235 list.h
236
237 ifeq ($(strip $(USE_KLIBC)),true)
238 HEADERS += klibc_fixups/klibc_fixups.h \
239 klibc_fixups/mntent.h \
240 klibc_fixups/pwd.h
241
242 OBJS += klibc_fixups/klibc_fixups.o
243 KLIBC_FIXUP = klibc_fixups/klibc_fixups.o
244 endif
245
246 ifeq ($(strip $(V)),false)
247 QUIET=@./ccdv
248 HOST_PROGS=ccdv
249 else
250 QUIET=
251 HOST_PROGS=
252 endif
253
254 # header files automatically generated
255 GEN_HEADERS = udev_version.h
256
257 ccdv:
258 @echo "Building ccdv"
259 @$(HOSTCC) -O1 ccdv.c -o ccdv
260
261 # Rules on how to create the generated header files
262 udev_version.h:
263 @echo "Creating udev_version.h"
264 @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
265 @echo \#define UDEV_ROOT \"$(udevdir)/\" >> $@
266 @echo \#define UDEV_DB \"$(udevdir)/.udev.tdb\" >> $@
267 @echo \#define UDEV_CONFIG_DIR \"$(configdir)\" >> $@
268 @echo \#define UDEV_CONFIG_FILE \"$(configdir)/udev.conf\" >> $@
269 @echo \#define UDEV_RULES_FILE \"$(configdir)/rules.d\" >> $@
270 @echo \#define UDEV_PERMISSION_FILE \"$(configdir)/permissions.d\" >> $@
271 @echo \#define UDEV_LOG_DEFAULT \"yes\" >> $@
272 @echo \#define UDEV_BIN \"$(DESTDIR)$(sbindir)/udev\" >> $@
273 @echo \#define UDEVD_BIN \"$(DESTDIR)$(sbindir)/udevd\" >> $@
274
275 # Rules on how to create the generated config files
276 $(LOCAL_CFG_DIR)/udev.conf:
277 sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
278
279 GEN_MANPAGES = udev.8
280 GEN_MANPAGESIN = udev.8.in
281 # Rules on how to create the man pages
282 $(GEN_MANPAGES): $(GEN_MANPAGESIN)
283 sed -e "s:@udevdir@:$(udevdir):" < $@.in > $@
284
285 $(OBJS): $(GEN_HEADERS) $(HOST_PROGS)
286 $(ROOT).o: $(GEN_HEADERS) $(HOST_PROGS)
287 $(TESTER).o: $(GEN_HEADERS) $(HOST_PROGS)
288 $(INFO).o: $(GEN_HEADERS) $(HOST_PROGS)
289 $(DAEMON).o: $(GEN_HEADERS) $(HOST_PROGS)
290 $(SENDER).o: $(GEN_HEADERS) $(HOST_PROGS)
291 $(STARTER).o: $(GEN_HEADERS) $(HOST_PROGS)
292 $(WAIT).o: $(GEN_HEADERS) $(HOST_PROGS)
293
294 $(ROOT): $(LIBC) $(ROOT).o $(STARTER).o $(OBJS) $(HEADERS) $(GEN_MANPAGES)
295 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o udevstart.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
296 $(QUIET) $(STRIPCMD) $@
297
298 $(TESTER): $(LIBC) $(TESTER).o $(OBJS) $(HEADERS)
299 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevtest.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
300 $(QUIET) $(STRIPCMD) $@
301
302 $(INFO): $(LIBC) $(INFO).o $(OBJS) $(HEADERS)
303 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_lib.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
304 $(QUIET) $(STRIPCMD) $@
305
306 $(DAEMON): $(LIBC) $(DAEMON).o $(OBJS) udevd.h
307 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o udev_lib.o $(KLIBC_FIXUP) $(LIB_OBJS) $(ARCH_LIB_OBJS)
308 $(QUIET) $(STRIPCMD) $@
309
310 $(SENDER): $(LIBC) $(SENDER).o $(OBJS) udevd.h
311 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o udev_lib.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
312 $(QUIET) $(STRIPCMD) $@
313
314 $(WAIT): $(WAIT).o $(OBJS) $(HEADERS) $(LIBC)
315 $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(WAIT).o udev_sysfs.o udev_lib.o udev_config.o $(SYSFS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
316 $(QUIET) $(STRIPCMD) $@
317
318 #.c.o:
319 # $(CC) $(CFLAGS) $(DEFS) $(CPPFLAGS) -c -o $@ $<
320 .c.o:
321 $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
322
323
324 clean:
325 -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
326 | xargs rm -f
327 -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) $(SENDER) $(TESTER) $(WAIT)
328 -rm -f ccdv
329 $(MAKE) -C klibc clean
330 @extras="$(EXTRAS)" ; for target in $$extras ; do \
331 echo $$target ; \
332 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
333 -C $$target $@ ; \
334 done ; \
335
336 spotless: clean
337 $(MAKE) -C klibc spotless
338 -rm -f klibc/linux
339
340 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 )
341 DISTDIR := $(RELEASE_NAME)
342 srcdir = .
343 release: clean
344 -rm -rf $(DISTDIR)
345 mkdir $(DISTDIR)
346 chmod 777 $(DISTDIR)
347 bk export $(DISTDIR)
348 tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
349 rm -rf $(DISTDIR)
350 @echo "$(RELEASE_NAME).tar.gz created"
351
352
353 small_release: $(DISTFILES) clean
354 # @echo $(DISTFILES)
355 @-rm -rf $(DISTDIR)
356 @mkdir $(DISTDIR)
357 @-chmod 777 $(DISTDIR)
358 @for file in $(DISTFILES); do \
359 if test -d $$file; then \
360 mkdir $(DISTDIR)/$$file; \
361 else \
362 cp -p $$file $(DISTDIR)/$$file; \
363 fi; \
364 done
365 @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
366 @rm -rf $(DISTDIR)
367 @echo "Built $(RELEASE_NAME).tar.gz"
368
369
370 install-initscript: etc/init.d/udev etc/init.d/udev.init.LSB
371 @if [ -f /etc/redhat-release ]; then \
372 $(INSTALL_DATA) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev; \
373 elif [ -f /etc/SuSE-release ]; then \
374 $(INSTALL_DATA) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev; \
375 fi
376
377 install-config:
378 $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
379 $(INSTALL) -d $(DESTDIR)$(configdir)/permissions.d
380 @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
381 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
382 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
383 fi
384 @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
385 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
386 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
387 fi
388 @if [ ! -r $(DESTDIR)$(configdir)/permissions.d/50-udev.permissions ]; then \
389 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir)/permissions.d/50-udev.permissions; \
390 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir)/permissions.d/50-udev.permissions; \
391 fi
392
393 install-dev.d:
394 $(INSTALL) -d $(DESTDIR)$(dev_ddir)/default
395 $(INSTALL_PROGRAM) -D etc/dev.d/net/hotplug.dev $(DESTDIR)$(dev_ddir)/net/hotplug.dev
396
397 uninstall-dev.d:
398 - rm $(dev_ddir)/net/hotplug.dev
399 - rmdir $(dev_ddir)/net
400 - rmdir $(dev_ddir)/default
401 - rmdir $(dev_ddir)
402
403 install-man:
404 $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
405 $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
406 $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
407 $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
408 $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
409 - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
410
411 uninstall-man:
412 - rm $(mandir)/man8/udev.8
413 - rm $(mandir)/man8/udevinfo.8
414 - rm $(mandir)/man8/udevtest.8
415 - rm $(mandir)/man8/udevstart.8
416 - rm $(mandir)/man8/udevd.8
417 - rm $(mandir)/man8/udevsend.8
418
419 install: install-initscript install-config install-man install-dev.d all
420 $(INSTALL) -d $(DESTDIR)$(udevdir)
421 $(INSTALL) -d $(DESTDIR)$(hotplugdir)
422 $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
423 $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
424 $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
425 $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
426 $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
427 $(INSTALL_PROGRAM) -D $(WAIT) $(DESTDIR)$(sbindir)/$(WAIT)
428 - ln -f -s $(sbindir)/udev $(DESTDIR)$(sbindir)/$(STARTER)
429 - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/10-udev.hotplug
430 - ln -f -s $(sbindir)/$(WAIT) $(DESTDIR)$(hotplugdir)/05-wait_for_sysfs.hotplug
431 ifndef DESTDIR
432 - killall udevd
433 - rm -f $(udevdir)/.udev.tdb
434 endif
435 @extras="$(EXTRAS)" ; for target in $$extras ; do \
436 echo $$target ; \
437 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
438 -C $$target $@ ; \
439 done ; \
440
441 uninstall: uninstall-man uninstall-dev.d
442 - rm $(hotplugdir)/10-udev.hotplug
443 - rm $(hotplugdir)/05-wait_for_sysfs.hotplug
444 - rm $(configdir)/rules.d/50-udev.rules
445 - rm $(configdir)/permissions.d/50-udev.permissions
446 - rm $(configdir)/udev.conf
447 - rmdir $(configdir)/rules.d
448 - rmdir $(configdir)/permissions.d
449 - rmdir $(configdir)
450 - rm $(initdir)/udev
451 - rm $(sbindir)/$(ROOT)
452 - rm $(sbindir)/$(DAEMON)
453 - rm $(sbindir)/$(SENDER)
454 - rm $(sbindir)/$(STARTER)
455 - rm $(usrbindir)/$(INFO)
456 - rm $(usrbindir)/$(TESTER)
457 - rm $(usrbindir)/$(WAIT)
458 - rmdir $(hotplugdir)
459 - rm $(udevdir)/.udev.tdb
460 - rmdir $(udevdir)
461 @extras="$(EXTRAS)" ; for target in $$extras ; do \
462 echo $$target ; \
463 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
464 -C $$target $@ ; \
465 done ; \
466
467 test: all
468 @ cd test && ./udev-test.pl