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