chiark / gitweb /
[PATCH] udev-test.pl: add check for textual uid/gid
[elogind.git] / Makefile
1 # Makefile for udev
2 #
3 # Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
4 # Copyright (C) 2004-2005 Kay Sievers <kay.sievers@vrfy.org>
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; version 2 of the License.
9 #
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 # General Public License for more details.
14 #
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the Free Software
17 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #
19
20 # Set this to make use of syslog
21 USE_LOG = true
22
23 # Set this to ad development debug messages
24 DEBUG = false
25
26 # Set this to include Security-Enhanced Linux support.
27 USE_SELINUX = false
28
29 # Set this to comile with the local version of klibc instead of glibc.
30 USE_KLIBC = false
31
32 # Set this to create statically linked binaries.
33 USE_STATIC = false
34
35 # To build any of the extras programs, run with:
36 #       make EXTRAS="extras/a extras/b"
37 EXTRAS=
38
39 # make the build silent. Set this to something else to make it noisy again.
40 V=false
41
42 ROOT =          udev
43 DAEMON =        udevd
44 SENDER =        udevsend
45 INFO =          udevinfo
46 TESTER =        udevtest
47 STARTER =       udevstart
48 VERSION =       055
49 INSTALL_DIR =   /usr/local/bin
50 RELEASE_NAME =  $(ROOT)-$(VERSION)
51 LOCAL_CFG_DIR = etc/udev
52 HOTPLUG_EXEC =  $(ROOT)
53 DESTDIR =
54 KERNEL_DIR = /lib/modules/${shell uname -r}/build
55
56 # override this to make udev look in a different location for it's config files
57 prefix =
58 exec_prefix =   ${prefix}
59 etcdir =        ${prefix}/etc
60 sbindir =       ${exec_prefix}/sbin
61 usrbindir =     ${exec_prefix}/usr/bin
62 mandir =        ${prefix}/usr/share/man
63 hotplugdir =    ${etcdir}/hotplug.d/default
64 configdir =     ${etcdir}/udev
65 initdir =       ${etcdir}/init.d
66 dev_ddir =      ${etcdir}/dev.d
67 srcdir = .
68
69 INSTALL = /usr/bin/install -c
70 INSTALL_PROGRAM = ${INSTALL}
71 INSTALL_DATA  = ${INSTALL} -m 644
72 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
73
74 # place to put our device nodes
75 udevdir =       ${prefix}/udev
76 udevdb =        ${udevdir}/.udevdb
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 HOSTCC = gcc
91
92 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
93
94 # code taken from uClibc to determine the current arch
95 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
96         -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
97
98 # code taken from uClibc to determine the gcc include dir
99 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
100
101 # code taken from uClibc to determine the libgcc.a filename
102 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
103
104 # use '-Os' optimization if available, else use -O2
105 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
106                 then echo "-Os"; else echo "-O2" ; fi}
107
108 # check if compiler option is supported
109 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; fi;}
110
111 CFLAGS          += -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith -Wstrict-prototypes -Wsign-compare
112 CFLAGS          += $(call cc-supports,-Wno-pointer-sign)
113 CFLAGS          += $(call cc-supports,-Wdeclaration-after-statement)
114 CFLAGS          += -pipe
115 CFLAGS          += -D_GNU_SOURCE
116
117 HEADERS = \
118         udev.h                  \
119         udev_utils.h            \
120         udev_rules.h            \
121         udev_version.h          \
122         udev_db.h               \
123         udev_sysfs.h            \
124         logging.h               \
125         udev_libc_wrapper.h     \
126         udev_selinux.h          \
127         list.h
128
129 SYSFS_OBJS = \
130         libsysfs/sysfs_class.o  \
131         libsysfs/sysfs_device.o \
132         libsysfs/sysfs_dir.o    \
133         libsysfs/sysfs_driver.o \
134         libsysfs/sysfs_utils.o  \
135         libsysfs/dlist.o
136
137 UDEV_OBJS = \
138         udev_utils.o            \
139         udev_config.o           \
140         udev_add.o              \
141         udev_remove.o           \
142         udev_sysfs.o            \
143         udev_db.o               \
144         udev_multiplex.o        \
145         udev_rules.o            \
146         udev_rules_parse.o      \
147         udev_libc_wrapper.o
148
149 OBJS = \
150         udev.a                  \
151         libsysfs/sysfs.a
152
153 SYSFS = $(PWD)/libsysfs/sysfs.a
154
155 CFLAGS +=       -I$(PWD)/libsysfs/sysfs \
156                 -I$(PWD)/libsysfs
157
158 ifeq ($(strip $(USE_LOG)),true)
159         CFLAGS += -DUSE_LOG
160 endif
161
162 # if DEBUG is enabled, then we do not strip or optimize
163 ifeq ($(strip $(DEBUG)),true)
164         CFLAGS  += -O1 -g -DDEBUG
165         LDFLAGS += -Wl
166         STRIPCMD = /bin/true -Since_we_are_debugging
167 else
168         CFLAGS  += $(OPTIMIZATION) -fomit-frame-pointer
169         LDFLAGS += -s -Wl
170         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
171 endif
172
173 # If we are using our version of klibc, then we need to build, link it, and then
174 # link udev against it statically. Otherwise, use glibc and link dynamically.
175 ifeq ($(strip $(USE_KLIBC)),true)
176         KLIBC_INSTALL   = $(PWD)/klibc/.install
177         KLCC            = $(KLIBC_INSTALL)/bin/klcc
178         CC              = $(KLCC)
179         LD              = $(KLCC)
180         LDFLAGS         += -static
181 else
182         CFLAGS          += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
183 endif
184
185 ifeq ($(strip $(USE_SELINUX)),true)
186         UDEV_OBJS += udev_selinux.o
187         LIB_OBJS += -lselinux
188         CFLAGS += -DUSE_SELINUX
189 endif
190
191 ifeq ($(strip $(USE_STATIC)),true)
192         CFLAGS += -DUSE_STATIC
193         LDFLAGS += -static
194 endif
195
196 ifeq ($(strip $(V)),false)
197         QUIET=@$(PWD)/ccdv
198         HOST_PROGS=ccdv
199 else
200         QUIET=
201         HOST_PROGS=
202 endif
203
204 # config files automatically generated
205 GEN_CONFIGS =   $(LOCAL_CFG_DIR)/udev.conf
206
207 all: $(ROOT) $(SENDER) $(DAEMON) $(INFO) $(TESTER) $(STARTER) $(GEN_CONFIGS) $(KLCC)
208         @extras="$(EXTRAS)" ; for target in $$extras ; do \
209                 echo $$target ; \
210                 $(MAKE) prefix=$(prefix) \
211                         LD="$(LD)" \
212                         SYSFS="$(SYSFS)" \
213                         KERNEL_DIR="$(KERNEL_DIR)" \
214                         QUIET="$(QUIET)" \
215                         -C $$target $@ ; \
216         done ; \
217
218 $(KLCC):
219         $(MAKE) -C klibc KRNLSRC=$(KERNEL_DIR) SUBDIRS=klibc TESTS= \
220                          SHLIBDIR=$(KLIBC_INSTALL)/lib \
221                          INSTALLDIR=$(KLIBC_INSTALL) \
222                          bindir=$(KLIBC_INSTALL)/bin \
223                          mandir=$(KLIBC_INSTALL)/man all install
224
225 udev.a: $(UDEV_OBJS)
226         rm -f $@
227         $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
228         $(QUIET) $(RANLIB) $@
229
230 libsysfs/sysfs.a: $(SYSFS_OBJS)
231         rm -f $@
232         $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
233         $(QUIET) $(RANLIB) $@
234
235 # header files automatically generated
236 GEN_HEADERS =   udev_version.h
237
238 ccdv:
239         @echo "Building ccdv"
240         @$(HOSTCC) -O1 ccdv.c -o ccdv
241
242 # Rules on how to create the generated header files
243 udev_version.h:
244         @echo "Creating udev_version.h"
245         @echo \#define UDEV_VERSION             \"$(VERSION)\" > $@
246         @echo \#define UDEV_ROOT                \"$(udevdir)\" >> $@
247         @echo \#define UDEV_DB                  \"$(udevdb)\" >> $@
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_LOG_DEFAULT         \"yes\" >> $@
252         @echo \#define UDEV_BIN                 \"$(DESTDIR)$(sbindir)/udev\" >> $@
253         @echo \#define UDEVD_BIN                \"$(DESTDIR)$(sbindir)/udevd\" >> $@
254
255 # Rules on how to create the generated config files
256 $(LOCAL_CFG_DIR)/udev.conf:
257         sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
258
259 GEN_MANPAGES   = udev.8
260 GEN_MANPAGESIN = udev.8.in
261 # Rules on how to create the man pages
262 $(GEN_MANPAGES): $(GEN_MANPAGESIN)
263         sed -e "s:@udevdir@:$(udevdir):" < $@.in > $@
264
265 $(UDEV_OBJS): $(GEN_HEADERS) $(HOST_PROGS)
266 $(SYSFS_OBJS): $(HOST_PROGS)
267 $(OBJS): $(GEN_HEADERS) $(HOST_PROGS)
268 $(ROOT).o: $(GEN_HEADERS) $(HOST_PROGS)
269 $(TESTER).o: $(GEN_HEADERS) $(HOST_PROGS)
270 $(INFO).o: $(GEN_HEADERS) $(HOST_PROGS)
271 $(DAEMON).o: $(GEN_HEADERS) $(HOST_PROGS)
272 $(SENDER).o: $(GEN_HEADERS) $(HOST_PROGS)
273 $(STARTER).o: $(GEN_HEADERS) $(HOST_PROGS)
274
275 $(ROOT): $(KLCC) $(ROOT).o $(OBJS) $(HEADERS) $(GEN_MANPAGES)
276         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(ROOT).o $(OBJS) $(LIB_OBJS)
277         $(QUIET) $(STRIPCMD) $@
278
279 $(TESTER): $(KLCC) $(TESTER).o $(OBJS) $(HEADERS)
280         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(TESTER).o $(OBJS) $(LIB_OBJS)
281         $(QUIET) $(STRIPCMD) $@
282
283 $(INFO): $(KLCC) $(INFO).o $(OBJS) $(HEADERS)
284         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(INFO).o $(OBJS) $(LIB_OBJS)
285         $(QUIET) $(STRIPCMD) $@
286
287 $(DAEMON): $(KLCC) $(DAEMON).o $(OBJS) udevd.h
288         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(DAEMON).o $(OBJS) $(LIB_OBJS)
289         $(QUIET) $(STRIPCMD) $@
290
291 $(SENDER): $(KLCC) $(SENDER).o $(OBJS) udevd.h
292         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(SENDER).o $(OBJS) $(LIB_OBJS)
293         $(QUIET) $(STRIPCMD) $@
294
295 $(STARTER): $(KLCC) $(STARTER).o $(OBJS)
296         $(QUIET) $(LD) $(LDFLAGS) -o $@ $(STARTER).o $(OBJS) $(LIB_OBJS)
297         $(QUIET) $(STRIPCMD) $@
298
299 .c.o:
300         $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
301
302 clean:
303         -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
304          | xargs rm -f 
305         -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(GEN_MANPAGES) $(INFO) $(DAEMON) \
306          $(SENDER) $(TESTER) $(STARTER)
307         -rm -f ccdv
308         $(MAKE) -C klibc SUBDIRS=klibc clean
309         @extras="$(EXTRAS)" ; for target in $$extras ; do \
310                 echo $$target ; \
311                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
312                         -C $$target $@ ; \
313         done ; \
314
315 spotless: clean
316         $(MAKE) -C klibc SUBDIRS=klibc spotless
317         rm -rf klibc/.install
318
319 DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v -e CVS -e "\.tar\.gz" -e "\/\." -e releases -e BitKeeper -e SCCS -e test/sys | sort )
320 DISTDIR := $(RELEASE_NAME)
321 srcdir = .
322 release: spotless
323         -rm -rf $(DISTDIR)
324         mkdir $(DISTDIR)
325         chmod 777 $(DISTDIR)
326         bk export -w $(DISTDIR)
327         tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
328         rm -rf $(DISTDIR)
329         @echo "$(RELEASE_NAME).tar.gz created"
330
331
332 small_release: $(DISTFILES) spotless
333 #       @echo $(DISTFILES)
334         @-rm -rf $(DISTDIR)
335         @mkdir $(DISTDIR)
336         @-chmod 777 $(DISTDIR)
337         @for file in $(DISTFILES); do                   \
338                 if test -d $$file; then                 \
339                         mkdir $(DISTDIR)/$$file;        \
340                 else                                    \
341                         cp -p $$file $(DISTDIR)/$$file; \
342                 fi;                                     \
343         done
344         @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
345         @rm -rf $(DISTDIR)
346         @echo "Built $(RELEASE_NAME).tar.gz"
347
348 install-config:
349         $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
350         @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
351                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
352                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
353         fi
354         @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
355                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
356                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir)/rules.d/50-udev.rules; \
357         fi
358
359 install-dev.d:
360         $(INSTALL) -d $(DESTDIR)$(dev_ddir)/default
361         $(INSTALL_PROGRAM) -D etc/dev.d/net/hotplug.dev $(DESTDIR)$(dev_ddir)/net/hotplug.dev
362
363 uninstall-dev.d:
364         - rm $(dev_ddir)/net/hotplug.dev
365         - rmdir $(dev_ddir)/net
366         - rmdir $(dev_ddir)/default
367         - rmdir $(dev_ddir)
368
369 install-man:
370         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
371         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
372         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
373         $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
374         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
375         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevsend.8
376
377 uninstall-man:
378         - rm $(mandir)/man8/udev.8
379         - rm $(mandir)/man8/udevinfo.8
380         - rm $(mandir)/man8/udevtest.8
381         - rm $(mandir)/man8/udevstart.8
382         - rm $(mandir)/man8/udevd.8
383         - rm $(mandir)/man8/udevsend.8
384
385 install: install-config install-man install-dev.d all
386         $(INSTALL) -d $(DESTDIR)$(udevdir)
387         $(INSTALL) -d $(DESTDIR)$(hotplugdir)
388         $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
389         $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
390         $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
391         $(INSTALL_PROGRAM) -D $(INFO) $(DESTDIR)$(usrbindir)/$(INFO)
392         $(INSTALL_PROGRAM) -D $(TESTER) $(DESTDIR)$(usrbindir)/$(TESTER)
393         $(INSTALL_PROGRAM) -D $(STARTER) $(DESTDIR)$(sbindir)/$(STARTER)
394         - ln -f -s $(sbindir)/$(SENDER) $(DESTDIR)$(hotplugdir)/10-udev.hotplug
395 ifndef DESTDIR
396         - killall $(DAEMON)
397         - rm -rf $(udevdb)
398 endif
399         @extras="$(EXTRAS)" ; for target in $$extras ; do \
400                 echo $$target ; \
401                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
402                         -C $$target $@ ; \
403         done ; \
404
405 uninstall: uninstall-man uninstall-dev.d
406         - rm $(hotplugdir)/10-udev.hotplug
407         - rm $(configdir)/rules.d/50-udev.rules
408         - rm $(configdir)/udev.conf
409         - rmdir $(configdir)/rules.d
410         - rmdir $(configdir)
411         - rm $(sbindir)/$(ROOT)
412         - rm $(sbindir)/$(DAEMON)
413         - rm $(sbindir)/$(SENDER)
414         - rm $(sbindir)/$(STARTER)
415         - rm $(usrbindir)/$(INFO)
416         - rm $(usrbindir)/$(TESTER)
417         - rmdir $(hotplugdir)
418         - rm -rf $(udevdb)
419         - rmdir $(udevdir)
420         - killall $(DAEMON)
421         @extras="$(EXTRAS)" ; for target in $$extras ; do \
422                 echo $$target ; \
423                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
424                         -C $$target $@ ; \
425         done ; \
426
427 test: all
428         @ cd test && ./udev-test.pl