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