OSDN Git Service

Implemented 'romfs' target so that uClibc works with building uClinux.
[uclinux-h8/uclibc-ng.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 #There are a number of configurable options in "Config"
28 #
29 #--------------------------------------------------------
30
31 TOPDIR=./
32 include Rules.mak
33
34 DIRS = extra ldso libc libcrypt libresolv libutil libm libpthread
35
36 all: headers uClibc_config subdirs shared utils finished
37
38 Config:
39         @echo
40         @echo "You didn't read the README, did you... =)"
41         @echo "Choose a configuration file in extras/Config/ and then run"
42         @echo "  ln -s ./extra/Configs/Config.<arch> ./Config"
43         @echo
44         @exit 1
45
46 shared:
47 ifeq ($(strip $(HAVE_SHARED)),true)
48         @$(MAKE) -C libc shared
49         @$(MAKE) -C ldso shared
50         @$(MAKE) -C libcrypt shared
51         @$(MAKE) -C libresolv shared
52         @$(MAKE) -C libutil shared
53         @$(MAKE) -C libm shared
54         @$(MAKE) -C libpthread shared
55 else
56         @echo
57         @echo Not building shared libraries...
58         @echo
59 endif
60
61 finished: shared
62         @echo
63         @echo Finally finished compiling...
64         @echo
65
66 #
67 # Target for uClinux distro
68 #
69 romfs:
70 ifeq ($(strip $(HAVE_SHARED)),true)
71         install -d $(ROMFSDIR)/lib
72         install -m 644 lib/lib*-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
73                 $(ROMFSDIR)/lib
74         cp -a lib/*.so.* $(ROMFSDIR)/lib
75         @if [ -x lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so ] ; then \
76             set -x -e; \
77             install -m 755 lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
78                         $(ROMFSDIR)/lib; \
79         fi;
80 endif
81
82 headers: dummy
83         rm -f include/asm;
84         @if [ $(TARGET_ARCH) = "powerpc" ];then \
85             ln -fs $(KERNEL_SOURCE)/include/asm-ppc include/asm; \
86         elif [ $(TARGET_ARCH) = "mips" ];then \
87             ln -fs $(KERNEL_SOURCE)/include/asm-mips include/asm; \
88         elif [ $(TARGET_ARCH) = "mipsel" ];then \
89             ln -fs $(KERNEL_SOURCE)/include/asm-mips include/asm; \
90             cd $(shell pwd)/libc/sysdeps/linux; \
91             ln -fs mips mipsel; \
92             cd $(shell pwd)/ldso/ldso; \
93             ln -fs mips mipsel; \
94             cd $(shell pwd)/libpthread/linuxthreads/sysdeps; \
95             ln -fs mips mipsel; \
96         elif [ $(TARGET_ARCH) = "cris" ];then \
97                 ln -fs $(KERNEL_SOURCE)/include/asm-cris include/asm; \
98         else \
99             if [ $(HAS_MMU) != "true" ]; then \
100                 if [ -d $(KERNEL_SOURCE)/include/asm-$(TARGET_ARCH)nommu ] ; then \
101                     ln -fs $(KERNEL_SOURCE)/include/asm-$(TARGET_ARCH)nommu include/asm;\
102                 else \
103                     ln -fs $(KERNEL_SOURCE)/include/asm-$(TARGET_ARCH) include/asm; \
104                 fi; \
105             else \
106                 ln -fs $(KERNEL_SOURCE)/include/asm-$(TARGET_ARCH) include/asm; \
107             fi; \
108         fi;
109         @if [ ! -f include/asm/unistd.h ] ; then \
110             set -e; \
111             echo " "; \
112             echo "The path '$(KERNEL_SOURCE)/include/asm' doesn't exist."; \
113             echo "I bet you didn't set KERNEL_SOURCE, TARGET_ARCH or HAS_MMU in \`Config'"; \
114             echo "correctly.  Please edit \`Config' and fix these settings."; \
115             echo " "; \
116             false; \
117         fi;
118         rm -f include/linux include/scsi
119         ln -fs $(KERNEL_SOURCE)/include/linux include/linux
120         ln -fs $(KERNEL_SOURCE)/include/scsi include/scsi
121         rm -rf include/bits
122         mkdir -p include/bits
123         @cd include/bits; \
124         set -e; \
125         for i in `ls ../../libc/sysdeps/linux/common/bits/*.h` ; do \
126                 ln -fs $$i .; \
127         done; \
128         if [ -d ../../libc/sysdeps/linux/$(TARGET_ARCH)/bits ] ; then \
129                 for i in `ls ../../libc/sysdeps/linux/$(TARGET_ARCH)/bits/*.h` ; do \
130                         ln -fs $$i .; \
131                 done; \
132         fi
133         @cd include/sys; \
134         set -e; \
135         for i in `ls ../../libc/sysdeps/linux/common/sys/*.h` ; do \
136                 ln -fs $$i .; \
137         done; \
138         if [ -d ../../libc/sysdeps/linux/$(TARGET_ARCH)/sys ] ; then \
139                 for i in `ls ../../libc/sysdeps/linux/$(TARGET_ARCH)/sys/*.h` ; do \
140                         ln -fs $$i .; \
141                 done; \
142         fi
143         @cd $(TOPDIR); \
144         set -x -e; \
145         rm -f include/bits/sysnum.h; \
146         TOPDIR=$(TOPDIR) CC=$(CC) /bin/sh $(TOPDIR)/extra/scripts/gen_bits_syscall_h.sh > include/bits/sysnum.h
147         $(MAKE) -C libc/sysdeps/linux/$(TARGET_ARCH) headers
148
149 uClibc_config: Makefile Config
150         @echo "/* WARNING!!! AUTO-GENERATED FILE!!! DO NOT EDIT!!! */" > include/bits/uClibc_config.h
151         @echo "#if !defined __FEATURES_H && !defined __need_uClibc_config_h" >> include/bits/uClibc_config.h
152         @echo "#error Never include <bits/uClibc_config.h> directly; use <features.h> instead." >> include/bits/uClibc_config.h
153         @echo "#endif" >> include/bits/uClibc_config.h
154         @echo "#define __UCLIBC_MAJOR__ $(MAJOR_VERSION)" >> include/bits/uClibc_config.h 
155         @echo "#define __UCLIBC_MINOR__ $(MINOR_VERSION)" >> include/bits/uClibc_config.h 
156         @echo "#define __UCLIBC_SUBLEVEL__ $(SUBLEVEL)" >> include/bits/uClibc_config.h 
157         @echo "#define linux 1" >> include/bits/uClibc_config.h 
158         @echo "#define __linux__ 1" >> include/bits/uClibc_config.h 
159         @if [ "$(INCLUDE_IPV6)" = "true" ] ; then \
160             echo "#define __UCLIBC_HAS_IPV6__ 1" >> include/bits/uClibc_config.h ; \
161         else \
162             echo "#undef __UCLIBC_HAS_IPV6__" >> include/bits/uClibc_config.h ; \
163         fi
164         @if [ "$(HAS_MMU)" = "true" ] ; then \
165             echo "#define __UCLIBC_HAS_MMU__ 1" >> include/bits/uClibc_config.h ; \
166         else \
167             echo "#undef __UCLIBC_HAS_MMU__" >> include/bits/uClibc_config.h ; \
168         fi
169         @if [ "$(HAS_FLOATING_POINT)" = "true" ] ; then \
170             echo "#define __UCLIBC_HAS_FLOATS__ 1" >> include/bits/uClibc_config.h ; \
171         else \
172             echo "#undef __UCLIBC_HAS_FLOATS__" >> include/bits/uClibc_config.h ; \
173         fi
174         @if [ "$(HAS_LOCALE)" = "true" ] ; then \
175             echo "#define __UCLIBC_HAS_LOCALE__ 1" >> include/bits/uClibc_config.h ; \
176         else \
177             echo "#undef __UCLIBC_HAS_LOCALE__" >> include/bits/uClibc_config.h ; \
178         fi
179         @if [ "$(HAS_WCHAR)" = "true" ] ; then \
180             echo "#define __UCLIBC_HAS_WCHAR__ 1" >> include/bits/uClibc_config.h ; \
181         else \
182             echo "#undef __UCLIBC_HAS_WCHAR__" >> include/bits/uClibc_config.h ; \
183         fi
184         @if [ "$(HAVE_ELF)" = "false" ] ; then \
185             echo "#undef HAVE_ELF" >> include/bits/uClibc_config.h ; \
186         else \
187             echo "#define HAVE_ELF 1" >> include/bits/uClibc_config.h ; \
188         fi
189         @if [ "$(HAVE_SHARED)" = "false" ] ; then \
190             echo "#undef HAVE_SHARED" >> include/bits/uClibc_config.h ; \
191         else \
192             echo "#define HAVE_SHARED 1" >> include/bits/uClibc_config.h ; \
193         fi
194         @if [ "$(TARGET_ARCH)" = "sh" ] ; then \
195             echo "#define NO_UNDERSCORES 1" >> include/bits/uClibc_config.h ; \
196         else \
197             echo "#undef NO_UNDERSCORES" >> include/bits/uClibc_config.h ; \
198         fi
199         @if [ "$(INCLUDE_RPC)" = "true" ] ; then \
200             echo "#define __UCLIBC_HAS_RPC__ 1" >> include/bits/uClibc_config.h ; \
201         else \
202             echo "#undef __UCLIBC_HAS_RPC__" >> include/bits/uClibc_config.h ; \
203         fi
204         @if [ "$(DOLFS)" = "true" ] ; then \
205             echo "#define __UCLIBC_HAVE_LFS__ 1" >> include/bits/uClibc_config.h ; \
206         else \
207             echo "#undef __UCLIBC_HAVE_LFS__" >> include/bits/uClibc_config.h ; \
208         fi
209         @if [ "$(INCLUDE_THREADS)" = "true" ] ; then \
210             echo "#define __UCLIBC_HAS_THREADS__ 1" >> include/bits/uClibc_config.h ; \
211         else \
212             echo "#undef __UCLIBC_HAS_THREADS__" >> include/bits/uClibc_config.h ; \
213         fi
214         @if [ "$(INCLUDE_REGEX)" = "true" ] ; then \
215             echo "#define __UCLIBC_HAS_REGEX__ 1" >> include/bits/uClibc_config.h ; \
216         else \
217             echo "#undef __UCLIBC_HAS_REGEX__" >> include/bits/uClibc_config.h ; \
218         fi
219         @if [ "$(UNIX98PTY_ONLY)" = "true" ] ; then \
220             echo "#define UNIX98PTY_ONLY 1" >> include/bits/uClibc_config.h ; \
221         else \
222             echo "#undef UNIX98PTY_ONLY" >> include/bits/uClibc_config.h ; \
223         fi
224         @if [ "$(ASSUME_DEVPTS)" = "true" ] ; then \
225             echo "#define ASSUME_DEVPTS 1" >> include/bits/uClibc_config.h ; \
226         else \
227             echo "#undef ASSUME_DEVPTS" >> include/bits/uClibc_config.h ; \
228         fi
229         @echo "#define C_SYMBOL_PREFIX "\""$(C_SYMBOL_PREFIX)"\" >> include/bits/uClibc_config.h
230         @if [ "$(HAVE_DOT_HIDDEN)" = "true" ] ; then \
231             echo "#define HAVE_DOT_HIDDEN 1" >> include/bits/uClibc_config.h ; \
232         else \
233             echo "#undef HAVE_DOT_HIDDEN" >> include/bits/uClibc_config.h ; \
234         fi
235
236 subdirs: $(patsubst %, _dir_%, $(DIRS))
237
238 $(patsubst %, _dir_%, $(DIRS)) : dummy
239         $(MAKE) -C $(patsubst _dir_%, %, $@)
240
241 tags:
242         ctags -R
243
244 install: install_dev install_runtime install_toolchain install_utils finished2
245
246
247 # Installs header files and development library links.
248 install_dev:
249         install -d $(PREFIX)$(DEVEL_PREFIX)/lib
250         install -d $(PREFIX)$(DEVEL_PREFIX)/usr/lib
251         install -d $(PREFIX)$(DEVEL_PREFIX)/include
252         -install -m 644 lib/*.[ao] $(PREFIX)$(DEVEL_PREFIX)/lib/
253         tar -chf - include | tar -xf - -C $(PREFIX)$(DEVEL_PREFIX);
254         -@for i in `find  $(PREFIX)$(DEVEL_PREFIX) -type d` ; do \
255             chmod -f 755 $$i; chmod -f 644 $$i/*.h; \
256         done;
257         -find $(PREFIX)$(DEVEL_PREFIX) -name CVS | xargs rm -rf;
258         -chown -R `id | sed 's/^uid=\([0-9]*\).*gid=\([0-9]*\).*$$/\1.\2/'` $(PREFIX)$(DEVEL_PREFIX)
259 ifeq ($(strip $(HAVE_SHARED)),true)
260         -find lib/ -type l -name '*.so' -exec cp -a {} $(PREFIX)$(DEVEL_PREFIX)/lib ';'
261         # If we build shared libraries then the static libs are PIC...
262         # Make _pic.a symlinks to make mklibs.py and similar tools happy.
263         for i in `find lib/  -type f -name '*.a' | sed -e 's/lib\///'` ; do \
264                 ln -sf $$i $(PREFIX)$(DEVEL_PREFIX)/lib/`echo $$i | sed -e 's/\.a$$/_pic.a/'`; \
265         done
266 endif
267
268
269 # Installs run-time libraries and helper apps onto the host system
270 # allowing cross development.  If you want to deploy to a target 
271 # system, use the "install_target" target instead... 
272 install_runtime:
273 ifeq ($(strip $(HAVE_SHARED)),true)
274         install -d $(PREFIX)$(DEVEL_PREFIX)/lib
275         install -d $(PREFIX)$(DEVEL_PREFIX)/bin
276         install -m 644 lib/lib*-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
277                 $(PREFIX)$(DEVEL_PREFIX)/lib
278         cp -a lib/*.so.* $(PREFIX)$(DEVEL_PREFIX)/lib
279         @if [ -x lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so ] ; then \
280             set -x -e; \
281             install -m 755 lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
282                         $(PREFIX)$(DEVEL_PREFIX)/lib; \
283             mkdir -p $(PREFIX)$(SHARED_LIB_LOADER_PATH); \
284             ln -s $(DEVEL_PREFIX)/lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
285                         $(PREFIX)$(SHARED_LIB_LOADER_PATH)/$(UCLIBC_LDSO) || true; \
286         fi;
287 endif
288
289 install_toolchain:
290         install -d $(PREFIX)$(DEVEL_PREFIX)/lib
291         install -d $(PREFIX)$(DEVEL_PREFIX)/bin
292         install -d $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin
293         install -d $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin
294         $(MAKE) -C extra/gcc-uClibc install
295
296 ifeq ($(strip $(HAVE_SHARED)),true)
297 utils: $(TOPDIR)ldso/util/ldd
298         $(MAKE) -C ldso utils
299 else
300 utils: dummy
301 endif
302
303 install_utils: utils
304 ifeq ($(strip $(HAVE_SHARED)),true)
305         install -d $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin;
306         install -m 755 ldso/util/ldd \
307                 $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-ldd
308         ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-ldd \
309                 $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/ldd
310         # For now, don't bother with readelf since surely the host
311         # system has binutils, or we couldn't have gotten this far...
312         #install -m 755 ldso/util/readelf \
313         #       $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-readelf
314         #ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-readelf \
315         #       $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/readelf
316         @if [ -x ldso/util/ldconfig ] ; then \
317             set -x -e; \
318             install -d $(PREFIX)$(DEVEL_PREFIX)/etc; \
319             install -m 755 ldso/util/ldconfig \
320                     $(PREFIX)$(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-ldconfig; \
321             ln -fs $(SYSTEM_DEVEL_PREFIX)/bin/$(TARGET_ARCH)-uclibc-ldconfig \
322                     $(PREFIX)$(DEVEL_TOOL_PREFIX)/bin/ldconfig; \
323         fi;
324 endif
325
326 # Installs run-time libraries and helper apps in preparation for
327 # deploying onto a target system, but installed below wherever
328 # $PREFIX is set to, allowing you to package up the result for
329 # deployment onto your target system.
330 install_target:
331 ifeq ($(strip $(HAVE_SHARED)),true)
332         install -d $(PREFIX)$(TARGET_PREFIX)/lib
333         install -d $(PREFIX)$(TARGET_PREFIX)/usr/bin
334         install -m 644 lib/lib*-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
335                 $(PREFIX)$(TARGET_PREFIX)/lib
336         cp -a lib/*.so.* $(PREFIX)$(TARGET_PREFIX)/lib
337         @if [ -x lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so ] ; then \
338             set -x -e; \
339             install -m 755 lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
340                         $(PREFIX)$(TARGET_PREFIX)/lib; \
341             mkdir -p $(PREFIX)$(SHARED_LIB_LOADER_PATH); \
342             ln -s $(TARGET_PREFIX)/lib/ld-uClibc-$(MAJOR_VERSION).$(MINOR_VERSION).$(SUBLEVEL).so \
343                         $(PREFIX)$(SHARED_LIB_LOADER_PATH)/$(UCLIBC_LDSO) || true; \
344         fi;
345 endif
346
347 install_target_utils:
348 ifeq ($(strip $(HAVE_SHARED)),true)
349         @$(MAKE) -C ldso/util ldd.target readelf.target #ldconfig.target
350         install -d $(PREFIX)$(TARGET_PREFIX)/usr/bin;
351         install -m 755 ldso/util/ldd.target $(PREFIX)$(TARGET_PREFIX)/usr/bin/ldd
352         install -m 755 ldso/util/readelf.target $(PREFIX)$(TARGET_PREFIX)/usr/bin/readelf
353         @if [ -x ldso/util/ldconfig.target ] ; then \
354             set -x -e; \
355             install -d $(PREFIX)$(TARGET_PREFIX)/etc; \
356             install -d $(PREFIX)$(TARGET_PREFIX)/sbin; \
357             install -m 755 ldso/util/ldconfig.target $(PREFIX)$(TARGET_PREFIX)/sbin/ldconfig; \
358         fi;
359 endif
360
361 finished2:
362         @echo
363         @echo Finished installing...
364         @echo
365
366
367 distclean clean:
368         - find . \( -name \*.o -o -name \*.a -o -name \*.so -o -name core -o -name .\#\* \) -exec rm -f {} \;
369         @rm -rf tmp lib include/bits libc/tmp _install
370         $(MAKE) -C test clean
371         $(MAKE) -C ldso clean
372         $(MAKE) -C libc/misc/internals clean
373         $(MAKE) -C libc/unistd clean
374         $(MAKE) -C libc/sysdeps/linux/common clean
375         $(MAKE) -C extra/gcc-uClibc clean
376         @set -e; \
377         for i in `(cd $(TOPDIR)/libc/sysdeps/linux/common/sys; ls *.h)` ; do \
378                 rm -f include/sys/$$i; \
379         done; \
380         if [ -d libc/sysdeps/linux/$(TARGET_ARCH)/sys ] ; then \
381                 for i in `(cd libc/sysdeps/linux/$(TARGET_ARCH)/sys; ls *.h)` ; do \
382                         rm -f include/sys/$$i; \
383                 done; \
384         fi;
385         @rm -f include/linux include/scsi include/asm
386         @if [ -d libc/sysdeps/linux/$(TARGET_ARCH) ]; then              \
387             $(MAKE) -C libc/sysdeps/linux/$(TARGET_ARCH) clean;         \
388         fi;
389         @if [ $(TARGET_ARCH) = "mipsel" ]; then \
390             $(MAKE) -C libc/sysdeps/linux/mips clean; \
391             rm -f ldso/ldso/mipsel; \
392             rm -f libc/sysdeps/linux/mipsel; \
393             rm -f libpthread/linuxthreads/sysdeps/mipsel; \
394         fi;
395
396 dist release: distclean
397         cd ..;                                  \
398         rm -rf uClibc-$(VERSION);               \
399         cp -a uClibc uClibc-$(VERSION);         \
400         find uClibc-$(VERSION)/ -type d         \
401             -name .\#* -exec rm -rf {} \; ;     \
402                                                 \
403         tar -cvzf uClibc-$(VERSION).tar.gz --exclude CVS uClibc-$(VERSION)/;
404
405 .PHONY: dummy subdirs release distclean clean
406