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