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