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