chiark / gitweb /
[PATCH] remove Makefile magic for klibc integration
[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 # Set this to compile with Security-Enhanced Linux support.
29 USE_SELINUX = false
30
31 ROOT =          udev
32 DAEMON =        udevd
33 SENDER =        udevsend
34 INFO =          udevinfo
35 TESTER =        udevtest
36 STARTER =       udevstart
37 VERSION =       054
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 usrbindir =     ${exec_prefix}/usr/bin
53 mandir =        ${prefix}/usr/share/man
54 hotplugdir =    ${etcdir}/hotplug.d/default
55 configdir =     ${etcdir}/udev
56 initdir =       ${etcdir}/init.d
57 dev_ddir =      ${etcdir}/dev.d
58 srcdir = .
59
60 INSTALL = /usr/bin/install -c
61 INSTALL_PROGRAM = ${INSTALL}
62 INSTALL_DATA  = ${INSTALL} -m 644
63 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
64
65 # To build any of the extras programs, run with:
66 #       make EXTRAS="extras/a extras/b" 
67 EXTRAS=
68
69 # place to put our device nodes
70 udevdir =       ${prefix}/udev
71 udevdb =        ${udevdir}/.udevdb
72
73 # Comment out this line to build with something other 
74 # than the local version of klibc
75 #USE_KLIBC = true
76
77 # make the build silent (well, at least the udev part)  Set this
78 # to something else to make it noisy again.
79 V=false
80
81 # set up PWD so that older versions of make will work with our build.
82 PWD = $(shell pwd)
83
84 # If you are running a cross compiler, you may want to set this
85 # to something more interesting, like "arm-linux-".  If you want
86 # to compile vs uClibc, that can be done here as well.
87 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
88 CC = $(CROSS)gcc
89 LD = $(CROSS)gcc
90 AR = $(CROSS)ar
91 STRIP = $(CROSS)strip
92 RANLIB = $(CROSS)ranlib
93 HOSTCC = gcc
94
95 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0
96
97 # code taken from uClibc to determine the current arch
98 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
99         -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
100
101 # code taken from uClibc to determine the gcc include dir
102 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
103
104 # code taken from uClibc to determine the libgcc.a filename
105 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
106
107 # use '-Os' optimization if available, else use -O2
108 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
109                 then echo "-Os"; else echo "-O2" ; fi}
110
111 # check if compiler option is supported
112 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
113
114 WARNINGS := -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith -Wstrict-prototypes -Wsign-compare
115 WARNINGS += $(call cc-supports,-Wno-pointer-sign)
116 WARNINGS += $(call cc-supports,-Wdeclaration-after-statement)
117
118 CFLAGS := -pipe
119
120 HEADERS = \
121         udev.h                  \
122         udev_utils.h            \
123         namedev.h               \
124         udev_version.h          \
125         udev_db.h               \
126         udev_sysfs.h            \
127         logging.h               \
128         udev_libc_wrapper.h     \
129         udev_selinux.h          \
130         list.h
131
132 SYSFS_OBJS = \
133         libsysfs/sysfs_class.o  \
134         libsysfs/sysfs_device.o \
135         libsysfs/sysfs_dir.o    \
136         libsysfs/sysfs_driver.o \
137         libsysfs/sysfs_utils.o  \
138         libsysfs/dlist.o
139
140 UDEV_OBJS = \
141         udev_utils.o            \
142         udev_config.o           \
143         udev_add.o              \
144         udev_remove.o           \
145         udev_start.o            \
146         udev_sysfs.o            \
147         udev_db.o               \
148         udev_multiplex.o        \
149         namedev.o               \
150         namedev_parse.o         \
151         udev_libc_wrapper.o
152
153 OBJS = \
154         udev.a                  \
155         libsysfs/sysfs.a
156
157 SYSFS = $(PWD)/libsysfs/sysfs.a
158
159 CFLAGS +=       -I$(PWD)/libsysfs/sysfs \
160                 -I$(PWD)/libsysfs
161
162 ifeq ($(strip $(USE_LOG)),true)
163         CFLAGS += -DLOG
164 endif
165
166 # if DEBUG is enabled, then we do not strip or optimize
167 ifeq ($(strip $(DEBUG)),true)
168         CFLAGS  += -O1 -g -DDEBUG -D_GNU_SOURCE
169         LDFLAGS += -Wl,-warn-common
170         STRIPCMD = /bin/true -Since_we_are_debugging
171 else
172         CFLAGS  += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
173         LDFLAGS += -s -Wl,-warn-common
174         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
175 endif
176
177 # If we are using our version of klibc, then we need to build, link it, and then
178 # link udev against it statically. Otherwise, use glibc and link dynamically.
179 ifeq ($(strip $(USE_KLIBC)),true)
180         KLIBC_BASE      = $(PWD)/klibc
181         KLIBC_DIR       = $(KLIBC_BASE)/klibc
182         INCLUDE_DIR     := $(KLIBC_BASE)/include
183         LINUX_INCLUDE_DIR       := $(KERNEL_DIR)/include
184         include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
185         # arch specific objects
186         ARCH_LIB_OBJS =  $(KLIBC_DIR)/libc.a
187
188
189         CRT0 = $(KLIBC_DIR)/crt0.o
190         LIBC = $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
191         CFLAGS += $(WARNINGS) -nostdinc                         \
192                 $(OPTFLAGS) $(REQFLAGS)                         \
193                 -D__KLIBC__ -fno-builtin-printf                 \
194                 -I$(INCLUDE_DIR)                                \
195                 -I$(INCLUDE_DIR)/arch/$(ARCH)                   \
196                 -I$(INCLUDE_DIR)/bits$(BITSIZE)                 \
197                 -I$(GCCINCDIR)                                  \
198                 -I$(LINUX_INCLUDE_DIR)
199         LIB_OBJS =
200         LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
201
202 else
203         WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
204         CRT0 =
205         LIBC =
206         CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
207         LIB_OBJS = -lc
208 endif
209
210 ifeq ($(strip $(USE_SELINUX)),true)
211         UDEV_OBJS += udev_selinux.o
212         LIB_OBJS += -lselinux
213         CFLAGS += -DUSE_SELINUX
214 endif
215
216 ifeq ($(strip $(V)),false)
217         QUIET=@$(PWD)/ccdv
218         HOST_PROGS=ccdv
219 else
220         QUIET=
221         HOST_PROGS=
222 endif
223
224 # config files automatically generated
225 GEN_CONFIGS =   $(LOCAL_CFG_DIR)/udev.conf
226
227 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(GEN_CONFIGS)
228         @extras="$(EXTRAS)" ; for target in $$extras ; do \
229                 echo $$target ; \
230                 $(MAKE) prefix=$(prefix) \
231                         LD="$(LD)" \
232                         SYSFS="$(SYSFS)" \
233                         KERNEL_DIR="$(KERNEL_DIR)" \
234                         QUIET="$(QUIET)" \
235                         -C $$target $@ ; \
236         done ; \
237
238 $(ARCH_LIB_OBJS) : $(CRT0)
239
240 $(CRT0):
241         @if [ ! -r klibc/linux ]; then \
242                 ln -f -s $(KERNEL_DIR) klibc/linux; \
243         fi
244         $(MAKE) -C klibc SUBDIRS=klibc TESTS=
245
246 udev.a: $(UDEV_OBJS)
247         rm -f $@
248         $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
249         $(QUIET) $(RANLIB) $@
250
251 libsysfs/sysfs.a: $(SYSFS_OBJS)
252         rm -f $@
253         $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
254         $(QUIET) $(RANLIB) $@
255
256 # header files automatically generated
257 GEN_HEADERS =   udev_version.h
258
259 ccdv:
260         @echo "Building ccdv"
261         @$(HOSTCC) -O1 ccdv.c -o ccdv
262
263 # Rules on how to create the generated header files
264 udev_version.h:
265         @echo "Creating udev_version.h"
266         @echo \#define UDEV_VERSION             \"$(VERSION)\" > $@
267         @echo \#define UDEV_ROOT                \"$(udevdir)\" >> $@
268         @echo \#define UDEV_DB                  \"$(udevdb)\" >> $@
269         @echo \#define UDEV_CONFIG_DIR          \"$(configdir)\" >> $@
270         @echo \#define UDEV_CONFIG_FILE         \"$(configdir)/udev.conf\" >> $@
271         @echo \#define UDEV_RULES_FILE          \"$(configdir)/rules.d\" >> $@
272         @echo \#define UDEV_LOG_DEFAULT         \"yes\" >> $@
273         @echo \#define UDEV_BIN                 \"$(DESTDIR)$(sbindir)/udev\" >> $@
274         @echo \#define UDEVD_BIN                \"$(DESTDIR)$(sbindir)/udevd\" >> $@
275
276 # Rules on how to create the generated config files
277 $(LOCAL_CFG_DIR)/udev.conf:
278         sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
279
280 GEN_MANPAGES   = udev.8
281 GEN_MANPAGESIN = udev.8.in
282 # Rules on how to create the man pages
283 $(GEN_MANPAGES): $(GEN_MANPAGESIN)
284         sed -e "s:@udevdir@:$(udevdir):" < $@.in > $@
285
286 $(UDEV_OBJS): $(GEN_HEADERS) $(HOST_PROGS)
287 $(SYSFS_OBJS): $(HOST_PROGS)
288 $(OBJS): $(GEN_HEADERS) $(HOST_PROGS)
289 $(ROOT).o: $(GEN_HEADERS) $(HOST_PROGS)
290 $(TESTER).o: $(GEN_HEADERS) $(HOST_PROGS)
291 $(INFO).o: $(GEN_HEADERS) $(HOST_PROGS)
292 $(DAEMON).o: $(GEN_HEADERS) $(HOST_PROGS)
293 $(SENDER).o: $(GEN_HEADERS) $(HOST_PROGS)
294 $(STARTER).o: $(GEN_HEADERS) $(HOST_PROGS)
295
296 $(ROOT): $(LIBC) $(ROOT).o $(OBJS) $(HEADERS) $(GEN_MANPAGES)
297         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(ROOT).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
298         $(QUIET) $(STRIPCMD) $@
299
300 $(TESTER): $(LIBC) $(TESTER).o $(OBJS) $(HEADERS)
301         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(TESTER).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
302         $(QUIET) $(STRIPCMD) $@
303
304 $(INFO): $(LIBC) $(INFO).o $(OBJS) $(HEADERS)
305         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(INFO).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
306         $(QUIET) $(STRIPCMD) $@
307
308 $(DAEMON): $(LIBC) $(DAEMON).o $(OBJS) udevd.h
309         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(DAEMON).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
310         $(QUIET) $(STRIPCMD) $@
311
312 $(SENDER): $(LIBC) $(SENDER).o $(OBJS) udevd.h
313         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(CRT0) $(SENDER).o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
314         $(QUIET) $(STRIPCMD) $@
315
316 .c.o:
317         $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
318
319
320 clean:
321         -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
322          | xargs rm -f 
323         -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) $(SENDER) $(TESTER)
324         -rm -f ccdv
325         $(MAKE) -C klibc SUBDIRS=klibc clean
326         @extras="$(EXTRAS)" ; for target in $$extras ; do \
327                 echo $$target ; \
328                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
329                         -C $$target $@ ; \
330         done ; \
331
332 spotless: clean
333         $(MAKE) -C klibc SUBDIRS=klibc spotless
334         -rm -f klibc/linux
335
336 DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v -e CVS -e "\.tar\.gz" -e "\/\." -e releases -e BitKeeper -e SCCS -e test/sys | sort )
337 DISTDIR := $(RELEASE_NAME)
338 srcdir = .
339 release: spotless
340         -rm -rf $(DISTDIR)
341         mkdir $(DISTDIR)
342         chmod 777 $(DISTDIR)
343         bk export -w $(DISTDIR)
344         tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
345         rm -rf $(DISTDIR)
346         @echo "$(RELEASE_NAME).tar.gz created"
347
348
349 small_release: $(DISTFILES) spotless
350 #       @echo $(DISTFILES)
351         @-rm -rf $(DISTDIR)
352         @mkdir $(DISTDIR)
353         @-chmod 777 $(DISTDIR)
354         @for file in $(DISTFILES); do                   \
355                 if test -d $$file; then                 \
356                         mkdir $(DISTDIR)/$$file;        \
357                 else                                    \
358                         cp -p $$file $(DISTDIR)/$$file; \
359                 fi;                                     \
360         done
361         @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
362         @rm -rf $(DISTDIR)
363         @echo "Built $(RELEASE_NAME).tar.gz"
364
365 install-config:
366         $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
367         @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
368                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
369                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
370         fi
371         @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
372                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
373                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
374         fi
375
376 install-dev.d:
377         $(INSTALL) -d $(DESTDIR)$(dev_ddir)/default
378         $(INSTALL_PROGRAM) -D etc/dev.d/net/hotplug.dev $(DESTDIR)$(dev_ddir)/net/hotplug.dev
379
380 uninstall-dev.d:
381         - rm $(dev_ddir)/net/hotplug.dev
382         - rmdir $(dev_ddir)/net
383         - rmdir $(dev_ddir)/default
384         - rmdir $(dev_ddir)
385
386 install-man:
387         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
388         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
389         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
390         $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
391         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
392         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
393
394 uninstall-man:
395         - rm $(mandir)/man8/udev.8
396         - rm $(mandir)/man8/udevinfo.8
397         - rm $(mandir)/man8/udevtest.8
398         - rm $(mandir)/man8/udevstart.8
399         - rm $(mandir)/man8/udevd.8
400         - rm $(mandir)/man8/udevsend.8
401
402 install: install-config install-man install-dev.d all
403         $(INSTALL) -d $(DESTDIR)$(udevdir)
404         $(INSTALL) -d $(DESTDIR)$(hotplugdir)
405         $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
406         $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
407         $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
408         $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
409         $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
410         - ln -f -s $(sbindir)/udev $(DESTDIR)$(sbindir)/$(STARTER)
411         - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/10-udev.hotplug
412 ifndef DESTDIR
413         - killall $(DAEMON)
414         - rm -rf $(udevdb)
415 endif
416         @extras="$(EXTRAS)" ; for target in $$extras ; do \
417                 echo $$target ; \
418                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
419                         -C $$target $@ ; \
420         done ; \
421
422 uninstall: uninstall-man uninstall-dev.d
423         - rm $(hotplugdir)/10-udev.hotplug
424         - rm $(configdir)/rules.d/50-udev.rules
425         - rm $(configdir)/udev.conf
426         - rmdir $(configdir)/rules.d
427         - rmdir $(configdir)
428         - rm $(sbindir)/$(ROOT)
429         - rm $(sbindir)/$(DAEMON)
430         - rm $(sbindir)/$(SENDER)
431         - rm $(sbindir)/$(STARTER)
432         - rm $(usrbindir)/$(INFO)
433         - rm $(usrbindir)/$(TESTER)
434         - rmdir $(hotplugdir)
435         - rm -rf $(udevdb)
436         - rmdir $(udevdir)
437         - killall $(DAEMON)
438         @extras="$(EXTRAS)" ; for target in $$extras ; do \
439                 echo $$target ; \
440                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
441                         -C $$target $@ ; \
442         done ; \
443
444 test: all
445         @ cd test && ./udev-test.pl