OSDN Git Service

Begin converting the client utils
[uclinux-h8/uClibc.git] / Makefile
1 # Makefile for uClibc
2 #
3 # Copyright (C) 2000-2003 Erik Andersen <andersen@uclibc.org>
4 #
5 # This program is free software; you can redistribute it and/or
6 # modify it under the terms of the GNU Library General Public
7 # License as published by the Free Software Foundation; either
8 # version 2 of the License, or (at your option) any later
9 # version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU Library General Public License for more details.
15 #
16 # You should have received a copy of the GNU Library General
17 # Public License along with this program; if not, write to the
18 # Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19 # Boston, MA 02111-1307 USA
20
21
22 #--------------------------------------------------------------
23 # You shouldn't need to mess with anything beyond this point...
24 #--------------------------------------------------------------
25 noconfig_targets := menuconfig config oldconfig randconfig \
26         defconfig allyesconfig allnoconfig clean distclean \
27         release tags TAGS
28 TOPDIR=./
29 include Rules.mak
30
31 DIRS = ldso libc libcrypt libresolv libnsl libutil libm libpthread
32 ifeq ($(strip $(UCLIBC_HAS_GETTEXT_AWARENESS)),y)
33         DIRS += libintl
34 endif
35
36 ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
37
38 all: headers pregen subdirs shared finished
39
40 # In this section, we need .config
41 -include .config.cmd
42
43 .PHONY: $(SHARED_TARGET)
44 shared: $(SHARED_TARGET)
45 ifeq ($(strip $(HAVE_SHARED)),y)
46         @$(MAKE) -C libc shared
47         @$(MAKE) -C ldso shared
48         @$(MAKE) -C libcrypt shared
49         @$(MAKE) -C libresolv shared
50         @$(MAKE) -C libnsl shared
51         @$(MAKE) -C libutil shared
52         @$(MAKE) -C libm shared
53         @$(MAKE) -C libpthread shared
54 ifeq ($(strip $(UCLIBC_HAS_GETTEXT_AWARENESS)),y)
55         @$(MAKE) -C libintl shared
56 endif
57 else
58 ifeq ($(SHARED_TARGET),)
59         @echo
60         @echo Not building shared libraries...
61         @echo
62 endif
63 endif
64
65 ifneq ($(SHARED_TARGET),)
66
67 lib/main.o: $(ROOTDIR)/lib/libc/main.c
68         $(CC) $(CFLAGS) $(ARCH_CFLAGS) -c -o $@ $(ROOTDIR)/lib/libc/main.c
69
70 bogus $(SHARED_TARGET): lib/libc.a lib/main.o Makefile
71         make -C $(ROOTDIR) relink
72         $(CC) -nostartfiles -o $(SHARED_TARGET) $(ARCH_CFLAGS) -Wl,-elf2flt -nostdlib           \
73                 -Wl,-shared-lib-id,${LIBID}                             \
74                 lib/main.o \
75                 -Wl,--whole-archive,lib/libc.a,-lgcc,--no-whole-archive
76         $(OBJCOPY) -L _GLOBAL_OFFSET_TABLE_ -L main -L __main -L _start \
77                 -L __uClibc_main -L __uClibc_start_main -L lib_main \
78                 -L _exit_dummy_ref              \
79                 -L __do_global_dtors -L __do_global_ctors               \
80                 -L __CTOR_LIST__ -L __DTOR_LIST__                       \
81                 -L _current_shared_library_a5_offset_                   \
82                 $(SHARED_TARGET).gdb
83         $(LN) -sf $(SHARED_TARGET).gdb .
84 endif
85
86 finished: shared
87         @echo
88         @echo Finally finished compiling...
89         @echo
90
91 #
92 # Target for uClinux distro
93 #
94 .PHONY: romfs
95 romfs:
96         @if [ "$(CONFIG_BINFMT_SHARED_FLAT)" = "y" ]; then \
97                 [ -e $(ROMFSDIR)/lib ] || $(INSTALL) -d $(ROMFSDIR)/lib; \
98                 $(ROMFSINST) $(SHARED_TARGET) /lib/lib$(LIBID).so; \
99         fi
100 ifeq ($(strip $(HAVE_SHARED)),y)
101         $(INSTALL) -d $(ROMFSDIR)/lib
102         $(INSTALL) -m 644 lib/lib*-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
103                 $(ROMFSDIR)/lib
104         cp -fa lib/*.so.* $(ROMFSDIR)/lib/.
105         @if [ -x lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so ] ; then \
106             set -x -e; \
107             $(INSTALL) -m 755 lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
108                         $(ROMFSDIR)/lib; \
109                 $(ROMFSINST) -s \
110                         /lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
111                         /lib/ld-linux.so.2; \
112         fi;
113 endif
114
115 include/bits/uClibc_config.h: .config
116         @if [ ! -x ./extra/config/conf ] ; then \
117             make -C extra/config conf; \
118         fi;
119         $(RM) -r include/bits
120         $(INSTALL) -d include/bits
121         @./extra/config/conf -o extra/Configs/Config.in
122
123 headers: include/bits/uClibc_config.h
124 ifeq ($(strip $(UCLIBC_HAS_MMU)),y)
125         @set -x; ./extra/scripts/fix_includes.sh -k $(KERNEL_SOURCE) -t $(TARGET_ARCH)
126 else
127         @set -x; ./extra/scripts/fix_includes.sh -k $(KERNEL_SOURCE) -t $(TARGET_ARCH) -n
128 endif
129         @cd include/bits; \
130         set -e; \
131         for i in `ls ../../libc/sysdeps/linux/common/bits/*.h` ; do \
132                 $(LN) -fs $$i .; \
133         done; \
134         if [ -d ../../libc/sysdeps/linux/$(TARGET_ARCH)/bits ] ; then \
135                 for i in `ls ../../libc/sysdeps/linux/$(TARGET_ARCH)/bits/*.h` ; do \
136                         $(LN) -fs $$i .; \
137                 done; \
138         fi
139         @cd include/sys; \
140         set -e; \
141         for i in `ls ../../libc/sysdeps/linux/common/sys/*.h` ; do \
142                 $(LN) -fs $$i .; \
143         done; \
144         if [ -d ../../libc/sysdeps/linux/$(TARGET_ARCH)/sys ] ; then \
145                 for i in `ls ../../libc/sysdeps/linux/$(TARGET_ARCH)/sys/*.h` ; do \
146                         $(LN) -fs $$i .; \
147                 done; \
148         fi
149         @cd $(TOPDIR); \
150         set -x -e; \
151         TOPDIR=. CC="$(CC)" /bin/sh extra/scripts/gen_bits_syscall_h.sh > include/bits/sysnum.h.new; \
152         if cmp include/bits/sysnum.h include/bits/sysnum.h.new >/dev/null 2>&1; then \
153                 $(RM) include/bits/sysnum.h.new; \
154         else \
155                 mv -f include/bits/sysnum.h.new include/bits/sysnum.h; \
156         fi
157         $(MAKE) -C libc/sysdeps/linux/common headers
158         $(MAKE) -C libc/sysdeps/linux/$(TARGET_ARCH) headers
159
160 # Command used to download source code
161 WGET:=wget --passive-ftp
162
163 pregen: headers
164 ifeq ($(strip $(UCLIBC_DOWNLOAD_PREGENERATED_LOCALE_DATA)),y)
165         (cd extra/locale; \
166         $(WGET) http://www.uclibc.org/downloads/uClibc-locale-030818.tgz);
167 endif
168 ifeq ($(strip $(UCLIBC_PREGENERATED_LOCALE_DATA)),y)
169         (cd extra/locale; zcat uClibc-locale-030818.tgz | tar -xvf -)
170         make -C extra/locale pregen
171 endif
172
173
174 subdirs: $(patsubst %, _dir_%, $(DIRS))
175
176 $(patsubst %, _dir_%, $(DIRS)) : dummy
177         $(MAKE) -C $(patsubst _dir_%, %, $@)
178
179 tags:
180         ctags -R
181
182 install: install_dev install_runtime install_utils finished2
183
184
185 # Installs header files and development library links.
186 install_dev:
187         $(INSTALL) -d $(PREFIX)$(DEVEL_PREFIX)lib
188         $(INSTALL) -d $(PREFIX)$(DEVEL_PREFIX)include
189         -$(INSTALL) -m 644 lib/*.[ao] $(PREFIX)$(DEVEL_PREFIX)lib/
190         tar -chf - include | tar -xf - -C $(PREFIX)$(DEVEL_PREFIX);
191 ifneq ($(strip $(UCLIBC_HAS_FLOATS)),y)
192         # Remove floating point related headers since float support is disabled.
193         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/complex.h
194         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/fpu_control.h
195         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/ieee754.h
196         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/math.h
197         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/tgmath.h
198 endif
199 ifneq ($(strip $(UCLIBC_HAS_WCHAR)),y)
200         # Remove wide char headers since wide char support is disabled.
201         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/wctype.h
202         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/wchar.h
203 endif
204 ifneq ($(strip $(UCLIBC_HAS_LOCALE)),y)
205         # Remove iconv header since locale support is disabled.
206         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/iconv.h
207 endif
208 ifneq ($(strip $(UCLIBC_HAS_GLIBC_CUSTOM_PRINTF)),y)
209         # Remove printf header since custom print specifier support is disabled.
210         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/printf.h
211 endif
212 ifneq ($(strip $(UCLIBC_HAS_XLOCALE)),y)
213         # Remove xlocale header since extended locale support is disabled.
214         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/xlocale.h
215 endif
216 ifneq ($(strip $(UCLIBC_HAS_GETTEXT_AWARENESS)),y)
217         # Remove libintl header since gettext support is disabled.
218         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/libintl.h
219 endif
220 ifneq ($(strip $(UCLIBC_HAS_REGEX)),y)
221         # Remove regex headers since regex support is disabled.
222         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/regex.h
223         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/regexp.h
224 endif
225 ifneq ($(strip $(UCLIBC_HAS_WORDEXP)),y)
226         # Remove wordexp header since wordexp support is disabled.
227         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/wordexp.h
228 endif
229 ifneq ($(strip $(UCLIBC_HAS_FTW)),y)
230         # Remove ftw header since ftw support is disabled.
231         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/ftw.h
232 endif
233 ifneq ($(strip $(UCLIBC_HAS_GLOB)),y)
234         # Remove glob header since glob support is disabled.
235         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/glob.h
236 endif
237 ifneq ($(strip $(UCLIBC_HAS_GNU_GETOPT)),y)
238         # Remove getopt header since gnu getopt support is disabled.
239         $(RM) $(PREFIX)$(DEVEL_PREFIX)include/getopt.h
240 endif
241         -@for i in `find  $(PREFIX)$(DEVEL_PREFIX) -type d` ; do \
242             chmod 755 $$i; chmod 644 $$i/*.h > /dev/null 2>&1; \
243         done;
244         -find $(PREFIX)$(DEVEL_PREFIX) -name CVS | xargs $(RM) -r;
245         -chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$$/\1.\2/'` $(PREFIX)$(DEVEL_PREFIX)
246 ifeq ($(strip $(HAVE_SHARED)),y)
247         -$(INSTALL) -m 644 lib/*.so $(PREFIX)$(DEVEL_PREFIX)lib/
248         -find lib/ -type l -name '*.so' -exec cp -fa {} $(PREFIX)$(DEVEL_PREFIX)lib ';'
249         # If we build shared libraries then the static libs are PIC...
250         # Make _pic.a symlinks to make mklibs.py and similar tools happy.
251         for i in `find lib/  -type f -name '*.a' | sed -e 's/lib\///'` ; do \
252                 $(LN) -sf $$i $(PREFIX)$(DEVEL_PREFIX)lib/`echo $$i | sed -e 's/\.a$$/_pic.a/'`; \
253         done
254 endif
255
256
257 # Installs run-time libraries and helper apps onto the host system
258 # allowing cross development.  If you want to deploy to a target 
259 # system, use the "install_target" target instead... 
260 install_runtime:
261 ifeq ($(strip $(HAVE_SHARED)),y)
262         $(INSTALL) -d $(PREFIX)$(RUNTIME_PREFIX)lib
263         $(INSTALL) -m 644 lib/lib*-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
264                 $(PREFIX)$(RUNTIME_PREFIX)lib
265         cp -fa lib/*.so.* $(PREFIX)$(RUNTIME_PREFIX)lib
266         @if [ -x lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so ] ; then \
267             set -x -e; \
268             $(INSTALL) -m 755 lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
269                         $(PREFIX)$(RUNTIME_PREFIX)lib; \
270         fi;
271 endif
272
273 ifeq ($(strip $(HAVE_SHARED)),y)
274 utils: $(TOPDIR)utils/ldd
275         $(MAKE) -C utils
276 else
277 utils: dummy
278 endif
279
280 install_utils: utils
281 ifeq ($(strip $(HAVE_SHARED)),y)
282         $(INSTALL) -d $(PREFIX)$(RUNTIME_PREFIX)sbin
283         $(INSTALL) -d $(PREFIX)$(RUNTIME_PREFIX)usr/bin
284         $(INSTALL) -m 755 ldso/util/ldd \
285                 $(PREFIX)$(RUNTIME_PREFIX)usr/bin/ldd
286         $(INSTALL) -m 755 ldso/util/ldconfig \
287                 $(PREFIX)$(RUNTIME_PREFIX)sbin/ldconfig;
288         # For now, don't bother with readelf since surely the host
289         # system has binutils, or we couldn't have gotten this far...
290         #$(INSTALL) -m 755 ldso/util/readelf \
291         #       $(PREFIX)$(RUNTIME_PREFIX)usr/bin/readelf
292 endif
293 ifeq ($(strip $(UCLIBC_HAS_LOCALE)),y)
294         @$(MAKE) -C libc/misc/wchar iconv.target
295         $(INSTALL) -d $(PREFIX)$(RUNTIME_PREFIX)/usr/bin;
296         $(INSTALL) -m 755 libc/misc/wchar/iconv.target $(PREFIX)$(RUNTIME_PREFIX)/usr/bin/iconv
297 endif
298
299 finished2:
300         @echo
301         @echo Finished installing...
302         @echo
303
304 else # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
305
306 all: menuconfig
307
308 # configuration
309 # ---------------------------------------------------------------------------
310 extra/config/conf:
311         make -C extra/config conf
312
313 extra/config/mconf:
314         make -C extra/config ncurses mconf
315
316 menuconfig: extra/config/mconf
317         $(RM) -r include/bits
318         $(INSTALL) -d include/bits
319         @./extra/config/mconf extra/Configs/Config.in
320
321 config: extra/config/conf
322         $(RM) -r include/bits
323         $(INSTALL) -d include/bits
324         @./extra/config/conf extra/Configs/Config.in
325
326 oldconfig: extra/config/conf
327         $(RM) -r include/bits
328         $(INSTALL) -d include/bits
329         @./extra/config/conf -o extra/Configs/Config.in
330
331 randconfig: extra/config/conf
332         $(RM) -r include/bits
333         $(INSTALL) -d include/bits
334         @./extra/config/conf -r extra/Configs/Config.in
335
336 allyesconfig: extra/config/conf
337         $(RM) -r include/bits
338         $(INSTALL) -d include/bits
339         @./extra/config/conf -y extra/Configs/Config.in
340
341 allnoconfig: extra/config/conf
342         $(RM) -r include/bits
343         $(INSTALL) -d include/bits
344         @./extra/config/conf -n extra/Configs/Config.in
345
346 defconfig: extra/config/conf
347         $(RM) -r include/bits
348         $(INSTALL) -d include/bits
349         @./extra/config/conf -d extra/Configs/Config.in
350
351
352 clean:
353         - find . \( -name \*.o -o -name \*.a -o -name \*.so -o -name core -o -name .\#\* \) -exec $(RM) {} \;
354         @$(RM) -r tmp lib include/bits libc/tmp _install
355         $(MAKE) -C test clean
356         $(MAKE) -C ldso clean
357         $(MAKE) -C libc/misc/internals clean
358         $(MAKE) -C libc/misc/wchar clean
359         $(MAKE) -C libc/unistd clean
360         $(MAKE) -C libc/sysdeps/linux/common clean
361         $(MAKE) -C extra/locale clean
362         @set -e; \
363         for i in `(cd $(TOPDIR)/libc/sysdeps/linux/common/sys; ls *.h)` ; do \
364                 $(RM) include/sys/$$i; \
365         done; \
366         if [ -d libc/sysdeps/linux/$(TARGET_ARCH)/sys ] ; then \
367                 for i in `(cd libc/sysdeps/linux/$(TARGET_ARCH)/sys; ls *.h)` ; do \
368                         $(RM) include/sys/$$i; \
369                 done; \
370         fi;
371         @$(RM) include/linux include/scsi include/asm
372         @if [ -d libc/sysdeps/linux/$(TARGET_ARCH) ]; then              \
373             $(MAKE) -C libc/sysdeps/linux/$(TARGET_ARCH) clean;         \
374         fi;
375
376 distclean: clean
377         $(RM) .config .config.old .config.cmd
378         $(MAKE) -C extra clean
379
380 release: distclean
381         cd ..;                                  \
382         $(RM) -r uClibc-$(VERSION);             \
383         cp -fa uClibc uClibc-$(VERSION);        \
384         find uClibc-$(VERSION)/ -type f         \
385             -name .\#* -exec $(RM) -r {} \; ;   \
386         find uClibc-$(VERSION)/ -type d         \
387             -name CVS  -exec $(RM) -r {} \; ;   \
388                                                 \
389         tar -cvzf uClibc-$(VERSION).tar.gz uClibc-$(VERSION)/;
390
391 endif # ifeq ($(strip $(HAVE_DOT_CONFIG)),y)
392
393 .PHONY: dummy subdirs release distclean clean config oldconfig menuconfig
394
395