chiark / gitweb /
replace udeveventrecorder by a shell script
[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 VERSION = 074
21
22 # set this to make use of syslog
23 USE_LOG = true
24
25 # compile-in development debug messages
26 # (export UDEV_LOG="debug" or set udev_log="debug" in udev.conf
27 #  to print the debug messages to syslog)
28 DEBUG = false
29
30 # compile with gcc's code coverage option
31 USE_GCOV = false
32
33 # include Security-Enhanced Linux support
34 USE_SELINUX = false
35
36 # comile with klibc instead of glibc
37 USE_KLIBC = false
38
39 # set this to create statically linked binaries
40 USE_STATIC = false
41
42 # to build any of the extras programs pass:
43 #  make EXTRAS="extras/<extra1> extras/<extra2>"
44 EXTRAS =
45
46 # make the build silent. Set this to something else to make it noisy again.
47 V = false
48
49 PROGRAMS = \
50         udev                            \
51         udevd                           \
52         udevsend                        \
53         udevcontrol                     \
54         udevmonitor                     \
55         udevinfo                        \
56         udevtest                        \
57         udevstart
58
59 HEADERS = \
60         udev.h                          \
61         udev_utils.h                    \
62         udev_rules.h                    \
63         udev_db.h                       \
64         udev_sysfs.h                    \
65         logging.h                       \
66         udev_libc_wrapper.h             \
67         udev_selinux.h                  \
68         list.h
69
70 UDEV_OBJS = \
71         udev_event.o                    \
72         udev_device.o                   \
73         udev_config.o                   \
74         udev_add.o                      \
75         udev_remove.o                   \
76         udev_sysfs.o                    \
77         udev_db.o                       \
78         udev_rules.o                    \
79         udev_rules_parse.o              \
80         udev_utils.o                    \
81         udev_utils_string.o             \
82         udev_utils_file.o               \
83         udev_utils_run.o                \
84         udev_libc_wrapper.o
85 LIBUDEV = libudev.a
86
87 MAN_PAGES = \
88         udev.8                          \
89         udevmonitor.8                   \
90         udevd.8                         \
91         udevsend.8                      \
92         udevtest.8                      \
93         udevinfo.8                      \
94         udevstart.8
95
96 SYSFS_OBJS = \
97         libsysfs/sysfs_class.o          \
98         libsysfs/sysfs_device.o         \
99         libsysfs/sysfs_dir.o            \
100         libsysfs/sysfs_driver.o         \
101         libsysfs/sysfs_utils.o          \
102         libsysfs/dlist.o
103 LIBSYSFS = libsysfs/libsysfs.a
104
105 # config files automatically generated
106 GEN_CONFIGS = \
107         $(LOCAL_CFG_DIR)/udev.conf
108
109 GEN_HEADERS = \
110         udev_version.h
111
112 # override this to make udev look in a different location for it's config files
113 prefix =
114 exec_prefix =   ${prefix}
115 etcdir =        ${prefix}/etc
116 sbindir =       ${exec_prefix}/sbin
117 usrbindir =     ${exec_prefix}/usr/bin
118 usrsbindir =    ${exec_prefix}/usr/sbin
119 mandir =        ${prefix}/usr/share/man
120 configdir =     ${etcdir}/udev
121 udevdir =       /dev
122 udevdb =        ${udevdir}/.udevdb
123 LOCAL_CFG_DIR = etc/udev
124 DESTDIR =
125
126 INSTALL = /usr/bin/install -c
127 INSTALL_PROGRAM = ${INSTALL}
128 INSTALL_DATA  = ${INSTALL} -m 644
129 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
130 PWD = $(shell pwd)
131
132 CROSS =
133 CC = $(CROSS)gcc
134 LD = $(CROSS)gcc
135 AR = $(CROSS)ar
136 RANLIB = $(CROSS)ranlib
137 HOSTCC = gcc
138 STRIP = $(CROSS)strip
139 STRIPCMD = $(STRIP) -s
140
141 # check if compiler option is supported
142 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;}
143
144 CFLAGS          = -g -Wall -pipe -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
145 WARNINGS        = -Wstrict-prototypes -Wsign-compare -Wshadow \
146                   -Wchar-subscripts -Wmissing-declarations -Wnested-externs \
147                   -Wpointer-arith -Wcast-align -Wsign-compare -Wmissing-prototypes
148 WARNINGS        += $(call cc-supports, -Wdeclaration-after-statement, )
149 CFLAGS          += $(WARNINGS)
150
151 LDFLAGS = -Wl,-warn-common
152
153 # use -Os optimization if available, else use -O2
154 OPTFLAGS := $(call cc-supports, -Os, -O2)
155 CFLAGS += $(OPTFLAGS)
156
157 # include our local copy of libsysfs
158 CFLAGS +=       -I$(PWD)/libsysfs/sysfs \
159                 -I$(PWD)/libsysfs
160
161 ifeq ($(strip $(USE_LOG)),true)
162         CFLAGS += -DUSE_LOG
163 endif
164
165 # if DEBUG is enabled, then we do not strip
166 ifeq ($(strip $(DEBUG)),true)
167         CFLAGS  += -DDEBUG
168         STRIPCMD =
169 endif
170
171 ifeq ($(strip $(USE_GCOV)),true)
172         CFLAGS += -fprofile-arcs -ftest-coverage
173         LDFLAGS += -fprofile-arcs
174 endif
175
176 # if our own version of klibc is used, we need to build it
177 ifeq ($(strip $(USE_KLIBC)),true)
178         KLCC            = /usr/bin/$(CROSS)klcc
179         CC              = $(KLCC)
180         LD              = $(KLCC)
181         V = true
182 endif
183
184 ifeq ($(strip $(USE_SELINUX)),true)
185         UDEV_OBJS += udev_selinux.o
186         LIB_OBJS += -lselinux -lsepol
187         CFLAGS += -DUSE_SELINUX
188 endif
189
190 ifeq ($(strip $(USE_STATIC)),true)
191         CFLAGS += -DUSE_STATIC
192         LDFLAGS += -static
193 endif
194
195 ifeq ($(strip $(V)),false)
196         QUIET=@$(PWD)/ccdv
197         HOST_PROGS=ccdv
198 else
199         QUIET=
200         HOST_PROGS=
201 endif
202
203 all: $(PROGRAMS) $(MAN_PAGES)
204         @extras="$(EXTRAS)"; for target in $$extras; do \
205                 echo $$target; \
206                 $(MAKE) CC="$(CC)" \
207                         CFLAGS="$(CFLAGS)" \
208                         LD="$(LD)" \
209                         LDFLAGS="$(LDFLAGS)" \
210                         STRIPCMD="$(STRIPCMD)" \
211                         LIB_OBJS="$(LIB_OBJS)" \
212                         LIBUDEV="$(PWD)/$(LIBUDEV)" \
213                         LIBSYSFS="$(PWD)/$(LIBSYSFS)" \
214                         QUIET="$(QUIET)" \
215                         -C $$target $@; \
216         done;
217 .PHONY: all
218 .DEFAULT: all
219
220 # clear implicit rules
221 .SUFFIXES:
222
223 # build the objects
224 %.o: %.c $(GEN_HEADERS)
225         $(QUIET) $(CC) -c $(CFLAGS) $< -o $@
226
227 # "Static Pattern Rule" to build all programs
228 $(PROGRAMS): %: $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(LIBSYSFS) $(LIBUDEV) %.o
229         $(QUIET) $(LD) $(LDFLAGS) $@.o -o $@ $(LIBUDEV) $(LIBSYSFS) $(LIB_OBJS)
230 ifneq ($(STRIPCMD),)
231         $(QUIET) $(STRIPCMD) $@
232 endif
233
234 $(UDEV_OBJS):
235 $(LIBUDEV): $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
236         @rm -f $@
237         $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
238         $(QUIET) $(RANLIB) $@
239
240 $(SYSFS_OBJS):
241 $(LIBSYSFS): $(HOST_PROGS) $(SYSFS_OBJS)
242         @rm -f $@
243         $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
244         $(QUIET) $(RANLIB) $@
245
246 # generate config files
247 $(GEN_CONFIGS):
248         sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $@.in > $@
249
250 # generate config header file
251 udev_version.h:
252         @echo "Creating udev_version.h"
253         @echo \#define UDEV_VERSION             \"$(VERSION)\" > $@
254         @echo \#define UDEV_ROOT                \"$(udevdir)\" >> $@
255         @echo \#define UDEV_DB                  \"$(udevdb)\" >> $@
256         @echo \#define UDEV_CONFIG_DIR          \"$(configdir)\" >> $@
257         @echo \#define UDEV_CONFIG_FILE         \"$(configdir)/udev.conf\" >> $@
258         @echo \#define UDEV_RULES_FILE          \"$(configdir)/rules.d\" >> $@
259         @echo \#define UDEVD_BIN                \"$(sbindir)/udevd\" >> $@
260
261 # man pages
262 %.8: docs/%.xml
263         xmlto man $?
264 .PRECIOUS: %.8
265
266 ccdv: ccdv.c
267         @$(HOSTCC) -O1 ccdv.c -o ccdv
268 .SILENT: ccdv
269
270 clean:
271         - find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print0 | xargs -0rt rm -f
272         - find -name "*.gcno" -print0 | xargs -0rt rm -f
273         - find -name "*.gcda" -print0 | xargs -0rt rm -f
274         - find -name "*.gcov" -print0 | xargs -0rt rm -f
275         - rm -f udev_gcov.txt
276         - rm -f core $(PROGRAMS) $(GEN_HEADERS) $(GEN_CONFIGS)
277         - rm -f udev-$(VERSION).tar.gz
278         @extras="$(EXTRAS)"; for target in $$extras; do \
279                 echo $$target; \
280                 $(MAKE) -C $$target $@; \
281         done;
282 .PHONY: clean
283
284 release:
285         git-tar-tree HEAD udev-$(VERSION) | gzip -9v > udev-$(VERSION).tar.gz
286         @echo "udev-$(VERSION).tar.gz created"
287 .PHONY: release
288
289 install-config: $(GEN_CONFIGS)
290         $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
291         @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
292                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
293                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
294         fi
295         @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
296                 echo; \
297                 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
298                 echo; \
299         fi
300         @extras="$(EXTRAS)"; for target in $$extras; do \
301                 echo $$target; \
302                 $(MAKE) -C $$target $@; \
303         done;
304 .PHONY: install-config
305
306 install-man:
307         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
308         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
309         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
310         $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
311         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
312         $(INSTALL_DATA) -D udevsend.8 $(DESTDIR)$(mandir)/man8/udevsend.8
313         $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
314         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
315         @extras="$(EXTRAS)"; for target in $$extras; do \
316                 echo $$target; \
317                 $(MAKE) -C $$target $@; \
318         done;
319 .PHONY: install-man
320
321 uninstall-man:
322         - rm -f $(DESTDIR)$(mandir)/man8/udev.8
323         - rm -f $(DESTDIR)$(mandir)/man8/udevinfo.8
324         - rm -f $(DESTDIR)$(mandir)/man8/udevtest.8
325         - rm -f $(DESTDIR)$(mandir)/man8/udevstart.8
326         - rm -f $(DESTDIR)$(mandir)/man8/udevd.8
327         - rm -f $(DESTDIR)$(mandir)/man8/udevmonitor.8
328         - rm -f $(DESTDIR)$(mandir)/man8/udevsend.8
329         - rm -f $(DESTDIR)$(mandir)/man8/udevcontrol.8
330         @extras="$(EXTRAS)"; for target in $$extras; do \
331                 echo $$target; \
332                 $(MAKE) -C $$target $@; \
333         done;
334 .PHONY: uninstall-man
335
336 install-bin:
337         $(INSTALL) -d $(DESTDIR)$(udevdir)
338         $(INSTALL_PROGRAM) -D udev $(DESTDIR)$(sbindir)/udev
339         $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
340         $(INSTALL_PROGRAM) -D udevsend $(DESTDIR)$(sbindir)/udevsend
341         $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
342         $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
343         $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
344         $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
345         $(INSTALL_PROGRAM) -D udevstart $(DESTDIR)$(sbindir)/udevstart
346         @extras="$(EXTRAS)"; for target in $$extras; do \
347                 echo $$target; \
348                 $(MAKE) -C $$target $@; \
349         done;
350 ifndef DESTDIR
351         - killall udevd
352         - rm -rf $(udevdb)
353         - $(sbindir)/udevd --daemon
354 endif
355 .PHONY: install-bin
356
357 uninstall-bin:
358         - rm -f $(DESTDIR)$(sbindir)/udev
359         - rm -f $(DESTDIR)$(sbindir)/udevd
360         - rm -f $(DESTDIR)$(sbindir)/udevsend
361         - rm -f $(DESTDIR)$(sbindir)/udevcontrol
362         - rm -f $(DESTDIR)$(sbindir)/udevstart
363         - rm -f $(DESTDIR)$(usrsbindir)/udevmonitor
364         - rm -f $(usrbindir)/udevinfo
365         - rm -f $(DESTDIR)$(DESTDIR)$(usrbindir)/udevtest
366 ifndef DESTDIR
367         - killall udevd
368         - rm -rf $(udevdb)
369 endif
370         @extras="$(EXTRAS)"; for target in $$extras; do \
371                 echo $$target; \
372                 $(MAKE) -C $$target $@; \
373         done;
374 .PHONY: uninstall-bin
375
376 install: all install-bin install-config install-man
377 .PHONY: install
378
379 uninstall: uninstall-bin uninstall-man
380 .PHONY: uninstall
381
382 test tests: all
383         @ cd test && ./udev-test.pl
384         @ cd test && ./udevstart-test.pl
385 .PHONY: test tests
386
387 buildtest:
388         ./test/simple-build-check.sh
389 .PHONY: buildtest
390
391 gcov-all:
392         $(MAKE) clean all STRIPCMD= USE_GCOV=true
393         @echo
394         @echo "binaries built with gcov support."
395         @echo "run the tests and analyze with 'make udev_gcov.txt'"
396 .PHONY: gcov-all
397
398 # see docs/README-gcov_for_udev
399 udev_gcov.txt: $(wildcard *.gcda) $(wildcard *.gcno)
400         for file in `find -maxdepth 1 -name "*.gcno"`; do \
401                 name=`basename $$file .gcno`; \
402                 echo "################" >> $@; \
403                 echo "$$name.c" >> $@; \
404                 echo "################" >> $@; \
405                 if [ -e "$$name.gcda" ]; then \
406                         gcov -l "$$name.c" >> $@ 2>&1; \
407                 else \
408                         echo "code for $$name.c was never executed" >> $@ 2>&1; \
409                 fi; \
410                 echo >> $@; \
411         done; \
412         echo "view $@ for the result"
413