chiark / gitweb /
add udevtrigger to request events for coldplug
[elogind.git] / Makefile
1 # Makefile for udev
2 #
3 # Copyright (C) 2003,2004 Greg Kroah-Hartman <greg@kroah.com>
4 # Copyright (C) 2004-2006 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 = 087
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
47 V =
48
49 PROGRAMS = \
50         udev                            \
51         udevd                           \
52         udevtrigger                     \
53         udevsend                        \
54         udevcontrol                     \
55         udevmonitor                     \
56         udevinfo                        \
57         udevtest                        \
58         udevstart
59
60 HEADERS = \
61         udev.h                          \
62         udev_rules.h                    \
63         logging.h                       \
64         udev_libc_wrapper.h             \
65         udev_selinux.h                  \
66         list.h
67
68 UDEV_OBJS = \
69         udev_device.o                   \
70         udev_config.o                   \
71         udev_add.o                      \
72         udev_remove.o                   \
73         udev_db.o                       \
74         udev_sysfs.o                    \
75         udev_rules.o                    \
76         udev_rules_parse.o              \
77         udev_utils.o                    \
78         udev_utils_string.o             \
79         udev_utils_file.o               \
80         udev_utils_run.o                \
81         udev_libc_wrapper.o
82 LIBUDEV = libudev.a
83
84 MAN_PAGES = \
85         udev.7                          \
86         udevmonitor.8                   \
87         udevd.8                         \
88         udevtrigger.8                   \
89         udevsend.8                      \
90         udevtest.8                      \
91         udevinfo.8                      \
92         udevstart.8
93
94 GEN_HEADERS = \
95         udev_version.h
96
97 prefix =
98 etcdir =        ${prefix}/etc
99 sbindir =       ${prefix}/sbin
100 usrbindir =     ${prefix}/usr/bin
101 usrsbindir =    ${prefix}/usr/sbin
102 libudevdir =    ${prefix}/lib/udev
103 mandir =        ${prefix}/usr/share/man
104 configdir =     ${etcdir}/udev
105 udevdir =       /dev
106 DESTDIR =
107
108 INSTALL = /usr/bin/install -c
109 INSTALL_PROGRAM = ${INSTALL}
110 INSTALL_DATA = ${INSTALL} -m 644
111 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
112 PWD = $(shell pwd)
113
114 CROSS_COMPILE =
115 CC = $(CROSS_COMPILE)gcc
116 LD = $(CROSS_COMPILE)gcc
117 AR = $(CROSS_COMPILE)ar
118 RANLIB = $(CROSS_COMPILE)ranlib
119 HOSTCC = gcc
120 STRIP = $(CROSS_COMPILE)strip
121 STRIPCMD = $(STRIP) -s
122
123 CFLAGS          = -g -Wall -pipe -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
124 WARNINGS        = -Wstrict-prototypes -Wsign-compare -Wshadow \
125                   -Wchar-subscripts -Wmissing-declarations -Wnested-externs \
126                   -Wpointer-arith -Wcast-align -Wsign-compare -Wmissing-prototypes
127 CFLAGS          += $(WARNINGS)
128
129 LDFLAGS = -Wl,-warn-common
130
131 OPTFLAGS = -Os
132 CFLAGS += $(OPTFLAGS)
133
134 ifeq ($(strip $(USE_LOG)),true)
135         CFLAGS += -DUSE_LOG
136 endif
137
138 # if DEBUG is enabled, then we do not strip
139 ifeq ($(strip $(DEBUG)),true)
140         CFLAGS  += -DDEBUG
141         STRIPCMD =
142 endif
143
144 ifeq ($(strip $(USE_GCOV)),true)
145         CFLAGS += -fprofile-arcs -ftest-coverage
146         LDFLAGS += -fprofile-arcs
147 endif
148
149 ifeq ($(strip $(USE_KLIBC)),true)
150         KLCC            = /usr/bin/$(CROSS_COMPILE)klcc
151         CC              = $(KLCC)
152         LD              = $(KLCC)
153 endif
154
155 ifeq ($(strip $(USE_SELINUX)),true)
156         UDEV_OBJS += udev_selinux.o
157         LIB_OBJS += -lselinux -lsepol
158         CFLAGS += -DUSE_SELINUX
159 endif
160
161 ifeq ($(strip $(USE_STATIC)),true)
162         CFLAGS += -DUSE_STATIC
163         LDFLAGS += -static
164 endif
165
166 ifeq ($(strip $(V)),)
167         E = @echo
168         Q = @
169 else
170         E = @\#
171         Q =
172 endif
173 export E Q
174
175 all: $(PROGRAMS) $(MAN_PAGES)
176         $(Q) extras="$(EXTRAS)"; for target in $$extras; do \
177                 $(MAKE) CC="$(CC)" \
178                         CFLAGS="$(CFLAGS)" \
179                         LD="$(LD)" \
180                         LDFLAGS="$(LDFLAGS)" \
181                         STRIPCMD="$(STRIPCMD)" \
182                         LIB_OBJS="$(LIB_OBJS)" \
183                         LIBUDEV="$(PWD)/$(LIBUDEV)" \
184                         -C $$target $@ || exit 1; \
185         done;
186 .PHONY: all
187 .DEFAULT: all
188
189 # clear implicit rules
190 .SUFFIXES:
191
192 # build the objects
193 %.o: %.c $(HEADERS) $(GEN_HEADERS)
194         $(E) "  CC      " $@
195         $(Q) $(CC) -c $(CFLAGS) $< -o $@
196
197 # "Static Pattern Rule" to build all programs
198 $(PROGRAMS): %: $(HEADERS) $(GEN_HEADERS) $(LIBUDEV) %.o
199         $(E) "  LD      " $@
200         $(Q) $(LD) $(LDFLAGS) $@.o -o $@ $(LIBUDEV) $(LIB_OBJS)
201 ifneq ($(STRIPCMD),)
202         $(E) "  STRIP   " $@
203         $(Q) $(STRIPCMD) $@
204 endif
205
206 $(LIBUDEV): $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
207         $(Q) rm -f $@
208         $(E) "  AR      " $@
209         $(Q) $(AR) cq $@ $(UDEV_OBJS)
210         $(E) "  RANLIB  " $@
211         $(Q) $(RANLIB) $@
212
213 udev_version.h:
214         $(E) "  GENHDR  " $@
215         $(Q) echo "/* Generated by make. */" > $@
216         $(Q) echo \#define UDEV_VERSION         \"$(VERSION)\" >> $@
217         $(Q) echo \#define UDEV_ROOT            \"$(udevdir)\" >> $@
218         $(Q) echo \#define UDEV_CONFIG_FILE     \"$(configdir)/udev.conf\" >> $@
219         $(Q) echo \#define UDEV_RULES_FILE      \"$(configdir)/rules.d\" >> $@
220
221 # man pages
222 %.8 %.7: %.xml
223         $(E) "  XMLTO   " $@
224         $(Q) xmlto man $?
225 .PRECIOUS: %.8
226
227 clean:
228         $(E) "  CLEAN   "
229         $(Q) - find . -type f -name '*.orig' -print0 | xargs -0r rm -f
230         $(Q) - find . -type f -name '*.rej' -print0 | xargs -0r rm -f
231         $(Q) - find . -type f -name '*~' -print0 | xargs -0r rm -f
232         $(Q) - find . -type f -name '*.[oas]' -print0 | xargs -0r rm -f
233         $(Q) - find . -type f -name "*.gcno" -print0 | xargs -0r rm -f
234         $(Q) - find . -type f -name "*.gcda" -print0 | xargs -0r rm -f
235         $(Q) - find . -type f -name "*.gcov" -print0 | xargs -0r rm -f
236         $(Q) - rm -f udev_gcov.txt
237         $(Q) - rm -f core $(PROGRAMS) $(GEN_HEADERS)
238         $(Q) - rm -f udev-$(VERSION).tar.gz
239         $(Q) - rm -f udev-$(VERSION).tar.bz2
240         @ extras="$(EXTRAS)"; for target in $$extras; do \
241                 $(MAKE) -C $$target $@ || exit 1; \
242         done;
243 .PHONY: clean
244
245 release:
246         git-tar-tree HEAD udev-$(VERSION) | gzip -9v > udev-$(VERSION).tar.gz
247         git-tar-tree HEAD udev-$(VERSION) | bzip2 -9v > udev-$(VERSION).tar.bz2
248 .PHONY: release
249
250 install-config:
251         $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
252         @ if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
253                 $(INSTALL_DATA) etc/udev/udev.conf $(DESTDIR)$(configdir); \
254         fi
255         @ if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
256                 echo; \
257                 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
258                 echo; \
259         fi
260         @ extras="$(EXTRAS)"; for target in $$extras; do \
261                 $(MAKE) -C $$target $@ || exit 1; \
262         done;
263 .PHONY: install-config
264
265 install-man:
266         $(INSTALL_DATA) -D udev.7 $(DESTDIR)$(mandir)/man7/udev.7
267         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
268         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
269         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
270         $(INSTALL_DATA) -D udevtrigger.8 $(DESTDIR)$(mandir)/man8/udevtrigger.8
271         $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
272         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
273         @extras="$(EXTRAS)"; for target in $$extras; do \
274                 $(MAKE) -C $$target $@ || exit 1; \
275         done;
276 .PHONY: install-man
277
278 uninstall-man:
279         - rm -f $(DESTDIR)$(mandir)/man7/udev.7
280         - rm -f $(DESTDIR)$(mandir)/man8/udevinfo.8
281         - rm -f $(DESTDIR)$(mandir)/man8/udevtest.8
282         - rm -f $(DESTDIR)$(mandir)/man8/udevd.8
283         - rm -f $(DESTDIR)$(mandir)/man8/udevtrigger.8
284         - rm -f $(DESTDIR)$(mandir)/man8/udevmonitor.8
285         - rm -f $(DESTDIR)$(mandir)/man8/udevcontrol.8
286         @ extras="$(EXTRAS)"; for target in $$extras; do \
287                 $(MAKE) -C $$target $@ || exit 1; \
288         done;
289 .PHONY: uninstall-man
290
291 install-bin:
292         $(INSTALL) -d $(DESTDIR)$(udevdir)
293         $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
294         $(INSTALL_PROGRAM) -D udevtrigger $(DESTDIR)$(sbindir)/udevtrigger
295         $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
296         $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
297         $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
298         $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
299         @extras="$(EXTRAS)"; for target in $$extras; do \
300                 $(MAKE) -C $$target $@ || exit 1; \
301         done;
302 ifndef DESTDIR
303         - killall udevd
304         - rm -rf /dev/.udev
305         - $(sbindir)/udevd --daemon
306 endif
307 .PHONY: install-bin
308
309 uninstall-bin:
310         - rm -f $(DESTDIR)$(sbindir)/udevd
311         - rm -f $(DESTDIR)$(sbindir)/udevtrigger
312         - rm -f $(DESTDIR)$(sbindir)/udevcontrol
313         - rm -f $(DESTDIR)$(usrsbindir)/udevmonitor
314         - rm -f $(DESTDIR)$(usrbindir)/udevinfo
315         - rm -f $(DESTDIR)$(usrbindir)/udevtest
316 ifndef DESTDIR
317         - killall udevd
318         - rm -rf /dev/.udev
319 endif
320         @extras="$(EXTRAS)"; for target in $$extras; do \
321                 $(MAKE) -C $$target $@ || exit 1; \
322         done;
323 .PHONY: uninstall-bin
324
325 install: all install-bin install-config install-man
326 .PHONY: install
327
328 uninstall: uninstall-bin uninstall-man
329 .PHONY: uninstall
330
331 test tests: all
332         @ cd test && ./udev-test.pl
333         @ cd test && ./udevstart-test.pl
334 .PHONY: test tests
335
336 buildtest:
337         test/simple-build-check.sh
338 .PHONY: buildtest
339
340 ChangeLog: Makefile
341         @ mv $@ $@.tmp
342         @ echo "Summary of changes from v$(shell printf '%03i' $$(expr $(VERSION) - 1)) to v$(VERSION)" >> $@
343         @ echo "============================================" >> $@
344         @ echo >> $@
345         @ git log --pretty=short $(shell printf '%03i' $$(expr $(VERSION) - 1))..HEAD | git shortlog  >> $@
346         @ echo >> $@
347         @ cat $@
348         @ cat $@.tmp >> $@
349         @ rm $@.tmp
350
351 gcov-all:
352         $(MAKE) clean all STRIPCMD= USE_GCOV=true
353         @ echo
354         @ echo "binaries built with gcov support."
355         @ echo "run the tests and analyze with 'make udev_gcov.txt'"
356 .PHONY: gcov-all
357
358 # see docs/README-gcov_for_udev
359 udev_gcov.txt: $(wildcard *.gcda) $(wildcard *.gcno)
360         for file in `find -maxdepth 1 -name "*.gcno"`; do \
361                 name=`basename $$file .gcno`; \
362                 echo "################" >> $@; \
363                 echo "$$name.c" >> $@; \
364                 echo "################" >> $@; \
365                 if [ -e "$$name.gcda" ]; then \
366                         gcov -l "$$name.c" >> $@ 2>&1; \
367                 else \
368                         echo "code for $$name.c was never executed" >> $@ 2>&1; \
369                 fi; \
370                 echo >> $@; \
371         done; \
372         echo "view $@ for the result"