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