chiark / gitweb /
all man pages rewritten to use DocBook XML
[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 =       068
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 # include Security-Enhanced Linux support
31 USE_SELINUX = false
32
33 # comile with klibc instead of glibc
34 USE_KLIBC = false
35
36 # set this to create statically linked binaries
37 USE_STATIC = false
38
39 # to build any of the extras programs pass:
40 #  make EXTRAS="extras/<extra1> extras/<extra2>"
41 EXTRAS=
42
43 # make the build silent. Set this to something else to make it noisy again.
44 V=false
45
46 PROGRAMS = \
47         udev                            \
48         udevd                           \
49         udevsend                        \
50         udevrulescompile                \
51         udevinitsend                    \
52         udeveventrecorder               \
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_version.h                  \
64         udev_db.h                       \
65         udev_sysfs.h                    \
66         logging.h                       \
67         udev_libc_wrapper.h             \
68         udev_selinux.h                  \
69         list.h
70
71 UDEV_OBJS = \
72         udev_event.o                    \
73         udev_device.o                   \
74         udev_config.o                   \
75         udev_add.o                      \
76         udev_remove.o                   \
77         udev_sysfs.o                    \
78         udev_db.o                       \
79         udev_rules.o                    \
80         udev_rules_parse.o              \
81         udev_utils.o                    \
82         udev_utils_string.o             \
83         udev_utils_file.o               \
84         udev_utils_run.o                \
85         udev_libc_wrapper.o
86 LIBUDEV = libudev.a
87
88 MAN_PAGES = \
89         udev.8                          \
90         udevmonitor.8                   \
91         udevd.8                         \
92         udevsend.8                      \
93         udevtest.8                      \
94         udevinfo.8                      \
95         udevstart.8
96
97 SYSFS_OBJS = \
98         libsysfs/sysfs_class.o          \
99         libsysfs/sysfs_device.o         \
100         libsysfs/sysfs_dir.o            \
101         libsysfs/sysfs_driver.o         \
102         libsysfs/sysfs_utils.o          \
103         libsysfs/dlist.o
104 LIBSYSFS = libsysfs/libsysfs.a
105
106 # config files automatically generated
107 GEN_CONFIGS = \
108         $(LOCAL_CFG_DIR)/udev.conf
109
110 GEN_HEADERS = \
111         udev_version.h
112
113 # override this to make udev look in a different location for it's config files
114 prefix =
115 exec_prefix =   ${prefix}
116 etcdir =        ${prefix}/etc
117 sbindir =       ${exec_prefix}/sbin
118 usrbindir =     ${exec_prefix}/usr/bin
119 usrsbindir =    ${exec_prefix}/usr/sbin
120 mandir =        ${prefix}/usr/share/man
121 configdir =     ${etcdir}/udev
122 udevdir =       /dev
123 udevdb =        ${udevdir}/.udevdb
124 LOCAL_CFG_DIR = etc/udev
125 KERNEL_DIR =    /lib/modules/${shell uname -r}/build
126 srcdir = .
127 DESTDIR =
128 RELEASE_NAME =  udev-$(VERSION)
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 # If you are running a cross compiler, you may want to set this
137 # to something more interesting, like "arm-linux-".  If you want
138 # to compile vs uClibc, that can be done here as well.
139 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
140 CC = $(CROSS)gcc
141 LD = $(CROSS)gcc
142 AR = $(CROSS)ar
143 STRIP = $(CROSS)strip
144 RANLIB = $(CROSS)ranlib
145 HOSTCC = gcc
146
147 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS
148
149 # code taken from uClibc to determine the current arch
150 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
151         -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
152
153 # determine the gcc include dir
154 GCCINCDIR := ${shell LC_ALL=C $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
155
156 # determine the libgcc.a filename
157 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
158
159 # check if compiler option is supported
160 cc-supports = ${shell if $(CC) ${1} -S -o /dev/null -xc /dev/null > /dev/null 2>&1; then echo "$(1)"; else echo "$(2)"; fi;}
161
162 CFLAGS          += -Wall -fno-builtin -Wchar-subscripts -Wpointer-arith \
163                    -Wstrict-prototypes -Wsign-compare
164 CFLAGS          += $(call cc-supports, -Wdeclaration-after-statement, )
165 CFLAGS          += -pipe
166 CFLAGS          += -D_GNU_SOURCE -D_FILE_OFFSET_BITS=64
167
168 # use '-Os' optimization if available, else use -O2
169 OPTFLAGS := $(call cc-supports, -Os, -O2)
170
171 # include our local copy of libsysfs
172 CFLAGS +=       -I$(PWD)/libsysfs/sysfs \
173                 -I$(PWD)/libsysfs
174
175 ifeq ($(strip $(USE_LOG)),true)
176         CFLAGS += -DUSE_LOG
177 endif
178
179 # if DEBUG is enabled, then we do not strip or optimize
180 ifeq ($(strip $(DEBUG)),true)
181         CFLAGS  += -O1 -g -DDEBUG
182         LDFLAGS += -Wl
183         STRIPCMD = /bin/true -Since_we_are_debugging
184 else
185         CFLAGS  += $(OPTFLAGS) -fomit-frame-pointer
186         LDFLAGS += -s -Wl
187         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
188 endif
189
190 # if our own version of klibc is used, we need to build it
191 ifeq ($(strip $(USE_KLIBC)),true)
192         KLIBC_INSTALL   = $(PWD)/klibc/.install
193         KLCC            = $(KLIBC_INSTALL)/bin/$(CROSS)klcc
194         CC              = $(KLCC)
195         LD              = $(KLCC)
196 else
197         CFLAGS          += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
198 endif
199
200 ifeq ($(strip $(USE_SELINUX)),true)
201         UDEV_OBJS += udev_selinux.o
202         LIB_OBJS += -lselinux
203         CFLAGS += -DUSE_SELINUX
204 endif
205
206 ifeq ($(strip $(USE_STATIC)),true)
207         CFLAGS += -DUSE_STATIC
208         LDFLAGS += -static
209 endif
210
211 ifeq ($(strip $(V)),false)
212         QUIET=@$(PWD)/ccdv
213         HOST_PROGS=ccdv
214 else
215         QUIET=
216         HOST_PROGS=
217 endif
218
219 all: $(KLCC) $(PROGRAMS) $(MAN_PAGES)
220         @extras="$(EXTRAS)"; for target in $$extras; do \
221                 echo $$target; \
222                 $(MAKE) prefix=$(prefix) \
223                         LD="$(LD)" \
224                         LIBUDEV="$(PWD)/$(LIBUDEV)" \
225                         LIBSYSFS="$(PWD)/$(LIBSYSFS)" \
226                         KERNEL_DIR="$(KERNEL_DIR)" \
227                         QUIET="$(QUIET)" \
228                         -C $$target $@; \
229         done;
230 .PHONY: all
231
232 $(PROGRAMS): $(HOST_PROGS) $(KLCC) $(HEADERS) $(GEN_HEADERS) $(LIBSYSFS) $(LIBUDEV)
233         $(QUIET) $(CC) $(CFLAGS) -c -o $@.o $@.c
234         $(QUIET) $(LD) $(LDFLAGS) -o $@ $@.o $(LIBUDEV) $(LIBSYSFS) $(LIB_OBJS)
235         $(QUIET) $(STRIPCMD) $@
236
237 # our own copy of klibc if KLCC is specified it will not be used
238 $(KLCC):
239         $(MAKE) -j1 -C klibc KRNLSRC=$(KERNEL_DIR) SUBDIRS=klibc TESTS= \
240                          SHLIBDIR=$(KLIBC_INSTALL)/lib \
241                          INSTALLDIR=$(KLIBC_INSTALL) \
242                          bindir=$(KLIBC_INSTALL)/bin \
243                          mandir=$(KLIBC_INSTALL)/man all install
244         -find $(KLIBC_INSTALL)/include -name SCCS -print| xargs rm -rf
245
246 $(UDEV_OBJS): $(KLCC)
247 $(LIBUDEV): $(HOST_PROGS) $(HEADERS) $(GEN_HEADERS) $(UDEV_OBJS)
248         @rm -f $@
249         $(QUIET) $(AR) cq $@ $(UDEV_OBJS)
250         $(QUIET) $(RANLIB) $@
251
252 $(SYSFS_OBJS): $(KLCC)
253 $(LIBSYSFS): $(HOST_PROGS) $(SYSFS_OBJS)
254         @rm -f $@
255         $(QUIET) $(AR) cq $@ $(SYSFS_OBJS)
256         $(QUIET) $(RANLIB) $@
257
258 # generate config files
259 $(GEN_CONFIGS):
260         sed -e "s:@udevdir@:$(udevdir):" -e "s:@configdir@:$(configdir):" < $@.in > $@
261
262 # generate config header file
263 udev_version.h:
264         @echo "Creating udev_version.h"
265         @echo \#define UDEV_VERSION             \"$(VERSION)\" > $@
266         @echo \#define UDEV_ROOT                \"$(udevdir)\" >> $@
267         @echo \#define UDEV_DB                  \"$(udevdb)\" >> $@
268         @echo \#define UDEV_CONFIG_DIR          \"$(configdir)\" >> $@
269         @echo \#define UDEV_CONFIG_FILE         \"$(configdir)/udev.conf\" >> $@
270         @echo \#define UDEV_RULES_FILE          \"$(configdir)/rules.d\" >> $@
271         @echo \#define UDEV_BIN                 \"$(sbindir)/udev\" >> $@
272         @echo \#define UDEVD_BIN                \"$(sbindir)/udevd\" >> $@
273
274 # man pages
275 %.8: docs/%.xml
276         xmlto man $?
277 .PRECIOUS: %.8
278
279 .c.o:
280         $(QUIET) $(CC) $(CFLAGS) -c -o $@ $<
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 -print | xargs rm -f
288         -rm -f core $(PROGRAMS) $(GEN_HEADERS) $(GEN_CONFIGS)
289         $(MAKE) -C klibc SUBDIRS=klibc clean
290         @extras="$(EXTRAS)"; for target in $$extras; do \
291                 echo $$target; \
292                 $(MAKE) prefix=$(prefix) -C $$target $@; \
293         done;
294 .PHONY: clean
295
296 spotless: clean
297         $(MAKE) -C klibc SUBDIRS=klibc spotless
298         rm -rf klibc/.install
299 .PHONY: spotless
300
301 release: spotless
302         git-tar-tree HEAD $(RELEASE_NAME) | gzip -9v > $(RELEASE_NAME).tar.gz
303         @echo "$(RELEASE_NAME).tar.gz created"
304 .PHONY: release
305
306 install-config: $(GEN_CONFIGS)
307         $(INSTALL) -d $(DESTDIR)$(configdir)/rules.d
308         @if [ ! -r $(DESTDIR)$(configdir)/udev.conf ]; then \
309                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
310                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
311         fi
312         @if [ ! -r $(DESTDIR)$(configdir)/rules.d/50-udev.rules ]; then \
313                 echo; \
314                 echo "pick a udev rules file from the etc/udev directory that matches your distribution"; \
315                 echo; \
316         fi
317 .PHONY: install-config
318
319 install-man:
320         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
321         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
322         $(INSTALL_DATA) -D udevtest.8 $(DESTDIR)$(mandir)/man8/udevtest.8
323         $(INSTALL_DATA) -D udevstart.8 $(DESTDIR)$(mandir)/man8/udevstart.8
324         $(INSTALL_DATA) -D udevd.8 $(DESTDIR)$(mandir)/man8/udevd.8
325         $(INSTALL_DATA) -D udevsend.8 $(DESTDIR)$(mandir)/man8/udevsend.8
326         $(INSTALL_DATA) -D udevmonitor.8 $(DESTDIR)$(mandir)/man8/udevmonitor.8
327         - ln -f -s udevd.8 $(DESTDIR)$(mandir)/man8/udevcontrol.8
328 .PHONY: install-man
329
330 uninstall-man:
331         - rm $(mandir)/man8/udev.8
332         - rm $(mandir)/man8/udevinfo.8
333         - rm $(mandir)/man8/udevtest.8
334         - rm $(mandir)/man8/udevstart.8
335         - rm $(mandir)/man8/udevd.8
336         - rm $(mandir)/man8/udevmonitor.8
337         - rm $(mandir)/man8/udevsend.8
338         - rm $(mandir)/man8/udevcontrol.8
339 .PHONY: uninstall-man
340
341 install: install-config install-man all
342         $(INSTALL) -d $(DESTDIR)$(udevdir)
343         $(INSTALL_PROGRAM) -D udev $(DESTDIR)$(sbindir)/udev
344         $(INSTALL_PROGRAM) -D udevd $(DESTDIR)$(sbindir)/udevd
345         $(INSTALL_PROGRAM) -D udevsend $(DESTDIR)$(sbindir)/udevsend
346         $(INSTALL_PROGRAM) -D udevcontrol $(DESTDIR)$(sbindir)/udevcontrol
347         $(INSTALL_PROGRAM) -D udevmonitor $(DESTDIR)$(usrsbindir)/udevmonitor
348         $(INSTALL_PROGRAM) -D udevinfo $(DESTDIR)$(usrbindir)/udevinfo
349         $(INSTALL_PROGRAM) -D udevtest $(DESTDIR)$(usrbindir)/udevtest
350         $(INSTALL_PROGRAM) -D udevstart $(DESTDIR)$(sbindir)/udevstart
351 ifndef DESTDIR
352         - killall udevd
353         - rm -rf $(udevdb)
354         - $(sbindir)/udevd --daemon
355 endif
356         @extras="$(EXTRAS)"; for target in $$extras; do \
357                 echo $$target; \
358                 $(MAKE) prefix=$(prefix) -C $$target $@; \
359         done;
360 .PHONY: install
361
362 uninstall: uninstall-man
363         - rm $(configdir)/rules.d/50-udev.rules
364         - rm $(configdir)/udev.conf
365         - rmdir $(configdir)/rules.d
366         - rmdir $(configdir)
367         - rm $(sbindir)/udev
368         - rm $(sbindir)/udevd
369         - rm $(sbindir)/udevsend
370         - rm $(sbindir)/udevinitsend
371         - rm $(sbindir)/udeveventrecoreder
372         - rm $(sbindir)/udevcontrol
373         - rm $(sbindir)/udevstart
374         - rm $(usrsbindir)/udevmonitor
375         - rm $(usrbindir)/udevinfo
376         - rm $(usrbindir)/udevtest
377         - rm -rf $(udevdb)
378         - rmdir $(udevdir)
379         - killall udevd
380         @extras="$(EXTRAS)"; for target in $$extras; do \
381                 echo $$target; \
382                 $(MAKE) prefix=$(prefix) -C $$target $@; \
383         done;
384 .PHONY: uninstall-man
385
386 test tests: all
387         @ cd test && ./udev-test.pl
388         @ cd test && ./udevstart-test.pl
389 .PHONY: test tests
390