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