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