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