chiark / gitweb /
[PATCH] make udevtest a real program :)
[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 VERSION =       022
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 dbusdir =       ${etcdir}/dbus-1/system.d
58 configdir =     ${etcdir}/udev/
59 initdir =       ${etcdir}/init.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 $(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 # Some nice architecture specific optimizations
111 ifeq ($(strip $(TARGET_ARCH)),arm)
112         OPTIMIZATION+=-fstrict-aliasing
113 endif
114 ifeq ($(strip $(TARGET_ARCH)),i386)
115         OPTIMIZATION+=-march=i386
116         OPTIMIZATION += ${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \
117                 /dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi}
118         OPTIMIZATION += ${shell if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \
119                 /dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi}
120         CFLAGS+=-pipe
121 else
122         CFLAGS+=-pipe
123 endif
124
125 ifeq ($(strip $(USE_LOG)),true)
126         CFLAGS  += -DLOG
127 endif
128
129 # if DEBUG is enabled, then we do not strip or optimize
130 ifeq ($(strip $(DEBUG)),true)
131         CFLAGS  += -O1 -g -DDEBUG -D_GNU_SOURCE
132         LDFLAGS += -Wl,-warn-common
133         STRIPCMD = /bin/true -Since_we_are_debugging
134 else
135         CFLAGS  += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
136         LDFLAGS += -s -Wl,-warn-common
137         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
138 endif
139
140 # If we are using our version of klibc, then we need to build, link it, and then
141 # link udev against it statically.
142 # Otherwise, use glibc and link dynamically.
143 ifeq ($(strip $(USE_KLIBC)),true)
144         KLIBC_BASE      = $(PWD)/klibc
145         KLIBC_DIR       = $(KLIBC_BASE)/klibc
146         INCLUDE_DIR     := $(KLIBC_DIR)/include
147         LINUX_INCLUDE_DIR       := $(KERNEL_DIR)/include
148 #       LINUX_INCLUDE_DIR       := $(KLIBC_BASE)/linux/include
149         include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
150         # arch specific objects
151         ARCH_LIB_OBJS = \
152                         $(KLIBC_DIR)/libc.a
153
154
155         CRT0 = $(KLIBC_DIR)/crt0.o
156         LIBC =  $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
157         CFLAGS += $(WARNINGS) -nostdinc                 \
158                 $(OPTFLAGS)                             \
159                 -D__KLIBC__ -fno-builtin-printf         \
160                 -I$(INCLUDE_DIR)                        \
161                 -I$(KLIBC_DIR)/arch/$(ARCH)/include     \
162                 -I$(INCLUDE_DIR)/bits$(BITSIZE)         \
163                 -I$(GCCINCDIR)                          \
164                 -I$(LINUX_INCLUDE_DIR)
165         LIB_OBJS =
166         LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
167 else
168         WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
169         CRT0 =
170         LIBC = 
171         CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
172         LIB_OBJS = -lc
173         LDFLAGS =
174 endif
175
176 CFLAGS += -I$(PWD)/libsysfs
177
178 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(STARTER)
179         @extras="$(EXTRAS)" ; for target in $$extras ; do \
180                 echo $$target ; \
181                 $(MAKE) prefix=$(prefix) \
182                         LD="$(LD)" \
183                         SYSFS="$(SYSFS)" \
184                         KERNEL_DIR="$(KERNEL_DIR)" \
185                         -C $$target $@ ; \
186         done ; \
187
188 $(ARCH_LIB_OBJS) : $(CRT0)
189
190 $(CRT0):
191         $(MAKE) -C klibc KERNEL_DIR=$(KERNEL_DIR)
192
193 TDB =   tdb/tdb.o       \
194         tdb/spinlock.o
195
196 SYSFS = $(PWD)/libsysfs/sysfs_bus.o     \
197         $(PWD)/libsysfs/sysfs_class.o   \
198         $(PWD)/libsysfs/sysfs_device.o  \
199         $(PWD)/libsysfs/sysfs_dir.o     \
200         $(PWD)/libsysfs/sysfs_driver.o  \
201         $(PWD)/libsysfs/sysfs_utils.o   \
202         $(PWD)/libsysfs/dlist.o
203
204 OBJS =  udev_config.o   \
205         udev-add.o      \
206         udev-remove.o   \
207         udevdb.o        \
208         namedev.o       \
209         namedev_parse.o \
210         $(SYSFS)        \
211         $(TDB)
212
213 HEADERS =       udev.h          \
214                 namedev.h       \
215                 udev_version.h  \
216                 udev_dbus.h     \
217                 udevdb.h        \
218                 klibc_fixups.h  \
219                 logging.h       \
220                 list.h
221
222 ifeq ($(strip $(USE_KLIBC)),true)
223         OBJS += klibc_fixups.o
224 endif
225
226 ifeq ($(USE_DBUS), true)
227         CFLAGS += -DUSE_DBUS
228         CFLAGS += $(shell pkg-config --cflags dbus-1)
229         LDFLAGS += $(shell pkg-config --libs dbus-1)
230         OBJS += udev_dbus.o
231 endif
232
233 # if USE_SELINUX is enabled, then we do not strip or optimize
234 ifeq ($(strip $(USE_SELINUX)),true)
235         CFLAGS  += -DUSE_SELINUX
236         OBJS += udev_selinux.o
237         LIB_OBJS += -lselinux
238 endif
239
240
241 # header files automatically generated
242 GEN_HEADERS =   udev_version.h
243
244 # Rules on how to create the generated header files
245 udev_version.h:
246         @echo \#define UDEV_VERSION     \"$(VERSION)\" > $@
247         @echo \#define UDEV_ROOT        \"$(udevdir)/\" >> $@
248         @echo \#define UDEV_DB          \"$(udevdir)/\.udev.tdb\" >> $@
249         @echo \#define UDEV_CONFIG_DIR  \"$(configdir)\" >> $@
250         @echo \#define UDEV_CONFIG_FILE \"$(configdir)\udev.conf\" >> $@
251         @echo \#define UDEV_RULES_FILE  \"$(configdir)\udev.rules\" >> $@
252         @echo \#define UDEV_PERMISSION_FILE     \"$(configdir)\udev.permissions\" >> $@
253         @echo \#define UDEV_LOG_DEFAULT \"yes\" >> $@
254         @echo \#define UDEV_BIN         \"$(DESTDIR)$(sbindir)/udev\" >> $@
255         @echo \#define UDEVD_BIN        \"$(DESTDIR)$(sbindir)/udevd\" >> $@
256
257 # config files automatically generated
258 GEN_CONFIGS =   $(LOCAL_CFG_DIR)/udev.conf
259
260 # Rules on how to create the generated config files
261 $(LOCAL_CFG_DIR)/udev.conf:
262         sed -e "s:@udevdir@:$(udevdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
263
264
265 $(OBJS): $(GEN_HEADERS)
266 $(ROOT).o: $(GEN_HEADERS)
267 $(TESTER).o: $(GEN_HEADERS)
268 $(INFO).o: $(GEN_HEADERS)
269 $(DAEMON).o: $(GEN_HEADERS)
270 $(SENDER).o: $(GEN_HEADERS)
271 $(STARTER).o: $(GEN_HEADERS)
272
273 $(ROOT): $(ROOT).o $(OBJS) $(HEADERS) $(LIBC)
274         $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
275         $(STRIPCMD) $@
276
277 $(TESTER): $(TESTER).o $(OBJS) $(HEADERS) $(LIBC)
278         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevtest.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
279         $(STRIPCMD) $@
280
281 $(INFO): $(INFO).o $(OBJS) $(HEADERS) $(LIBC)
282         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
283         $(STRIPCMD) $@
284
285 $(DAEMON): $(DAEMON).o udevd.h $(LIBC)
286         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
287         $(STRIPCMD) $@
288
289 $(SENDER): $(SENDER).o udevd.h $(LIBC)
290         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
291         $(STRIPCMD) $@
292
293 $(STARTER): $(STARTER).o $(HEADERS) $(LIBC)
294         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevstart.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
295         $(STRIPCMD) $@
296
297 clean:
298         -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
299          | xargs rm -f 
300         -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(INFO) $(DAEMON) $(SENDER) $(TESTER) $(STARTER)
301         $(MAKE) -C klibc clean
302         @extras="$(EXTRAS)" ; for target in $$extras ; do \
303                 echo $$target ; \
304                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
305                         -C $$target $@ ; \
306         done ; \
307
308 spotless: clean
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 ifeq ($(USE_DBUS), true)
341 install-dbus-policy:
342         $(INSTALL) -d $(DESTDIR)$(dbusdir)
343         $(INSTALL_DATA) etc/dbus-1/system.d/udev_sysbus_policy.conf $(DESTDIR)$(dbusdir)
344
345 uninstall-dbus-policy:
346         - rm $(DESTDIR)$(dbusdir)/udev_sysbus_policy.conf
347 else
348 install-dbus-policy:
349         -
350 uninstall-dbus-policy:
351         -
352 endif
353
354 install-initscript: etc/init.d/udev etc/init.d/udev.debian etc/init.d/udev.init.LSB
355         @if [ -f /etc/redhat-release ]; then \
356                 $(INSTALL_DATA) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev; \
357         elif [ -f /etc/SuSE-release ]; then \
358                 $(INSTALL_DATA) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev; \
359         elif [ -f /etc/debian_version ]; then \
360                 $(INSTALL_DATA) -D etc/init.d/udev.debian $(DESTDIR)$(initdir)/udev; \
361         fi
362
363 install-config: $(GEN_CONFIGS)
364         $(INSTALL) -d $(DESTDIR)$(configdir)
365         @if [ ! -r $(DESTDIR)$(configdir)udev.conf ]; then \
366                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
367                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
368         fi
369         @if [ ! -r $(DESTDIR)$(configdir)udev.rules ]; then \
370                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
371                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
372         fi
373         @if [ ! -r $(DESTDIR)$(configdir)udev.permissions ]; then \
374                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
375                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
376         fi
377
378 install: install-initscript install-config install-dbus-policy all
379         $(INSTALL) -d $(DESTDIR)$(udevdir)
380         $(INSTALL) -d $(DESTDIR)$(hotplugdir)
381         $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
382         $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
383         $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
384         $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
385         $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
386         $(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
387         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
388         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
389         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
390         $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
391         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
392         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
393         - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/$(ROOT).hotplug
394 ifndef DESTDIR
395         - killall udevd
396         - rm -f $(udevdir)/.udev.tdb
397 endif
398         @extras="$(EXTRAS)" ; for target in $$extras ; do \
399                 echo $$target ; \
400                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
401                         -C $$target $@ ; \
402         done ; \
403
404 uninstall: uninstall-dbus-policy
405         - rm $(hotplugdir)/udev.hotplug
406         - rm $(configdir)/udev.permissions
407         - rm $(configdir)/udev.rules
408         - rm $(configdir)/udev.conf
409         - rm $(initdir)/udev
410         - rm $(mandir)/man8/udev.8
411         - rm $(mandir)/man8/udevinfo.8
412         - rm $(mandir)/man8/udevtest.8
413         - rm $(mandir)/man8/udevstart.8
414         - rm $(mandir)/man8/udevd.8
415         - rm $(mandir)/man8/udevsend.8
416         - rm $(sbindir)/$(ROOT)
417         - rm $(sbindir)/$(DAEMON)
418         - rm $(sbindir)/$(SENDER)
419         - rm $(usrbindir)/$(INFO)
420         - rmdir $(hotplugdir)
421         - rmdir $(configdir)
422         - rm $(udevdir)/.udev.tdb
423         - rmdir $(udevdir)
424         @extras="$(EXTRAS)" ; for target in $$extras ; do \
425                 echo $$target ; \
426                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
427                         -C $$target $@ ; \
428         done ; \