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