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