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