chiark / gitweb /
[PATCH] Add 'asmlinkage' to udev-030
[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
29 ROOT =          udev
30 DAEMON =        udevd
31 SENDER =        udevsend
32 INFO =          udevinfo
33 TESTER =        udevtest
34 STARTER =       udevstart
35 RULER =         udevruler
36 VERSION =       030
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_DIR)/include
144         LINUX_INCLUDE_DIR       := $(KERNEL_DIR)/include
145 #       LINUX_INCLUDE_DIR       := $(KLIBC_BASE)/linux/include
146         include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
147         # arch specific objects
148         ARCH_LIB_OBJS = \
149                         $(KLIBC_DIR)/libc.a
150
151
152         CRT0 = $(KLIBC_DIR)/crt0.o
153         LIBC =  $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
154         CFLAGS += $(WARNINGS) -nostdinc                 \
155                 $(OPTFLAGS)                             \
156                 -D__KLIBC__ -fno-builtin-printf         \
157                 -I$(INCLUDE_DIR)                        \
158                 -I$(KLIBC_DIR)/arch/$(ARCH)/include     \
159                 -I$(INCLUDE_DIR)/bits$(BITSIZE)         \
160                 -I$(GCCINCDIR)                          \
161                 -I$(LINUX_INCLUDE_DIR)
162         LIB_OBJS =
163         LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
164 else
165         WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
166         CRT0 =
167         LIBC = 
168         CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
169         LIB_OBJS = -lc
170         LDFLAGS =
171 endif
172
173 CFLAGS += -I$(PWD)/libsysfs
174
175 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(STARTER)
176         @extras="$(EXTRAS)" ; for target in $$extras ; do \
177                 echo $$target ; \
178                 $(MAKE) prefix=$(prefix) \
179                         LD="$(LD)" \
180                         SYSFS="$(SYSFS)" \
181                         KERNEL_DIR="$(KERNEL_DIR)" \
182                         -C $$target $@ ; \
183         done ; \
184
185 $(ARCH_LIB_OBJS) : $(CRT0)
186
187 $(CRT0):
188         $(MAKE) -C klibc KERNEL_DIR=$(KERNEL_DIR)
189
190 TDB =   tdb/tdb.o       \
191         tdb/spinlock.o
192
193 SYSFS = $(PWD)/libsysfs/sysfs_bus.o     \
194         $(PWD)/libsysfs/sysfs_class.o   \
195         $(PWD)/libsysfs/sysfs_device.o  \
196         $(PWD)/libsysfs/sysfs_dir.o     \
197         $(PWD)/libsysfs/sysfs_driver.o  \
198         $(PWD)/libsysfs/sysfs_utils.o   \
199         $(PWD)/libsysfs/dlist.o
200
201 OBJS =  udev_lib.o      \
202         udev_config.o   \
203         udev-add.o      \
204         udev-remove.o   \
205         udevdb.o        \
206         namedev.o       \
207         namedev_parse.o \
208         dev_d.o         \
209         $(SYSFS)        \
210         $(TDB)
211
212 HEADERS =       udev.h          \
213                 udev_lib.h      \
214                 namedev.h       \
215                 udev_version.h  \
216                 udevdb.h        \
217                 klibc_fixups.h  \
218                 logging.h       \
219                 list.h
220
221 ifeq ($(strip $(USE_KLIBC)),true)
222         OBJS += klibc_fixups.o
223         KLIBC_FIXUP = klibc_fixups.o
224 endif
225
226 # header files automatically generated
227 GEN_HEADERS =   udev_version.h
228
229 # Rules on how to create the generated header files
230 udev_version.h:
231         @echo \#define UDEV_VERSION             \"$(VERSION)\" > $@
232         @echo \#define UDEV_ROOT                \"$(udevdir)/\" >> $@
233         @echo \#define UDEV_DB                  \"$(udevdir)/.udev.tdb\" >> $@
234         @echo \#define UDEV_CONFIG_DIR          \"$(configdir)\" >> $@
235         @echo \#define UDEV_CONFIG_FILE         \"$(configdir)/udev.conf\" >> $@
236         @echo \#define UDEV_RULES_FILE          \"$(configdir)/rules.d\" >> $@
237         @echo \#define UDEV_PERMISSION_FILE     \"$(configdir)/permissions.d\" >> $@
238         @echo \#define UDEV_LOG_DEFAULT         \"yes\" >> $@
239         @echo \#define UDEV_BIN                 \"$(DESTDIR)$(sbindir)/udev\" >> $@
240         @echo \#define UDEVD_BIN                \"$(DESTDIR)$(sbindir)/udevd\" >> $@
241
242 # config files automatically generated
243 GEN_CONFIGS =   $(LOCAL_CFG_DIR)/udev.conf
244
245 # Rules on how to create the generated config files
246 $(LOCAL_CFG_DIR)/udev.conf:
247         sed -e "s:@udevdir@:$(udevdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
248
249 GEN_MANPAGES   = udev.8
250 GEN_MANPAGESIN = udev.8.in
251 # Rules on how to create the man pages
252 $(GEN_MANPAGES): $(GEN_MANPAGESIN)
253         sed -e "s:@udevdir@:$(udevdir):" < $@.in > $@
254
255
256 $(OBJS): $(GEN_HEADERS)
257 $(ROOT).o: $(GEN_HEADERS)
258 $(TESTER).o: $(GEN_HEADERS)
259 $(INFO).o: $(GEN_HEADERS)
260 $(DAEMON).o: $(GEN_HEADERS)
261 $(SENDER).o: $(GEN_HEADERS)
262 $(STARTER).o: $(GEN_HEADERS)
263
264 $(ROOT): $(ROOT).o $(OBJS) $(HEADERS) $(LIBC) $(GEN_MANPAGES)
265         $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
266         $(STRIPCMD) $@
267
268 $(TESTER): $(TESTER).o $(OBJS) $(HEADERS) $(LIBC)
269         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevtest.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
270         $(STRIPCMD) $@
271
272 $(INFO): $(INFO).o $(OBJS) $(HEADERS) $(LIBC)
273         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_lib.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
274         $(STRIPCMD) $@
275
276 $(DAEMON): $(DAEMON).o $(OBJS) udevd.h $(LIBC)
277         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevd.o udev_lib.o $(KLIBC_FIXUP) $(LIB_OBJS) $(ARCH_LIB_OBJS)
278         $(STRIPCMD) $@
279
280 $(SENDER): $(SENDER).o udevd.h $(LIBC)
281         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o udev_lib.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
282         $(STRIPCMD) $@
283
284 $(STARTER): $(STARTER).o $(HEADERS) $(LIBC)
285         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevstart.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
286         $(STRIPCMD) $@
287
288 $(RULER): $(RULER).o $(OBJS) $(HEADERS) $(LIBC)
289         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevruler.o udev_lib.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS) -lnewt
290         $(STRIPCMD) $@
291
292 clean:
293         -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
294          | xargs rm -f 
295         -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) $(SENDER) $(TESTER) $(STARTER) $(RULER)
296         $(MAKE) -C klibc clean
297         @extras="$(EXTRAS)" ; for target in $$extras ; do \
298                 echo $$target ; \
299                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
300                         -C $$target $@ ; \
301         done ; \
302
303 spotless: clean
304         $(MAKE) -C klibc spotless
305
306 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 )
307 DISTDIR := $(RELEASE_NAME)
308 srcdir = .
309 release: clean
310         -rm -rf $(DISTDIR)
311         mkdir $(DISTDIR)
312         chmod 777 $(DISTDIR)
313         bk export $(DISTDIR)
314         tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
315         rm -rf $(DISTDIR)
316         @echo "$(RELEASE_NAME).tar.gz created"
317
318
319 small_release: $(DISTFILES) clean
320 #       @echo $(DISTFILES)
321         @-rm -rf $(DISTDIR)
322         @mkdir $(DISTDIR)
323         @-chmod 777 $(DISTDIR)
324         @for file in $(DISTFILES); do                   \
325                 if test -d $$file; then                 \
326                         mkdir $(DISTDIR)/$$file;        \
327                 else                                    \
328                         cp -p $$file $(DISTDIR)/$$file; \
329                 fi;                                     \
330         done
331         @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
332         @rm -rf $(DISTDIR)
333         @echo "Built $(RELEASE_NAME).tar.gz"
334
335
336 install-initscript: etc/init.d/udev etc/init.d/udev.debian etc/init.d/udev.init.LSB
337         @if [ -f /etc/redhat-release ]; then \
338                 $(INSTALL_DATA) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev; \
339         elif [ -f /etc/SuSE-release ]; then \
340                 $(INSTALL_DATA) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev; \
341         elif [ -f /etc/debian_version ]; then \
342                 $(INSTALL_DATA) -D etc/init.d/udev.debian $(DESTDIR)$(initdir)/udev; \
343         fi
344
345 install-config: $(GEN_CONFIGS)
346         $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
347         $(INSTALL) -d $(DESTDIR)$(configdir)/permissions.d
348         @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
349                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
350                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
351         fi
352         @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
353                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
354                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
355         fi
356         @if [ ! -r $(DESTDIR)$(configdir)/permissions.d/50-udev.permissions ]; then \
357                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir)/permissions.d/50-udev.permissions; \
358                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir)/permissions.d/50-udev.permissions; \
359         fi
360
361 install-dev.d:
362         $(INSTALL) -d $(DESTDIR)$(dev_ddir)/default
363         $(INSTALL_PROGRAM) -D etc/dev.d/net/hotplug.dev $(DESTDIR)$(dev_ddir)/net/hotplug.dev
364
365 uninstall-dev.d:
366         - rm $(dev_ddir)/net/hotplug.dev
367         - rmdir $(dev_ddir)/net
368         - rmdir $(dev_ddir)/default
369         - rmdir $(dev_ddir)
370
371 install-man:
372         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
373         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
374         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
375         $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
376         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
377         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
378
379 uninstall-man:
380         - rm $(mandir)/man8/udev.8
381         - rm $(mandir)/man8/udevinfo.8
382         - rm $(mandir)/man8/udevtest.8
383         - rm $(mandir)/man8/udevstart.8
384         - rm $(mandir)/man8/udevd.8
385         - rm $(mandir)/man8/udevsend.8
386
387 install: install-initscript install-config install-man install-dev.d all
388         $(INSTALL) -d $(DESTDIR)$(udevdir)
389         $(INSTALL) -d $(DESTDIR)$(hotplugdir)
390         $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
391         $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
392         $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
393         $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
394         $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
395         $(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
396         - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/$(ROOT).hotplug
397 ifndef DESTDIR
398         - killall udevd
399         - rm -f $(udevdir)/.udev.tdb
400 endif
401         @extras="$(EXTRAS)" ; for target in $$extras ; do \
402                 echo $$target ; \
403                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
404                         -C $$target $@ ; \
405         done ; \
406
407 uninstall: uninstall-man uninstall-dev.d
408         - rm $(hotplugdir)/udev.hotplug
409         - rm $(configdir)/rules.d/50-udev.rules
410         - rm $(configdir)/permissions.d/50-udev.permissions
411         - rm $(configdir)/udev.conf
412         - rmdir $(configdir)/rules.d
413         - rmdir $(configdir)/permissions.d
414         - rmdir $(configdir)
415         - rm $(initdir)/udev
416         - rm $(sbindir)/$(ROOT)
417         - rm $(sbindir)/$(DAEMON)
418         - rm $(sbindir)/$(SENDER)
419         - rm $(sbindir)/$(STARTER)
420         - rm $(usrbindir)/$(INFO)
421         - rm $(usrbindir)/$(TESTER)
422         - rmdir $(hotplugdir)
423         - rm $(udevdir)/.udev.tdb
424         - rmdir $(udevdir)
425         @extras="$(EXTRAS)" ; for target in $$extras ; do \
426                 echo $$target ; \
427                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
428                         -C $$target $@ ; \
429         done ; \