OSDN Git Service

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