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