chiark / gitweb /
aa1d45bdb72a584bd24c5dc3ca05d187e30db265
[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 `true' to make a debuggable build.
20 # Leave this set to `false' for production use.
21 DEBUG = false
22
23
24 ROOT =          udev
25 VERSION =       008_bk
26 INSTALL_DIR =   /usr/local/bin
27 RELEASE_NAME =  $(ROOT)-$(VERSION)
28
29 DESTDIR =
30 # override this to make udev look in a different location for it's config files
31 prefix =
32 exec_prefix =   ${prefix}
33 etcdir =        ${prefix}/etc
34 sbindir =       ${exec_prefix}/sbin
35 mandir =        ${prefix}/usr/share/man
36 hotplugdir =    ${etcdir}/hotplug.d/default
37 configdir =     ${etcdir}/udev/
38 srcdir = .
39
40 INSTALL = /usr/bin/install -c
41 INSTALL_PROGRAM = ${INSTALL}
42 INSTALL_DATA  = ${INSTALL} -m 644
43 INSTALL_SCRIPT = ${INSTALL_PROGRAM}
44
45 # To build any of the extras programs, run with:
46 #       make EXTRAS="extras/a extras/b" 
47 EXTRAS=
48
49 # place to put our device nodes
50 udevdir = ${prefix}/udev/
51
52 # Comment out this line to build with something other 
53 # than the local version of klibc
54 #KLIBC = true
55
56 # If you are running a cross compiler, you may want to set this
57 # to something more interesting, like "arm-linux-".  I you want
58 # to compile vs uClibc, that can be done here as well.
59 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
60 CC = $(CROSS)gcc
61 LD = $(CROSS)gcc
62 AR = $(CROSS)ar
63 STRIP = $(CROSS)strip
64 RANLIB = $(CROSS)ranlib
65
66 export CROSS CC AR STRIP RANLIB CFLAGS LDFLAGS LIB_OBJS ARCH_LIB_OBJS CRT0
67
68 # code taken from uClibc to determine the current arch
69 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
70         -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/powerpc/ppc/g'}
71
72 # code taken from uClibc to determine the gcc include dir
73 GCCINCDIR := ${shell $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
74
75 # code taken from uClibc to determine the libgcc.a filename
76 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
77
78 # use '-Os' optimization if available, else use -O2
79 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
80                 then echo "-Os"; else echo "-O2" ; fi}
81
82 # add -Wredundant-decls when libsysfs gets cleaned up
83 WARNINGS := -Wall -Wshadow -Wstrict-prototypes -Wmissing-prototypes -Wmissing-declarations
84
85 # Some nice architecture specific optimizations
86 ifeq ($(strip $(TARGET_ARCH)),arm)
87         OPTIMIZATION+=-fstrict-aliasing
88 endif
89 ifeq ($(strip $(TARGET_ARCH)),i386)
90         OPTIMIZATION+=-march=i386
91         OPTIMIZATION += ${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \
92                 /dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi}
93         OPTIMIZATION += ${shell if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \
94                 /dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi}
95         CFLAGS+=-pipe
96 else
97         CFLAGS+=-pipe
98 endif
99
100 # if DEBUG is enabled, then we do not strip or optimize
101 ifeq ($(strip $(DEBUG)),true)
102         CFLAGS  += $(WARNINGS) -O1 -g -DDEBUG -D_GNU_SOURCE
103         LDFLAGS += -Wl,-warn-common
104         STRIPCMD = /bin/true -Since_we_are_debugging
105 else
106         CFLAGS  += $(WARNINGS) $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
107         LDFLAGS += -s -Wl,-warn-common
108         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
109 endif
110
111 # If we are using our version of klibc, then we need to build and link it.
112 # Otherwise, use glibc and link statically.
113 ifeq ($(strip $(KLIBC)),true)
114         KLIBC_BASE      = $(PWD)/klibc
115         KLIBC_DIR       = $(KLIBC_BASE)/klibc
116         INCLUDE_DIR     := $(KLIBC_DIR)/include
117         LINUX_INCLUDE_DIR       := $(KLIBC_BASE)/linux/include
118         include $(KLIBC_DIR)/arch/$(ARCH)/MCONFIG
119         # arch specific objects
120         ARCH_LIB_OBJS = \
121                         $(KLIBC_DIR)/libc.a
122
123
124         CRT0 = $(KLIBC_DIR)/crt0.o
125         LIBC =  $(ARCH_LIB_OBJS) $(LIB_OBJS) $(CRT0)
126         CFLAGS += -nostdinc -I$(INCLUDE_DIR) -I$(KLIBC_DIR)/arch/$(ARCH)/include \
127                 -I$(INCLUDE_DIR)/bits$(BITSIZE) -I$(GCCINCDIR) -I$(LINUX_INCLUDE_DIR) \
128                 -D__KLIBC__
129         LIB_OBJS =
130         LDFLAGS = --static --nostdlib -nostartfiles -nodefaultlibs
131 else
132         CRT0 =
133         LIBC = 
134         CFLAGS += -I$(GCCINCDIR)
135         LIB_OBJS = -lc
136         LDFLAGS = --static 
137 endif
138
139 CFLAGS += -I$(PWD)/libsysfs
140
141 all: $(ROOT)
142         @for target in $(EXTRAS) ; do \
143                 echo $$target ; \
144                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
145                         -C $$target $@ ; \
146         done ; \
147
148 $(ROOT): $(LIBC)
149
150 $(ARCH_LIB_OBJS) : $(CRT0)
151
152 $(CRT0):
153         $(MAKE) -C klibc
154
155 TDB =   tdb/tdb.o       \
156         tdb/spinlock.o
157
158 SYSFS = $(PWD)/libsysfs/sysfs_bus.o     \
159         $(PWD)/libsysfs/sysfs_class.o   \
160         $(PWD)/libsysfs/sysfs_device.o  \
161         $(PWD)/libsysfs/sysfs_dir.o     \
162         $(PWD)/libsysfs/sysfs_driver.o  \
163         $(PWD)/libsysfs/sysfs_utils.o   \
164         $(PWD)/libsysfs/dlist.o
165
166 OBJS =  udev.o          \
167         udev_config.o   \
168         udev-add.o      \
169         udev-remove.o   \
170         udevdb.o        \
171         logging.o       \
172         namedev.o       \
173         namedev_parse.o \
174         $(SYSFS)        \
175         $(TDB)
176
177 ifeq ($(strip $(KLIBC)),true)
178         OBJS += klibc_fixups.o
179 endif
180
181 # header files automatically generated
182 GEN_HEADERS =   udev_version.h
183
184 # Rules on how to create the generated header files
185 udev_version.h:
186         @echo \#define UDEV_VERSION     \"$(VERSION)\" > $@
187         @echo \#define UDEV_ROOT        \"$(udevdir)\" >> $@
188         @echo \#define UDEV_DB          \"$(udevdir)\.udev.tdb\" >> $@
189         @echo \#define UDEV_CONFIG_DIR  \"$(configdir)\" >> $@
190         @echo \#define UDEV_CONFIG_FILE \"$(configdir)\udev.conf\" >> $@
191         @echo \#define UDEV_RULES_FILE  \"$(configdir)\udev.rules\" >> $@
192         @echo \#define UDEV_PERMISSION_FILE     \"$(configdir)\udev.permissions\" >> $@
193
194 $(OBJS): $(GEN_HEADERS)
195
196 $(ROOT): $(OBJS)
197         $(LD) $(LDFLAGS) -o $(ROOT) $(CRT0) $(OBJS) $(LIB_OBJS) $(ARCH_LIB_OBJS)
198         $(STRIPCMD) $(ROOT)
199
200 clean:
201         -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
202          | xargs rm -f 
203         -rm -f core $(ROOT) $(GEN_HEADERS)
204         $(MAKE) -C klibc clean
205         @for target in $(EXTRAS) ; do \
206                 echo $$target ; \
207                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
208                         -C $$target $@ ; \
209         done ; \
210
211 DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v CVS | grep -v "\.tar\.gz" | grep -v "\/\." | grep -v releases | grep -v BitKeeper | grep -v SCCS | grep -v "\.tdb" | grep -v "test\/sys" | sort )
212 DISTDIR := $(RELEASE_NAME)
213 srcdir = .
214 release: clean
215         @echo "--------------------------cut here------------------------"
216         @echo "cd .."
217         @echo "rm -rf $(DISTDIR)"
218         @echo "mkdir $(DISTDIR)"
219         @echo "chmod 777 $(DISTDIR)"
220         @echo "cp -avr udev/* $(DISTDIR)"
221         @echo "tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz"
222         @echo "rm -rf $(DISTDIR)"
223         @echo "--------------------------cut here------------------------"
224
225
226 small_release: $(DISTFILES) clean
227 #       @echo $(DISTFILES)
228         @-rm -rf $(DISTDIR)
229         @mkdir $(DISTDIR)
230         @-chmod 777 $(DISTDIR)
231         @for file in $(DISTFILES); do                   \
232                 if test -d $$file; then                 \
233                         mkdir $(DISTDIR)/$$file;        \
234                 else                                    \
235                         cp -p $$file $(DISTDIR)/$$file; \
236                 fi;                                     \
237         done
238         @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
239         @rm -rf $(DISTDIR)
240         @echo "Built $(RELEASE_NAME).tar.gz"
241
242
243 install: all
244         $(INSTALL) -d $(DESTDIR)$(udevdir)
245         $(INSTALL) -d $(DESTDIR)$(configdir)
246         $(INSTALL) -d $(DESTDIR)$(hotplugdir)
247         $(INSTALL_PROGRAM) -D $(ROOT) $(DESTDIR)$(sbindir)/$(ROOT)
248         $(INSTALL_DATA) -D udev.8 $(DESTDIR)$(mandir)/man8/udev.8
249         $(INSTALL_DATA) udev.conf $(DESTDIR)$(configdir)
250         $(INSTALL_DATA) udev.rules $(DESTDIR)$(configdir)
251         $(INSTALL_DATA) udev.permissions $(DESTDIR)$(configdir)
252         - rm -f $(DESTDIR)$(hotplugdir)/udev.hotplug
253         - ln -s $(sbindir)/$(ROOT) $(DESTDIR)$(hotplugdir)/udev.hotplug
254         @for target in $(EXTRAS) ; do \
255                 echo $$target ; \
256                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
257                         -C $$target $@ ; \
258         done ; \
259
260 uninstall:
261         - rm $(hotplugdir)/udev.hotplug
262         - rm $(configdir)/udev.permissions
263         - rm $(configdir)/udev.rules
264         - rm $(configdir)/udev.conf
265         - rm $(mandir)/man8/udev.8
266         - rm $(sbindir)/$(ROOT)
267         - rmdir $(hotplugdir)
268         - rmdir $(configdir)
269         - rmdir $(udevdir)
270         @for target in $(EXTRAS) ; do \
271                 echo $$target ; \
272                 $(MAKE) prefix=$(prefix) LD="$(LD)" SYSFS="$(SYSFS)" \
273                         -C $$target $@ ; \
274         done ; \
275
276