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