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