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