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