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