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