chiark / gitweb /
[PATCH] make udevsend binary even smaller
[elogind.git] / Makefile
1 # Makefile for udev
2 #
3 # Copyright (C) 2003  Greg Kroah-Hartman <greg@kroah.com>
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 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17 #
18
19 # Set the following to control the use of syslog
20 # Set it to `false' to remove all logging
21 USE_LOG = true
22
23 # Set the following to `true' to log the debug
24 # and make a unstripped, unoptimized  binary.
25 # Leave this set to `false' for production use.
26 DEBUG = false
27
28 # Set the following to `true' to make udev emit a D-BUS signal when a
29 # new node is created.
30 USE_DBUS = false
31
32
33 ROOT =          udev
34 DAEMON =        udevd
35 SENDER =        udevsend
36 HELPER =        udevinfo
37 VERSION =       015_bk
38 INSTALL_DIR =   /usr/local/bin
39 RELEASE_NAME =  $(ROOT)-$(VERSION)
40 LOCAL_CFG_DIR = etc/udev
41 HOTPLUG_EXEC =  $(ROOT)
42
43 DESTDIR =
44 # override this to make udev look in a different location for it's config files
45 prefix =
46 exec_prefix =   ${prefix}
47 etcdir =        ${prefix}/etc
48 sbindir =       ${exec_prefix}/sbin
49 mandir =        ${prefix}/usr/share/man
50 hotplugdir =    ${etcdir}/hotplug.d/default
51 dbusdir =       ${etcdir}/dbus-1/system.d
52 configdir =     ${etcdir}/udev/
53 initdir =       ${etcdir}/init.d/
54 srcdir = .
55
56 INSTALL = /usr/bin/install -c
57 INSTALL_PROGRAM = ${INSTALL}
58 INSTALL_DATA  = ${INSTALL} -m 644
59 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
60
61 # To build any of the extras programs, run with:
62 #       make EXTRAS="extras/a extras/b" 
63 EXTRAS=
64
65 # place to put our device nodes
66 udevdir = ${prefix}/udev
67
68 # Comment out this line to build with something other 
69 # than the local version of klibc
70 #USE_KLIBC = true
71
72 # If you are running a cross compiler, you may want to set this
73 # to something more interesting, like "arm-linux-".  If you want
74 # to compile vs uClibc, that can be done here as well.
75 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
76 CC = $(CROSS)gcc
77 LD = $(CROSS)gcc
78 AR = $(CROSS)ar
79 STRIP = $(CROSS)strip
80 RANLIB = $(CROSS)ranlib
81
82 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0
83
84 # code taken from uClibc to determine the current arch
85 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
86         -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
87
88 # code taken from uClibc to determine the gcc include dir
89 GCCINCDIR := ${shell $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
90
91 # code taken from uClibc to determine the libgcc.a filename
92 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
93
94 # use '-Os' optimization if available, else use -O2
95 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
96                 then echo "-Os"; else echo "-O2" ; fi}
97
98 # add -Wredundant-decls when libsysfs gets cleaned up
99 WARNINGS := -Wall 
100
101 # Some nice architecture specific optimizations
102 ifeq ($(strip $(TARGET_ARCH)),arm)
103         OPTIMIZATION+=-fstrict-aliasing
104 endif
105 ifeq ($(strip $(TARGET_ARCH)),i386)
106         OPTIMIZATION+=-march=i386
107         OPTIMIZATION += ${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \
108                 /dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi}
109         OPTIMIZATION += ${shell if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \
110                 /dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi}
111         CFLAGS+=-pipe
112 else
113         CFLAGS+=-pipe
114 endif
115
116 ifeq ($(strip $(USE_LOG)),true)
117         CFLAGS  += -DLOG
118 endif
119
120 # if DEBUG is enabled, then we do not strip or optimize
121 ifeq ($(strip $(DEBUG)),true)
122         CFLAGS  += -O1 -g -DDEBUG -D_GNU_SOURCE
123         LDFLAGS += -Wl,-warn-common
124         STRIPCMD = /bin/true -Since_we_are_debugging
125 else
126         CFLAGS  += $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
127         LDFLAGS += -s -Wl,-warn-common
128         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
129 endif
130
131 # If we are using our version of klibc, then we need to build, link it, and then
132 # link udev against it statically.
133 # Otherwise, use glibc and link dynamically.
134 ifeq ($(strip $(USE_KLIBC)),true)
135         KLIBC_BASE      = $(PWD)/klibc
136         KLIBC_DIR       = $(KLIBC_BASE)/klibc
137         INCLUDE_DIR     := $(KLIBC_DIR)/include
138         LINUX_INCLUDE_DIR       := $(KLIBC_BASE)/linux/include
139         include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
140         # arch specific objects
141         ARCH_LIB_OBJS = \
142                         $(KLIBC_DIR)/libc.a
143
144
145         CRT0 = $(KLIBC_DIR)/crt0.o
146         LIBC =  $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
147         CFLAGS += $(WARNINGS) -nostdinc                 \
148                 -D__KLIBC__ -fno-builtin-printf         \
149                 -I$(INCLUDE_DIR)                        \
150                 -I$(KLIBC_DIR)/arch/$(ARCH)/include     \
151                 -I$(INCLUDE_DIR)/bits$(BITSIZE)         \
152                 -I$(GCCINCDIR)                          \
153                 -I$(LINUX_INCLUDE_DIR)
154         LIB_OBJS =
155         LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
156         UDEVD =
157 else
158         WARNINGS += -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
159         CRT0 =
160         LIBC = 
161         CFLAGS += $(WARNINGS) -I$(GCCINCDIR)
162         LIB_OBJS = -lc
163         LDFLAGS =
164         UDEVD = $(DAEMON)
165 endif
166
167 CFLAGS += -I$(PWD)/libsysfs
168
169 all: $(ROOT) $(SENDER) $(UDEVD) $(HELPER)
170         @extras="$(EXTRAS)" ; for target in $$extras ; do \
171                 echo $$target ; \
172                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
173                         -C $$target $@ ; \
174         done ; \
175
176 $(ROOT): $(LIBC)
177
178 $(ARCH_LIB_OBJS) : $(CRT0)
179
180 $(CRT0):
181         $(MAKE) -C klibc
182
183 TDB =   tdb/tdb.o       \
184         tdb/spinlock.o
185
186 SYSFS = $(PWD)/libsysfs/sysfs_bus.o     \
187         $(PWD)/libsysfs/sysfs_class.o   \
188         $(PWD)/libsysfs/sysfs_device.o  \
189         $(PWD)/libsysfs/sysfs_dir.o     \
190         $(PWD)/libsysfs/sysfs_driver.o  \
191         $(PWD)/libsysfs/sysfs_utils.o   \
192         $(PWD)/libsysfs/dlist.o
193
194 OBJS =  udev_config.o   \
195         udev-add.o      \
196         udev-remove.o   \
197         udevdb.o        \
198         namedev.o       \
199         namedev_parse.o \
200         $(SYSFS)        \
201         $(TDB)
202
203 HEADERS =       udev.h          \
204                 namedev.h       \
205                 udev_version.h  \
206                 udev_dbus.h     \
207                 udevdb.h        \
208                 klibc_fixups.h  \
209                 logging.h       \
210                 list.h
211
212 ifeq ($(strip $(USE_KLIBC)),true)
213         OBJS += klibc_fixups.o
214 endif
215
216 ifeq ($(USE_DBUS), true)
217         CFLAGS += -DUSE_DBUS
218         CFLAGS += $(shell pkg-config --cflags dbus-1)
219         LDFLAGS += $(shell pkg-config --libs dbus-1)
220         OBJS += udev_dbus.o
221 endif
222
223 # header files automatically generated
224 GEN_HEADERS =   udev_version.h
225
226 # Rules on how to create the generated header files
227 udev_version.h:
228         @echo \#define UDEV_VERSION     \"$(VERSION)\" > $@
229         @echo \#define UDEV_ROOT        \"$(udevdir)/\" >> $@
230         @echo \#define UDEV_DB          \"$(udevdir)/\.udev.tdb\" >> $@
231         @echo \#define UDEV_CONFIG_DIR  \"$(configdir)\" >> $@
232         @echo \#define UDEV_CONFIG_FILE \"$(configdir)\udev.conf\" >> $@
233         @echo \#define UDEV_RULES_FILE  \"$(configdir)\udev.rules\" >> $@
234         @echo \#define UDEV_PERMISSION_FILE     \"$(configdir)\udev.permissions\" >> $@
235         @echo \#define UDEV_BIN         \"$(DESTDIR)$(sbindir)/udev\" >> $@
236         @echo \#define UDEVD_BIN        \"$(DESTDIR)$(sbindir)/udevd\" >> $@
237         @echo \#define UDEVD_SOCK       \"$(udevdir)/\.udevd.sock\" >> $@
238         @echo \#define UDEVD_LOCK       \"$(udevdir)/\.udevd.lock\" >> $@
239
240 # config files automatically generated
241 GEN_CONFIGS =   $(LOCAL_CFG_DIR)/udev.conf
242
243 # Rules on how to create the generated config files
244 $(LOCAL_CFG_DIR)/udev.conf:
245         sed -e "s:@udevdir@:$(udevdir):" < $(LOCAL_CFG_DIR)/udev.conf.in > $@
246
247
248 $(OBJS): $(GEN_HEADERS)
249 udev.o: $(GEN_HEADERS)
250
251 $(ROOT): udev.o $(OBJS) $(HEADERS) $(GEN_HEADERS)
252         $(LD) $(LDFLAGS) -o $@ $(CRT0) udev.o $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
253         $(STRIPCMD) $@
254
255 $(HELPER): udevinfo.o $(OBJS) $(HEADERS)
256         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevinfo.o udev_config.o udevdb.o $(SYSFS) $(TDB) $(LIB_OBJS) $(ARCH_LIB_OBJS)
257         $(STRIPCMD) $@
258
259 $(DAEMON): udevd.h udevd.o
260         $(LD) $(LDFLAGS) -lpthread -o $@ $(CRT0) udevd.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
261         $(STRIPCMD) $@
262
263 $(SENDER): udevd.h udevsend.o
264         $(LD) $(LDFLAGS) -o $@ $(CRT0) udevsend.o $(LIB_OBJS) $(ARCH_LIB_OBJS)
265         $(STRIPCMD) $@
266
267 clean:
268         -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
269          | xargs rm -f 
270         -rm -f core $(ROOT) $(GEN_HEADERS) $(GEN_CONFIGS) $(HELPER) $(DAEMON) $(SENDER)
271         $(MAKE) -C klibc clean
272         @extras="$(EXTRAS)" ; for target in $$extras ; do \
273                 echo $$target ; \
274                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
275                         -C $$target $@ ; \
276         done ; \
277
278 DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v -e CVS -e "\.tar\.gz$" -e "\/\." -e releases -e BitKeeper -e SCCS -e "\.tdb$" -e test/sys | sort )
279 DISTDIR := $(RELEASE_NAME)
280 srcdir = .
281 release: clean
282         @echo "--------------------------cut here------------------------"
283         @echo "cd .."
284         @echo "rm -rf $(DISTDIR)"
285         @echo "mkdir $(DISTDIR)"
286         @echo "chmod 777 $(DISTDIR)"
287         @echo "cp -avr udev/* $(DISTDIR)"
288         @echo "tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz"
289         @echo "rm -rf $(DISTDIR)"
290         @echo "--------------------------cut here------------------------"
291
292
293 small_release: $(DISTFILES) clean
294 #       @echo $(DISTFILES)
295         @-rm -rf $(DISTDIR)
296         @mkdir $(DISTDIR)
297         @-chmod 777 $(DISTDIR)
298         @for file in $(DISTFILES); do                   \
299                 if test -d $$file; then                 \
300                         mkdir $(DISTDIR)/$$file;        \
301                 else                                    \
302                         cp -p $$file $(DISTDIR)/$$file; \
303                 fi;                                     \
304         done
305         @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
306         @rm -rf $(DISTDIR)
307         @echo "Built $(RELEASE_NAME).tar.gz"
308
309
310 ifeq ($(USE_DBUS), true)
311 install-dbus-policy:
312         $(INSTALL) -d $(DESTDIR)$(dbusdir)
313         $(INSTALL_DATA) etc/dbus-1/system.d/udev_sysbus_policy.conf $(DESTDIR)$(dbusdir)
314
315 uninstall-dbus-policy:
316         - rm $(DESTDIR)$(dbusdir)/udev_sysbus_policy.conf
317 else
318 install-dbus-policy:
319         -
320 uninstall-dbus-policy:
321         -
322 endif
323
324 install-config: $(GEN_CONFIGS)
325         $(INSTALL) -d $(DESTDIR)$(configdir)
326         @if [ ! -r $(DESTDIR)$(configdir)udev.conf ]; then \
327                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
328                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.conf $(DESTDIR)$(configdir); \
329         fi
330         @if [ ! -r $(DESTDIR)$(configdir)udev.rules ]; then \
331                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
332                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.rules $(DESTDIR)$(configdir); \
333         fi
334         @if [ ! -r $(DESTDIR)$(configdir)udev.permissions ]; then \
335                 echo $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
336                 $(INSTALL_DATA) $(LOCAL_CFG_DIR)/udev.permissions $(DESTDIR)$(configdir); \
337         fi
338
339 install: install-config install-dbus-policy all
340         $(INSTALL) -d $(DESTDIR)$(udevdir)
341         $(INSTALL) -d $(DESTDIR)$(hotplugdir)
342         $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
343         $(INSTALL_PROGRAM) -D $(DAEMON) $(DESTDIR)$(sbindir)/$(DAEMON)
344         $(INSTALL_PROGRAM) -D $(SENDER) $(DESTDIR)$(sbindir)/$(SENDER)
345         $(INSTALL_PROGRAM) -D $(HELPER) $(DESTDIR)$(sbindir)/$(HELPER)
346         @if [ "x$(USE_LSB)" = "xtrue" ]; then \
347                 $(INSTALL_PROGRAM) -D etc/init.d/udev.init.LSB $(DESTDIR)$(initdir)/udev; \
348                 ln -s $(DESTDIR)$(initdir)/udev $(sbindir)/rcudev; \
349         else \
350                 $(INSTALL_PROGRAM) -D etc/init.d/udev $(DESTDIR)$(initdir)/udev; \
351         fi
352         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
353         $(INSTALL_DATA) -D udevinfo.8 $(DESTDIR)$(mandir)/man8/udevinfo.8
354         - rm -f $(DESTDIR)$(hotplugdir)/$(HOTPLUG_EXEC).hotplug
355         - ln -f -s $(sbindir)/$(HOTPLUG_EXEC) $(DESTDIR)$(hotplugdir)/udev.hotplug
356         @extras="$(EXTRAS)" ; for target in $$extras ; do \
357                 echo $$target ; \
358                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
359                         -C $$target $@ ; \
360         done ; \
361
362 uninstall: uninstall-dbus-policy
363         - rm $(hotplugdir)/udev.hotplug
364         - rm $(configdir)/udev.permissions
365         - rm $(configdir)/udev.rules
366         - rm $(configdir)/udev.conf
367         - rm $(initdir)/udev
368         - rm $(mandir)/man8/udev.8
369         - rm $(mandir)/man8/udevinfo.8
370         - rm $(sbindir)/$(ROOT)
371         - rm $(sbindir)/$(DAEMON)
372         - rm $(sbindir)/$(SENDER)
373         - rm $(sbindir)/$(HELPER)
374         - rmdir $(hotplugdir)
375         - rmdir $(configdir)
376         - rmdir $(udevdir)
377         @extras="$(EXTRAS)" ; for target in $$extras ; do \
378                 echo $$target ; \
379                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
380                         -C $$target $@ ; \
381         done ; \