chiark / gitweb /
3d5288b25d086507a5cf65f52e93cca00f54b666
[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
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         $(SYSFS)        \
213         $(TDB)
214
215 HEADERS =       udev.h          \
216                 udev_lib.h      \
217                 namedev.h       \
218                 udev_version.h  \
219                 udev_dbus.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
317 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 )
318 DISTDIR := $(RELEASE_NAME)
319 srcdir = .
320 release: clean
321         -rm -rf $(DISTDIR)
322         mkdir $(DISTDIR)
323         chmod 777 $(DISTDIR)
324         bk export $(DISTDIR)
325         tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
326         rm -rf $(DISTDIR)
327         @echo "$(RELEASE_NAME).tar.gz created"
328
329
330 small_release: $(DISTFILES) clean
331 #       @echo $(DISTFILES)
332         @-rm -rf $(DISTDIR)
333         @mkdir $(DISTDIR)
334         @-chmod 777 $(DISTDIR)
335         @for file in $(DISTFILES); do                   \
336                 if test -d $$file; then                 \
337                         mkdir $(DISTDIR)/$$file;        \
338                 else                                    \
339                         cp -p $$file $(DISTDIR)/$$file; \
340                 fi;                                     \
341         done
342         @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
343         @rm -rf $(DISTDIR)
344         @echo "Built $(RELEASE_NAME).tar.gz"
345
346
347 ifeq ($(USE_DBUS), true)
348 install-dbus-policy:
349         $(INSTALL) -d $(DESTDIR)$(dbusdir)
350         $(INSTALL_DATA) etc/dbus-1/system.d/udev_sysbus_policy.conf $(DESTDIR)$(dbusdir)
351
352 uninstall-dbus-policy:
353         - rm $(DESTDIR)$(dbusdir)/udev_sysbus_policy.conf
354 else
355 install-dbus-policy:
356         -
357 uninstall-dbus-policy:
358         -
359 endif
360
361 install-initscript: etc/init.d/udev etc/init.d/udev.debian etc/init.d/udev.init.LSB
362         @if [ -f /etc/redhat-release ]; then \
363                 $(INSTALL_DATA) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev; \
364         elif [ -f /etc/SuSE-release ]; then \
365                 $(INSTALL_DATA) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev; \
366         elif [ -f /etc/debian_version ]; then \
367                 $(INSTALL_DATA) -D etc/init.d/udev.debian $(DESTDIR)$(initdir)/udev; \
368         fi
369
370 install-config: $(GEN_CONFIGS)
371         $(INSTALL) -d $(DESTDIR)$(configdir)
372         @if [ ! -r $(DESTDIR)$(configdir)udev.conf ]; then \
373                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
374                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
375         fi
376         @if [ ! -r $(DESTDIR)$(configdir)udev.rules ]; then \
377                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
378                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
379         fi
380         @if [ ! -r $(DESTDIR)$(configdir)udev.permissions ]; then \
381                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
382                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
383         fi
384
385 install: install-initscript install-config install-dbus-policy all
386         $(INSTALL) -d $(DESTDIR)$(udevdir)
387         $(INSTALL) -d $(DESTDIR)$(hotplugdir)
388         $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
389         $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
390         $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
391         $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
392         $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
393         $(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
394         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
395         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
396         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
397         $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
398         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
399         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
400         - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/$(ROOT).hotplug
401 ifndef DESTDIR
402         - killall udevd
403         - rm -f $(udevdir)/.udev.tdb
404 endif
405         @extras="$(EXTRAS)" ; for target in $$extras ; do \
406                 echo $$target ; \
407                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
408                         -C $$target $@ ; \
409         done ; \
410
411 uninstall: uninstall-dbus-policy
412         - rm $(hotplugdir)/udev.hotplug
413         - rm $(configdir)/udev.permissions
414         - rm $(configdir)/udev.rules
415         - rm $(configdir)/udev.conf
416         - rm $(initdir)/udev
417         - rm $(mandir)/man8/udev.8
418         - rm $(mandir)/man8/udevinfo.8
419         - rm $(mandir)/man8/udevtest.8
420         - rm $(mandir)/man8/udevstart.8
421         - rm $(mandir)/man8/udevd.8
422         - rm $(mandir)/man8/udevsend.8
423         - rm $(sbindir)/$(ROOT)
424         - rm $(sbindir)/$(DAEMON)
425         - rm $(sbindir)/$(SENDER)
426         - rm $(usrbindir)/$(INFO)
427         - rmdir $(hotplugdir)
428         - rmdir $(configdir)
429         - rm $(udevdir)/.udev.tdb
430         - rmdir $(udevdir)
431         @extras="$(EXTRAS)" ; for target in $$extras ; do \
432                 echo $$target ; \
433                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
434                         -C $$target $@ ; \
435         done ; \