chiark / gitweb /
[PATCH] fix up Makefiles to get the klibc build working properly.
[elogind.git] / Makefile
1 # Makefile for udev
2 #
3 # Copyright (C) 2003,2004 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
29 ROOT =          udev
30 DAEMON =        udevd
31 SENDER =        udevsend
32 INFO =          udevinfo
33 TESTER =        udevtest
34 STARTER =       udevstart
35 RULER =         udevruler
36 VERSION =       032_bk
37 INSTALL_DIR =   /usr/local/bin
38 RELEASE_NAME =  $(ROOT)-$(VERSION)
39 LOCAL_CFG_DIR = etc/udev
40 HOTPLUG_EXEC =  $(ROOT)
41
42 DESTDIR =
43
44 KERNEL_DIR = /lib/modules/${shell uname -r}/build
45
46 # override this to make udev look in a different location for it's config files
47 prefix =
48 exec_prefix =   ${prefix}
49 etcdir =        ${prefix}/etc
50 sbindir =       ${exec_prefix}/sbin
51 usrbindir =     ${exec_prefix}/usr/bin
52 mandir =        ${prefix}/usr/share/man
53 hotplugdir =    ${etcdir}/hotplug.d/default
54 configdir =     ${etcdir}/udev
55 initdir =       ${etcdir}/init.d
56 dev_ddir =      ${etcdir}/dev.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 # set up PWD so that older versions of make will work with our build.
76 PWD = $(shell pwd)
77
78 # If you are running a cross compiler, you may want to set this
79 # to something more interesting, like "arm-linux-".  If you want
80 # to compile vs uClibc, that can be done here as well.
81 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
82 CC = $(CROSS)gcc
83 LD = $(CROSS)gcc
84 AR = $(CROSS)ar
85 STRIP = $(CROSS)strip
86 RANLIB = $(CROSS)ranlib
87
88 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0
89
90 # code taken from uClibc to determine the current arch
91 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
92         -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
93
94 # code taken from uClibc to determine the gcc include dir
95 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
96
97 # code taken from uClibc to determine the libgcc.a filename
98 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
99
100 # use '-Os' optimization if available, else use -O2
101 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
102                 then echo "-Os"; else echo "-O2" ; fi}
103
104 # add -Wredundant-decls when libsysfs gets cleaned up
105 WARNINGS := -Wall 
106
107 # Some nice architecture specific optimizations
108 ifeq ($(strip $(TARGET_ARCH)),arm)
109         OPTIMIZATION+=-fstrict-aliasing
110 endif
111 ifeq ($(strip $(TARGET_ARCH)),i386)
112         OPTIMIZATION+=-march=i386
113         OPTIMIZATION += ${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \
114                 /dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi}
115         OPTIMIZATION += ${shell if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \
116                 /dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi}
117         CFLAGS+=-pipe -Dasmlinkage=__attribute__((regparm(0)))
118 else
119         CFLAGS+=-pipe -Dasmlinkage=
120 endif
121
122 ifeq ($(strip $(USE_LOG)),true)
123         CFLAGS  += -DLOG
124 endif
125
126 # if DEBUG is enabled, then we do not strip or optimize
127 ifeq ($(strip $(DEBUG)),true)
128         CFLAGS  += -O1 -g -DDEBUG -D_GNU_SOURCE
129         LDFLAGS += -Wl,-warn-common
130         STRIPCMD = /bin/true -Since_we_are_debugging
131 else
132         CFLAGS  += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
133         LDFLAGS += -s -Wl,-warn-common
134         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
135 endif
136
137 # If we are using our version of klibc, then we need to build, link it, and then
138 # link udev against it statically.
139 # Otherwise, use glibc and link dynamically.
140 ifeq ($(strip $(USE_KLIBC)),true)
141         KLIBC_BASE      = $(PWD)/klibc
142         KLIBC_DIR       = $(KLIBC_BASE)/klibc
143         INCLUDE_DIR     := $(KLIBC_BASE)/include
144         LINUX_INCLUDE_DIR       := $(KERNEL_DIR)/include
145         include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
146         # arch specific objects
147         ARCH_LIB_OBJS = \
148                         $(KLIBC_DIR)/libc.a
149
150
151         CRT0 = $(KLIBC_DIR)/crt0.o
152         LIBC = $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
153         CFLAGS += $(WARNINGS) -nostdinc                 \
154                 $(OPTFLAGS)                             \
155                 -D__KLIBC__ -fno-builtin-printf         \
156                 -I$(INCLUDE_DIR)                        \
157                 -I$(INCLUDE_DIR)/arch/$(ARCH)           \
158                 -I$(INCLUDE_DIR)/bits$(BITSIZE)         \
159                 -I$(GCCINCDIR)                          \
160                 -I$(LINUX_INCLUDE_DIR)
161         LIB_OBJS =
162         LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
163 else
164         WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
165         CRT0 =
166         LIBC =
167         CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
168         LIB_OBJS = -lc
169         LDFLAGS =
170 endif
171
172 CFLAGS += -I$(PWD)/libsysfs
173
174 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER)
175         @extras="$(EXTRAS)" ; for target in $$extras ; do \
176                 echo $$target ; \
177                 $(MAKE) prefix=$(prefix) \
178                         LD="$(LD)" \
179                         SYSFS="$(SYSFS)" \
180                         KERNEL_DIR="$(KERNEL_DIR)" \
181                         -C $$target $@ ; \
182         done ; \
183
184 $(ARCH_LIB_OBJS) : $(CRT0)
185
186 $(CRT0):
187         @if [ ! -r klibc/linux ]; then \
188                 ln -f -s $(KERNEL_DIR) klibc/linux; \
189         fi
190         $(MAKE) -C klibc SUBDIRS=klibc
191
192 TDB =   tdb/tdb.o       \
193         tdb/spinlock.o
194
195 SYSFS = $(PWD)/libsysfs/sysfs_bus.o     \
196         $(PWD)/libsysfs/sysfs_class.o   \
197         $(PWD)/libsysfs/sysfs_device.o  \
198         $(PWD)/libsysfs/sysfs_dir.o     \
199         $(PWD)/libsysfs/sysfs_driver.o  \
200         $(PWD)/libsysfs/sysfs_utils.o   \
201         $(PWD)/libsysfs/dlist.o
202
203 OBJS =  udev_lib.o      \
204         udev_config.o   \
205         udev-add.o      \
206         udev-remove.o   \
207         udevdb.o        \
208         namedev.o       \
209         namedev_parse.o \
210         dev_d.o         \
211         $(SYSFS)        \
212         $(TDB)
213
214 HEADERS =       udev.h          \
215                 udev_lib.h      \
216                 namedev.h       \
217                 udev_version.h  \
218                 udevdb.h        \
219                 klibc_fixups.h  \
220                 logging.h       \
221                 list.h
222
223 ifeq ($(strip $(USE_KLIBC)),true)
224         OBJS += klibc_fixups.o
225         KLIBC_FIXUP = klibc_fixups.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)/rules.d\" >> $@
239         @echo \#define UDEV_PERMISSION_FILE     \"$(configdir)/permissions.d\" >> $@
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 GEN_MANPAGES   = udev.8
252 GEN_MANPAGESIN = udev.8.in
253 # Rules on how to create the man pages
254 $(GEN_MANPAGES): $(GEN_MANPAGESIN)
255         sed -e "s:@udevdir@:$(udevdir):" < $@.in > $@
256
257
258 $(OBJS): $(GEN_HEADERS)
259 $(ROOT).o: $(GEN_HEADERS)
260 $(TESTER).o: $(GEN_HEADERS)
261 $(INFO).o: $(GEN_HEADERS)
262 $(DAEMON).o: $(GEN_HEADERS)
263 $(SENDER).o: $(GEN_HEADERS)
264 $(STARTER).o: $(GEN_HEADERS)
265
266 $(ROOT): $(LIBC) $(ROOT).o $(STARTER).o $(OBJS) $(HEADERS) $(GEN_MANPAGES)
267         $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o udevstart.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
268         $(STRIPCMD) $@
269
270 $(TESTER): $(LIBC) $(TESTER).o $(OBJS) $(HEADERS)
271         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevtest.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
272         $(STRIPCMD) $@
273
274 $(INFO): $(LIBC) $(INFO).o $(OBJS) $(HEADERS)
275         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_lib.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
276         $(STRIPCMD) $@
277
278 $(DAEMON): $(LIBC) $(DAEMON).o $(OBJS) udevd.h
279         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o udev_lib.o $(KLIBC_FIXUP) $(LIB_OBJS) $(ARCH_LIB_OBJS)
280         $(STRIPCMD) $@
281
282 $(SENDER): $(LIBC) $(SENDER).o $(OBJS) udevd.h
283         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o udev_lib.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
284         $(STRIPCMD) $@
285
286 $(RULER): $(LIBC) $(RULER).o $(OBJS) $(HEADERS)
287         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevruler.o udev_lib.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS) -lnewt
288         $(STRIPCMD) $@
289
290 clean:
291         -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
292          | xargs rm -f 
293         -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) $(SENDER) $(TESTER) $(RULER)
294         $(MAKE) -C klibc clean
295         @extras="$(EXTRAS)" ; for target in $$extras ; do \
296                 echo $$target ; \
297                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
298                         -C $$target $@ ; \
299         done ; \
300
301 spotless: clean
302         $(MAKE) -C klibc spotless
303         -rm -f klibc/linux
304
305 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 )
306 DISTDIR := $(RELEASE_NAME)
307 srcdir = .
308 release: clean
309         -rm -rf $(DISTDIR)
310         mkdir $(DISTDIR)
311         chmod 777 $(DISTDIR)
312         bk export $(DISTDIR)
313         tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
314         rm -rf $(DISTDIR)
315         @echo "$(RELEASE_NAME).tar.gz created"
316
317
318 small_release: $(DISTFILES) clean
319 #       @echo $(DISTFILES)
320         @-rm -rf $(DISTDIR)
321         @mkdir $(DISTDIR)
322         @-chmod 777 $(DISTDIR)
323         @for file in $(DISTFILES); do                   \
324                 if test -d $$file; then                 \
325                         mkdir $(DISTDIR)/$$file;        \
326                 else                                    \
327                         cp -p $$file $(DISTDIR)/$$file; \
328                 fi;                                     \
329         done
330         @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
331         @rm -rf $(DISTDIR)
332         @echo "Built $(RELEASE_NAME).tar.gz"
333
334
335 install-initscript: etc/init.d/udev etc/init.d/udev.debian etc/init.d/udev.init.LSB
336         @if [ -f /etc/redhat-release ]; then \
337                 $(INSTALL_DATA) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev; \
338         elif [ -f /etc/SuSE-release ]; then \
339                 $(INSTALL_DATA) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev; \
340         elif [ -f /etc/debian_version ]; then \
341                 $(INSTALL_DATA) -D etc/init.d/udev.debian $(DESTDIR)$(initdir)/udev; \
342         fi
343
344 install-config: $(GEN_CONFIGS)
345         $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
346         $(INSTALL) -d $(DESTDIR)$(configdir)/permissions.d
347         @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
348                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
349                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
350         fi
351         @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
352                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
353                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
354         fi
355         @if [ ! -r $(DESTDIR)$(configdir)/permissions.d/50-udev.permissions ]; then \
356                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir)/permissions.d/50-udev.permissions; \
357                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir)/permissions.d/50-udev.permissions; \
358         fi
359
360 install-dev.d:
361         $(INSTALL) -d $(DESTDIR)$(dev_ddir)/default
362         $(INSTALL_PROGRAM) -D etc/dev.d/net/hotplug.dev $(DESTDIR)$(dev_ddir)/net/hotplug.dev
363
364 uninstall-dev.d:
365         - rm $(dev_ddir)/net/hotplug.dev
366         - rmdir $(dev_ddir)/net
367         - rmdir $(dev_ddir)/default
368         - rmdir $(dev_ddir)
369
370 install-man:
371         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
372         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
373         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
374         $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
375         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
376         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
377
378 uninstall-man:
379         - rm $(mandir)/man8/udev.8
380         - rm $(mandir)/man8/udevinfo.8
381         - rm $(mandir)/man8/udevtest.8
382         - rm $(mandir)/man8/udevstart.8
383         - rm $(mandir)/man8/udevd.8
384         - rm $(mandir)/man8/udevsend.8
385
386 install: install-initscript install-config install-man install-dev.d all
387         $(INSTALL) -d $(DESTDIR)$(udevdir)
388         $(INSTALL) -d $(DESTDIR)$(hotplugdir)
389         $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
390         $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
391         $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
392         $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
393         $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
394         ln -sf $(sbindir)/udev $(DESTDIR)$(sbindir)/$(STARTER)
395         - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/10-udev.hotplug
396 ifndef DESTDIR
397         - killall udevd
398         - rm -f $(udevdir)/.udev.tdb
399 endif
400         @extras="$(EXTRAS)" ; for target in $$extras ; do \
401                 echo $$target ; \
402                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
403                         -C $$target $@ ; \
404         done ; \
405
406 uninstall: uninstall-man uninstall-dev.d
407         - rm $(hotplugdir)/10-udev.hotplug
408         - rm $(configdir)/rules.d/50-udev.rules
409         - rm $(configdir)/permissions.d/50-udev.permissions
410         - rm $(configdir)/udev.conf
411         - rmdir $(configdir)/rules.d
412         - rmdir $(configdir)/permissions.d
413         - rmdir $(configdir)
414         - rm $(initdir)/udev
415         - rm $(sbindir)/$(ROOT)
416         - rm $(sbindir)/$(DAEMON)
417         - rm $(sbindir)/$(SENDER)
418         - rm $(sbindir)/$(STARTER)
419         - rm $(usrbindir)/$(INFO)
420         - rm $(usrbindir)/$(TESTER)
421         - rmdir $(hotplugdir)
422         - rm $(udevdir)/.udev.tdb
423         - rmdir $(udevdir)
424         @extras="$(EXTRAS)" ; for target in $$extras ; do \
425                 echo $$target ; \
426                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
427                         -C $$target $@ ; \
428         done ; \