chiark / gitweb /
EXTRAS/Makefile: fix install targets to match main Makefile
[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 =       069
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 # If you are running a cross compiler, you may want to set this
140 # to something more interesting, like "arm-linux-".  If you want
141 # to compile vs uClibc, that can be done here as well.
142 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
143 CC = $(CROSS)gcc
144 LD = $(CROSS)gcc
145 AR = $(CROSS)ar
146 STRIP = $(CROSS)strip
147 RANLIB = $(CROSS)ranlib
148 HOSTCC = gcc
149
150 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
151
152 # code taken from uClibc to determine the current arch
153 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
154         -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
155
156 # determine the gcc include dir
157 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
158
159 # determine the libgcc.a filename
160 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
161
162 # check if compiler option is supported
163 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;}
164
165 CFLAGS          += -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith \
166                    -Wstrict-prototypes -Wsign-compare
167 CFLAGS          += $(call cc-supports, -Wdeclaration-after-statement, )
168 CFLAGS          += -pipe
169 CFLAGS          += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
170
171 # use '-Os' optimization if available, else use -O2
172 OPTFLAGS := $(call cc-supports, -Os, -O2)
173
174 # include our local copy of libsysfs
175 CFLAGS +=       -I$(PWD)/libsysfs/sysfs \
176                 -I$(PWD)/libsysfs
177
178 ifeq ($(strip $(USE_LOG)),true)
179         CFLAGS += -DUSE_LOG
180 endif
181
182 # if DEBUG is enabled, then we do not strip or optimize
183 ifeq ($(strip $(DEBUG)),true)
184         CFLAGS  += -O1 -g -DDEBUG
185         LDFLAGS += -Wl
186         STRIPCMD = /bin/true -Since_we_are_debugging
187 else
188         CFLAGS  += $(OPTFLAGS) -fomit-frame-pointer
189         LDFLAGS += -s -Wl
190         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
191 endif
192
193 ifeq ($(strip $(USE_GCOV)),true)
194         CFLAGS += -fprofile-arcs -ftest-coverage
195         LDFLAGS = -fprofile-arcs
196 endif
197
198 # if our own version of klibc is used, we need to build it
199 ifeq ($(strip $(USE_KLIBC)),true)
200         KLIBC_INSTALL   = $(PWD)/klibc/.install
201         KLCC            = $(KLIBC_INSTALL)/bin/$(CROSS)klcc
202         CC              = $(KLCC)
203         LD              = $(KLCC)
204 else
205         CFLAGS          += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
206         LDFLAGS         += -Wl,-warn-common
207 endif
208
209 ifeq ($(strip $(USE_SELINUX)),true)
210         UDEV_OBJS += udev_selinux.o
211         LIB_OBJS += -lselinux
212         CFLAGS += -DUSE_SELINUX
213 endif
214
215 ifeq ($(strip $(USE_STATIC)),true)
216         CFLAGS += -DUSE_STATIC
217         LDFLAGS += -static
218 endif
219
220 ifeq ($(strip $(V)),false)
221         QUIET=@$(PWD)/ccdv
222         HOST_PROGS=ccdv
223 else
224         QUIET=
225         HOST_PROGS=
226 endif
227
228 all: $(KLCC) $(PROGRAMS) $(MAN_PAGES)
229         @extras="$(EXTRAS)"; for target in $$extras; do \
230                 echo $$target; \
231                 $(MAKE) prefix=$(prefix) \
232                         LD="$(LD)" \
233                         LIBUDEV="$(PWD)/$(LIBUDEV)" \
234                         LIBSYSFS="$(PWD)/$(LIBSYSFS)" \
235                         KERNEL_DIR="$(KERNEL_DIR)" \
236                         QUIET="$(QUIET)" \
237                         -C $$target $@; \
238         done;
239 .PHONY: all
240 .DEFAULT: all
241
242 # clear implicit rules
243 .SUFFIXES:
244
245 # build the objects
246 %.o: %.c
247         $(QUIET) $(CC) -c $(CFLAGS) $< -o $@
248
249 # "Static Pattern Rule" to build all programs
250 $(PROGRAMS): %: $(HOST_PROGS) $(KLCC) $(HEADERS) $(GEN_HEADERS) $(LIBSYSFS) $(LIBUDEV) %.o
251         $(QUIET) $(LD) $(LDFLAGS) $@.o -o $@ $(LIBUDEV) $(LIBSYSFS) $(LIB_OBJS)
252         $(QUIET) $(STRIPCMD) $@
253
254 # our own copy of klibc, it is not used if KLCC is given
255 $(KLCC):
256         $(MAKE) -C klibc KRNLSRC=$(KERNEL_DIR) SUBDIRS=klibc TESTS= \
257                          SHLIBDIR=$(KLIBC_INSTALL)/lib \
258                          INSTALLDIR=$(KLIBC_INSTALL) \
259                          bindir=$(KLIBC_INSTALL)/bin \
260                          mandir=$(KLIBC_INSTALL)/man all install
261         -find $(KLIBC_INSTALL)/include -name SCCS -print| xargs rm -rf
262 .NOTPARALLEL: $(KLCC)
263
264 $(UDEV_OBJS): $(KLCC)
265 $(LIBUDEV): $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
266         @rm -f $@
267         $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
268         $(QUIET) $(RANLIB) $@
269
270 $(SYSFS_OBJS): $(KLCC)
271 $(LIBSYSFS): $(HOST_PROGS) $(SYSFS_OBJS)
272         @rm -f $@
273         $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
274         $(QUIET) $(RANLIB) $@
275
276 # generate config files
277 $(GEN_CONFIGS):
278         sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $@.in > $@
279
280 # generate config header file
281 udev_version.h:
282         @echo "Creating udev_version.h"
283         @echo \#define UDEV_VERSION             \"$(VERSION)\" > $@
284         @echo \#define UDEV_ROOT                \"$(udevdir)\" >> $@
285         @echo \#define UDEV_DB                  \"$(udevdb)\" >> $@
286         @echo \#define UDEV_CONFIG_DIR          \"$(configdir)\" >> $@
287         @echo \#define UDEV_CONFIG_FILE         \"$(configdir)/udev.conf\" >> $@
288         @echo \#define UDEV_RULES_FILE          \"$(configdir)/rules.d\" >> $@
289         @echo \#define UDEV_BIN                 \"$(sbindir)/udev\" >> $@
290         @echo \#define UDEVD_BIN                \"$(sbindir)/udevd\" >> $@
291
292 # man pages
293 %.8: docs/%.xml
294         xmlto man $?
295 .PRECIOUS: %.8
296
297 ccdv: ccdv.c
298         @$(HOSTCC) -O1 ccdv.c -o ccdv
299 .SILENT: ccdv
300
301 clean:
302         - find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print0 | xargs -0rt rm -f
303         - find -name "*.gcno" -print0 | xargs -0rt rm -f
304         - find -name "*.gcda" -print0 | xargs -0rt rm -f
305         - find -name "*.gcov" -print0 | xargs -0rt rm -f
306         - rm -f udev_gcov.txt
307         - rm -f core $(PROGRAMS) $(GEN_HEADERS) $(GEN_CONFIGS)
308         $(MAKE) -C klibc SUBDIRS=klibc clean
309         @extras="$(EXTRAS)"; for target in $$extras; do \
310                 echo $$target; \
311                 $(MAKE) prefix=$(prefix) -C $$target $@; \
312         done;
313 .PHONY: clean
314
315 spotless: clean
316         $(MAKE) -C klibc SUBDIRS=klibc spotless
317         rm -rf klibc/.install
318 .PHONY: spotless
319
320 release: spotless
321         git-tar-tree HEAD $(RELEASE_NAME) | gzip -9v > $(RELEASE_NAME).tar.gz
322         @echo "$(RELEASE_NAME).tar.gz created"
323 .PHONY: release
324
325 install-config: $(GEN_CONFIGS)
326         $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
327         @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
328                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
329                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
330         fi
331         @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
332                 echo; \
333                 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
334                 echo; \
335         fi
336         @extras="$(EXTRAS)"; for target in $$extras; do \
337                 echo $$target; \
338                 $(MAKE) prefix=$(prefix) -C $$target $@; \
339         done;
340 .PHONY: install-config
341
342 install-man:
343         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
344         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
345         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
346         $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
347         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
348         $(INSTALL_DATA) -D udevsend.8 $(DESTDIR)$(mandir)/man8/udevsend.8
349         $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
350         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
351         @extras="$(EXTRAS)"; for target in $$extras; do \
352                 echo $$target; \
353                 $(MAKE) prefix=$(prefix) -C $$target $@; \
354         done;
355 .PHONY: install-man
356
357 uninstall-man:
358         - rm $(mandir)/man8/udev.8
359         - rm $(mandir)/man8/udevinfo.8
360         - rm $(mandir)/man8/udevtest.8
361         - rm $(mandir)/man8/udevstart.8
362         - rm $(mandir)/man8/udevd.8
363         - rm $(mandir)/man8/udevmonitor.8
364         - rm $(mandir)/man8/udevsend.8
365         - rm $(mandir)/man8/udevcontrol.8
366         @extras="$(EXTRAS)"; for target in $$extras; do \
367                 echo $$target; \
368                 $(MAKE) prefix=$(prefix) -C $$target $@; \
369         done;
370 .PHONY: uninstall-man
371
372 install-bin:
373         $(INSTALL) -d $(DESTDIR)$(udevdir)
374         $(INSTALL_PROGRAM) -D udev $(DESTDIR)$(sbindir)/udev
375         $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
376         $(INSTALL_PROGRAM) -D udevsend $(DESTDIR)$(sbindir)/udevsend
377         $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
378         $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
379         $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
380         $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
381         $(INSTALL_PROGRAM) -D udevstart $(DESTDIR)$(sbindir)/udevstart
382 ifndef DESTDIR
383         - killall udevd
384         - rm -rf $(udevdb)
385         - $(sbindir)/udevd --daemon
386 endif
387         @extras="$(EXTRAS)"; for target in $$extras; do \
388                 echo $$target; \
389                 $(MAKE) prefix=$(prefix) -C $$target $@; \
390         done;
391 .PHONY: install-bin
392
393 uninstall-bin:
394         - rm $(sbindir)/udev
395         - rm $(sbindir)/udevd
396         - rm $(sbindir)/udevsend
397         - rm $(sbindir)/udevinitsend
398         - rm $(sbindir)/udeveventrecoreder
399         - rm $(sbindir)/udevcontrol
400         - rm $(sbindir)/udevstart
401         - rm $(usrsbindir)/udevmonitor
402         - rm $(usrbindir)/udevinfo
403         - rm $(usrbindir)/udevtest
404         - rm -rf $(udevdb)
405         - killall udevd
406         @extras="$(EXTRAS)"; for target in $$extras; do \
407                 echo $$target; \
408                 $(MAKE) prefix=$(prefix) -C $$target $@; \
409         done;
410 .PHONY: uninstall-bin
411
412 install: all install-bin install-config install-man
413 .PHONY: install
414
415 uninstall: uninstall-bin uninstall-man
416 .PHONY: uninstall
417
418 test tests: all
419         @ cd test && ./udev-test.pl
420         @ cd test && ./udevstart-test.pl
421 .PHONY: test tests
422
423 buildtest:
424         ./test/simple-build-check.sh
425 .PHONY: buildtest
426
427 gcov-all:
428         $(MAKE) clean all DEBUG=true USE_GCOV=true
429         @echo
430         @echo "binaries built with gcov support."
431         @echo "run the tests and analyze with 'make udev_gcov.txt'"
432 .PHONY: gcov-all
433
434 # see docs/README-gcov_for_udev
435 udev_gcov.txt: $(wildcard *.gcda) $(wildcard *.gcno)
436         for file in `find -maxdepth 1 -name "*.gcno"`; do \
437                 name=`basename $$file .gcno`; \
438                 echo "################" >> $@; \
439                 echo "$$name.c" >> $@; \
440                 echo "################" >> $@; \
441                 if [ -e "$$name.gcda" ]; then \
442                         gcov -l "$$name.c" >> $@ 2>&1; \
443                 else \
444                         echo "code for $$name.c was never executed" >> $@ 2>&1; \
445                 fi; \
446                 echo >> $@; \
447         done; \
448         echo "view $@ for the result"
449