chiark / gitweb /
4dcdc9250b65eb50703bb5f9b503a52e1ae29745
[elogind.git] / Makefile
1 #
2 # Copyright (C) 2003-2004 Greg Kroah-Hartman <greg@kroah.com>
3 # Copyright (C) 2004-2006 Kay Sievers <kay.sievers@vrfy.org>
4 #
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; version 2 of the License.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 # General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program; if not, write to the Free Software
16 # 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 #
18
19 VERSION = 107
20
21 # set this to make use of syslog
22 USE_LOG = true
23
24 # compile-in development debug messages
25 # (export UDEV_LOG="debug" or set udev_log="debug" in udev.conf
26 #  to print the debug messages to syslog)
27 DEBUG = false
28
29 # compile with gcc's code coverage option
30 USE_GCOV = false
31
32 # include Security-Enhanced Linux support
33 USE_SELINUX = false
34
35 # set this to create statically linked binaries
36 USE_STATIC = false
37
38 # to build any of the extras programs pass:
39 #  make EXTRAS="extras/<extra1> extras/<extra2>"
40 EXTRAS =
41
42 # make the build silent
43 V =
44
45 PROGRAMS = \
46         udevd                           \
47         udevtrigger                     \
48         udevsettle                      \
49         udevcontrol                     \
50         udevmonitor                     \
51         udevinfo                        \
52         udevtest                        \
53         test-udev                       \
54         udevstart
55
56 HEADERS = \
57         udev.h                          \
58         udevd.h                         \
59         udev_rules.h                    \
60         logging.h                       \
61         udev_sysdeps.h                  \
62         udev_selinux.h                  \
63         list.h
64
65 UDEV_OBJS = \
66         udev_device.o                   \
67         udev_config.o                   \
68         udev_node.o                     \
69         udev_db.o                       \
70         udev_sysfs.o                    \
71         udev_rules.o                    \
72         udev_rules_parse.o              \
73         udev_utils.o                    \
74         udev_utils_string.o             \
75         udev_utils_file.o               \
76         udev_utils_run.o                \
77         udev_sysdeps.o
78 LIBUDEV = libudev.a
79
80 MAN_PAGES = \
81         udev.7                          \
82         udevmonitor.8                   \
83         udevd.8                         \
84         udevtrigger.8                   \
85         udevsettle.8                    \
86         udevtest.8                      \
87         udevinfo.8                      \
88         udevstart.8
89
90 GEN_HEADERS = \
91         udev_version.h
92
93 prefix ?=
94 etcdir =        ${prefix}/etc
95 sbindir =       ${prefix}/sbin
96 usrbindir =     ${prefix}/usr/bin
97 usrsbindir =    ${prefix}/usr/sbin
98 libudevdir =    ${prefix}/lib/udev
99 mandir =        ${prefix}/usr/share/man
100 configdir =     ${etcdir}/udev
101 udevdir =       /dev
102 DESTDIR =
103
104 INSTALL = install -c
105 INSTALL_PROGRAM = ${INSTALL}
106 INSTALL_DATA = ${INSTALL} -m 644
107 INSTALL_SCRIPT = ${INSTALL}
108 PWD = $(shell pwd)
109
110 CROSS_COMPILE ?=
111 CC = $(CROSS_COMPILE)gcc
112 LD = $(CROSS_COMPILE)gcc
113 AR = $(CROSS_COMPILE)ar
114 RANLIB = $(CROSS_COMPILE)ranlib
115
116 CFLAGS          = -g -Wall -pipe -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
117 WARNINGS        = -Wstrict-prototypes -Wsign-compare -Wshadow \
118                   -Wchar-subscripts -Wmissing-declarations -Wnested-externs \
119                   -Wpointer-arith -Wcast-align -Wsign-compare -Wmissing-prototypes
120 CFLAGS          += $(WARNINGS)
121
122 LDFLAGS = -Wl,-warn-common
123
124 OPTFLAGS = -Os
125 CFLAGS += $(OPTFLAGS)
126
127 ifeq ($(strip $(USE_LOG)),true)
128         CFLAGS += -DUSE_LOG
129 endif
130
131 # if DEBUG is enabled, then we do not strip
132 ifeq ($(strip $(DEBUG)),true)
133         CFLAGS  += -DDEBUG
134 endif
135
136 ifeq ($(strip $(USE_GCOV)),true)
137         CFLAGS += -fprofile-arcs -ftest-coverage
138         LDFLAGS += -fprofile-arcs
139 endif
140
141 ifeq ($(strip $(USE_SELINUX)),true)
142         UDEV_OBJS += udev_selinux.o
143         LIB_OBJS += -lselinux -lsepol
144         CFLAGS += -DUSE_SELINUX
145 endif
146
147 ifeq ($(strip $(USE_STATIC)),true)
148         CFLAGS += -DUSE_STATIC
149         LDFLAGS += -static
150 endif
151
152 ifeq ($(strip $(V)),)
153         E = @echo
154         Q = @
155 else
156         E = @\#
157         Q =
158 endif
159 export E Q
160
161 all: $(PROGRAMS) $(MAN_PAGES)
162         $(Q) extras="$(EXTRAS)"; for target in $$extras; do \
163                 $(MAKE) CC="$(CC)" \
164                         CFLAGS="$(CFLAGS)" \
165                         LD="$(LD)" \
166                         LDFLAGS="$(LDFLAGS)" \
167                         AR="$(AR)" \
168                         RANLIB="$(RANLIB)" \
169                         LIB_OBJS="$(LIB_OBJS)" \
170                         LIBUDEV="$(PWD)/$(LIBUDEV)" \
171                         -C $$target $@ || exit 1; \
172         done;
173 .PHONY: all
174 .DEFAULT: all
175
176 # clear implicit rules
177 .SUFFIXES:
178
179 # build the objects
180 %.o: %.c $(HEADERS) $(GEN_HEADERS)
181         $(E) "  CC      " $@
182         $(Q) $(CC) -c $(CFLAGS) $< -o $@
183
184 # "Static Pattern Rule" to build all programs
185 $(PROGRAMS): %: $(HEADERS) $(GEN_HEADERS) $(LIBUDEV) %.o
186         $(E) "  LD      " $@
187         $(Q) $(LD) $(LDFLAGS) $@.o -o $@ $(LIBUDEV) $(LIB_OBJS)
188
189 $(LIBUDEV): $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
190         $(Q) rm -f $@
191         $(E) "  AR      " $@
192         $(Q) $(AR) cq $@ $(UDEV_OBJS)
193         $(E) "  RANLIB  " $@
194         $(Q) $(RANLIB) $@
195
196 udev_version.h:
197         $(E) "  GENHDR  " $@
198         $(Q) echo "/* Generated by make. */" > $@
199         $(Q) echo \#define UDEV_VERSION         \"$(VERSION)\" >> $@
200         $(Q) echo \#define UDEV_ROOT            \"$(udevdir)\" >> $@
201         $(Q) echo \#define UDEV_CONFIG_FILE     \"$(configdir)/udev.conf\" >> $@
202         $(Q) echo \#define UDEV_RULES_DIR       \"$(configdir)/rules.d\" >> $@
203
204 # man pages
205 %.8 %.7: %.xml
206         $(E) "  XMLTO   " $@
207         $(Q) xmlto man $?
208 .PRECIOUS: %.8
209
210 clean:
211         $(E) "  CLEAN   "
212         $(Q) - find . -type f -name '*.orig' -print0 | xargs -0r rm -f
213         $(Q) - find . -type f -name '*.rej' -print0 | xargs -0r rm -f
214         $(Q) - find . -type f -name '*~' -print0 | xargs -0r rm -f
215         $(Q) - find . -type f -name '*.[oas]' -print0 | xargs -0r rm -f
216         $(Q) - find . -type f -name "*.gcno" -print0 | xargs -0r rm -f
217         $(Q) - find . -type f -name "*.gcda" -print0 | xargs -0r rm -f
218         $(Q) - find . -type f -name "*.gcov" -print0 | xargs -0r rm -f
219         $(Q) - rm -f udev_gcov.txt
220         $(Q) - rm -f core $(PROGRAMS) $(GEN_HEADERS)
221         $(Q) - rm -f udev-$(VERSION).tar.gz
222         $(Q) - rm -f udev-$(VERSION).tar.bz2
223         @ extras="$(EXTRAS)"; for target in $$extras; do \
224                 $(MAKE) -C $$target $@ || exit 1; \
225         done;
226 .PHONY: clean
227
228 release:
229         git-archive --format=tar --prefix=udev-$(VERSION)/ HEAD | gzip -9v > udev-$(VERSION).tar.gz
230         git-archive --format=tar --prefix=udev-$(VERSION)/ HEAD | bzip2 -9v > udev-$(VERSION).tar.bz2
231 .PHONY: release
232
233 install-config:
234         $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
235         @ if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
236                 $(INSTALL_DATA) etc/udev/udev.conf $(DESTDIR)$(configdir); \
237         fi
238         @ if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
239                 echo; \
240                 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
241                 echo; \
242         fi
243         @ extras="$(EXTRAS)"; for target in $$extras; do \
244                 $(MAKE) -C $$target $@ || exit 1; \
245         done;
246 .PHONY: install-config
247
248 install-man:
249         $(INSTALL_DATA) -D udev.7 $(DESTDIR)$(mandir)/man7/udev.7
250         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
251         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
252         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
253         $(INSTALL_DATA) -D udevtrigger.8 $(DESTDIR)$(mandir)/man8/udevtrigger.8
254         $(INSTALL_DATA) -D udevsettle.8 $(DESTDIR)$(mandir)/man8/udevsettle.8
255         $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
256         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
257         @extras="$(EXTRAS)"; for target in $$extras; do \
258                 $(MAKE) -C $$target $@ || exit 1; \
259         done;
260 .PHONY: install-man
261
262 uninstall-man:
263         - rm -f $(DESTDIR)$(mandir)/man7/udev.7
264         - rm -f $(DESTDIR)$(mandir)/man8/udevinfo.8
265         - rm -f $(DESTDIR)$(mandir)/man8/udevtest.8
266         - rm -f $(DESTDIR)$(mandir)/man8/udevd.8
267         - rm -f $(DESTDIR)$(mandir)/man8/udevtrigger.8
268         - rm -f $(DESTDIR)$(mandir)/man8/udevsettle.8
269         - rm -f $(DESTDIR)$(mandir)/man8/udevmonitor.8
270         - rm -f $(DESTDIR)$(mandir)/man8/udevcontrol.8
271         @ extras="$(EXTRAS)"; for target in $$extras; do \
272                 $(MAKE) -C $$target $@ || exit 1; \
273         done;
274 .PHONY: uninstall-man
275
276 install-bin:
277         $(INSTALL) -d $(DESTDIR)$(udevdir)
278         $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
279         $(INSTALL_PROGRAM) -D udevtrigger $(DESTDIR)$(sbindir)/udevtrigger
280         $(INSTALL_PROGRAM) -D udevsettle $(DESTDIR)$(sbindir)/udevsettle
281         $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
282         $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
283         $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
284         $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
285         @extras="$(EXTRAS)"; for target in $$extras; do \
286                 $(MAKE) -C $$target $@ || exit 1; \
287         done;
288 ifndef DESTDIR
289         - killall udevd
290         - rm -rf /dev/.udev
291         - $(sbindir)/udevd --daemon
292 endif
293 .PHONY: install-bin
294
295 uninstall-bin:
296         - rm -f $(DESTDIR)$(sbindir)/udevd
297         - rm -f $(DESTDIR)$(sbindir)/udevtrigger
298         - rm -f $(DESTDIR)$(sbindir)/udevsettle
299         - rm -f $(DESTDIR)$(sbindir)/udevcontrol
300         - rm -f $(DESTDIR)$(usrsbindir)/udevmonitor
301         - rm -f $(DESTDIR)$(usrbindir)/udevinfo
302         - rm -f $(DESTDIR)$(usrbindir)/udevtest
303 ifndef DESTDIR
304         - killall udevd
305         - rm -rf /dev/.udev
306 endif
307         @extras="$(EXTRAS)"; for target in $$extras; do \
308                 $(MAKE) -C $$target $@ || exit 1; \
309         done;
310 .PHONY: uninstall-bin
311
312 install: all install-bin install-config install-man
313 .PHONY: install
314
315 uninstall: uninstall-bin uninstall-man
316 .PHONY: uninstall
317
318 test tests: all
319         @ cd test && ./udev-test.pl
320         @ cd test && ./udevstart-test.pl
321 .PHONY: test tests
322
323 buildtest:
324         test/simple-build-check.sh
325 .PHONY: buildtest
326
327 ChangeLog: Makefile
328         @ mv $@ $@.tmp
329         @ echo "Summary of changes from v$(shell echo $$(($(VERSION) - 1))) to v$(VERSION)" >> $@
330         @ echo "============================================" >> $@
331         @ echo >> $@
332         @ git log --pretty=short $(shell echo $$(($(VERSION) - 1)))..HEAD | git shortlog  >> $@
333         @ echo >> $@
334         @ cat $@
335         @ cat $@.tmp >> $@
336         @ rm $@.tmp
337
338 gcov-all:
339         $(MAKE) clean all USE_GCOV=true
340         @ echo
341         @ echo "binaries built with gcov support."
342         @ echo "run the tests and analyze with 'make udev_gcov.txt'"
343 .PHONY: gcov-all
344
345 # see docs/README-gcov_for_udev
346 udev_gcov.txt: $(wildcard *.gcda) $(wildcard *.gcno)
347         for file in `find -maxdepth 1 -name "*.gcno"`; do \
348                 name=`basename $$file .gcno`; \
349                 echo "################" >> $@; \
350                 echo "$$name.c" >> $@; \
351                 echo "################" >> $@; \
352                 if [ -e "$$name.gcda" ]; then \
353                         gcov -l "$$name.c" >> $@ 2>&1; \
354                 else \
355                         echo "code for $$name.c was never executed" >> $@ 2>&1; \
356                 fi; \
357                 echo >> $@; \
358         done; \
359         echo "view $@ for the result"