chiark / gitweb /
3f9fef49d5b3bcb54a2a870a3c410104c26e0a1c
[elogind.git] / Makefile
1 # Makefile for diethotplug
2 #
3 # Copyright (C) 2000,2001 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 = true
22
23
24 ROOT =          udev
25 VERSION =       0.2
26 INSTALL_DIR =   /usr/local/bin
27 RELEASE_NAME =  $(ROOT)-$(VERSION)
28
29
30 # Comment out this line to build with something other 
31 # than the local version of klibc
32 #KLIBC = true
33
34 # If you are running a cross compiler, you may want to set this
35 # to something more interesting, like "arm-linux-".  I you want
36 # to compile vs uClibc, that can be done here as well.
37 CROSS = #/usr/i386-linux-uclibc/usr/bin/i386-uclibc-
38 CC = $(CROSS)gcc
39 AR = $(CROSS)ar
40 STRIP = $(CROSS)strip
41 RANLIB = $(CROSS)ranlib
42
43 export CROSS CC AR STRIP RANLIB
44
45 # code taken from uClibc to determine the current arch
46 ARCH := ${shell $(CC) -dumpmachine | sed -e s'/-.*//' -e 's/i.86/i386/' -e 's/sparc.*/sparc/' \
47         -e 's/arm.*/arm/g' -e 's/m68k.*/m68k/' -e 's/ppc/powerpc/g'}
48
49 # code taken from uClibc to determine the gcc include dir
50 GCCINCDIR := ${shell $(CC) -print-search-dirs | sed -ne "s/install: \(.*\)/\1include/gp"}
51
52 # code taken from uClibc to determine the libgcc.a filename
53 GCC_LIB := $(shell $(CC) -print-libgcc-file-name )
54
55 # use '-Os' optimization if available, else use -O2
56 OPTIMIZATION := ${shell if $(CC) -Os -S -o /dev/null -xc /dev/null >/dev/null 2>&1; \
57                 then echo "-Os"; else echo "-O2" ; fi}
58
59 WARNINGS := -Wall -Wshadow -Wstrict-prototypes 
60
61 # Some nice architecture specific optimizations
62 ifeq ($(strip $(TARGET_ARCH)),arm)
63         OPTIMIZATION+=-fstrict-aliasing
64 endif
65 ifeq ($(strip $(TARGET_ARCH)),i386)
66         OPTIMIZATION+=-march=i386
67         OPTIMIZATION += ${shell if $(CC) -mpreferred-stack-boundary=2 -S -o /dev/null -xc \
68                 /dev/null >/dev/null 2>&1; then echo "-mpreferred-stack-boundary=2"; fi}
69         OPTIMIZATION += ${shell if $(CC) -malign-functions=0 -malign-jumps=0 -S -o /dev/null -xc \
70                 /dev/null >/dev/null 2>&1; then echo "-malign-functions=0 -malign-jumps=0"; fi}
71         CFLAGS+=-pipe
72 else
73         CFLAGS+=-pipe
74 endif
75
76 # if DEBUG is enabled, then we do not strip or optimize
77 ifeq ($(strip $(DEBUG)),true)
78         CFLAGS  += $(WARNINGS) -O1 -g -DDEBUG -D_GNU_SOURCE
79         LDFLAGS += -Wl,-warn-common
80         STRIPCMD = /bin/true -Since_we_are_debugging
81 else
82         CFLAGS  += $(WARNINGS) $(OPTIMIZATION) -fomit-frame-pointer -D_GNU_SOURCE
83         LDFLAGS += -s -Wl,-warn-common
84         STRIPCMD = $(STRIP) -s --remove-section=.note --remove-section=.comment
85 endif
86
87 # If we are using our version of klibc, then we need to build and link it.
88 # Otherwise, use glibc and link statically.
89 ifeq ($(strip $(KLIBC)),true)
90         KLIBC_DIR       = klibc
91         INCLUDE_DIR     := $(KLIBC_DIR)/include
92         # arch specific objects
93         ARCH_LIB_OBJS = \
94                         $(KLIBC_DIR)/bin-$(ARCH)/start.o        \
95                         $(KLIBC_DIR)/bin-$(ARCH)/klibc.a
96
97         LIB_OBJS =      $(GCC_LIB)
98
99         LIBC =  $(ARCH_LIB_OBJS) $(LIB_OBJS)
100         CFLAGS += -nostdinc -I$(INCLUDE_DIR) -I$(GCCINCDIR)
101         LDFLAGS = --static --nostdlib -nostartfiles
102 else
103         LIBC = 
104         CFLAGS += -I$(GCCINCDIR)
105         LIB_OBJS = -lc
106         LDFLAGS = --static 
107 endif
108
109 LIB=libsysfs
110
111 all: $(LIBC) $(ROOT)
112
113 $(ARCH_LIB_OBJS) :
114         $(MAKE) -C klibc
115
116 LIBSYSFS = libsysfs/libsysfs.a
117 TDB = tdb/tdb.o tdb/spinlock.o
118
119 OBJS =  udev.o          \
120         udev-add.o      \
121         udev-remove.o   \
122         udevdb.o        \
123         logging.o       \
124         namedev.o       \
125         $(TDB)
126
127 libsysfs/libsysfs.a:
128         $(MAKE) -C libsysfs
129
130 tdb/tdb.o:
131         $(MAKE) -C tdb
132
133 # header files automatically generated
134 GEN_HEADERS =   udev_version.h
135
136 # Rules on how to create the generated header files
137 udev_version.h:
138         @echo \#define UDEV_VERSION \"$(VERSION)\" > $@
139
140
141 $(ROOT): $(GEN_HEADERS) $(OBJS) $(LIBSYSFS) $(TDB)
142         $(MAKE) -C libsysfs
143         $(CC) $(LDFLAGS) -o $(ROOT) $(OBJS) -lsysfs $(LIB_OBJS) -L$(LIB) $(ARCH_LIB_OBJS)
144         $(STRIPCMD) $(ROOT)
145
146 clean:
147         -find . \( -not -type d \) -and \( -name '*~' -o -name '*.[oas]' \) -type f -print \
148          | xargs rm -f 
149         -rm -f core $(ROOT) $(GEN_HEADERS)
150         $(MAKE) -C klibc clean
151         $(MAKE) -C libsysfs clean
152         $(MAKE) -C tdb clean
153
154 DISTFILES = $(shell find . \( -not -name '.' \) -print | grep -v CVS | grep -v "\.tar\.gz" | grep -v "\/\." | grep -v releases | grep -v BitKeeper | grep -v SCCS )
155 DISTDIR := $(RELEASE_NAME)
156 srcdir = .
157 release: $(DISTFILES) clean
158 #       @echo $(DISTFILES)
159         @-rm -rf $(DISTDIR)
160         @mkdir $(DISTDIR)
161         @-chmod 777 $(DISTDIR)
162         @for file in $(DISTFILES); do                   \
163                 if test -d $$file; then                 \
164                         mkdir $(DISTDIR)/$$file;        \
165                 else                                    \
166                         cp -p $$file $(DISTDIR)/$$file; \
167                 fi;                                     \
168         done
169         @tar -c $(DISTDIR) | gzip -9 > $(RELEASE_NAME).tar.gz
170         @rm -rf $(DISTDIR)
171         @echo "Built $(RELEASE_NAME).tar.gz"