OSDN Git Service

Fix a bug noted by David Beamonte <dbeamonte@intelnet.es>, so that
[uclinux-h8/uClibc.git] / Makefile
1 # Makefile for uClibc
2 #
3 # Copyright (C) 2000 by Lineo, inc.
4 #
5 # This program is free software; you can redistribute it and/or modify it under
6 # the terms of the GNU Library General Public License as published by the Free
7 # Software Foundation; either version 2 of the License, or (at your option) any
8 # later version.
9 #
10 # This program is distributed in the hope that it will be useful, but WITHOUT
11 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 # FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more
13 # details.
14 #
15 # You should have received a copy of the GNU Library General Public License
16 # along with this program; if not, write to the Free Software Foundation, Inc.,
17 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18 #
19 # Derived in part from the Linux-8086 C library, the GNU C Library, and several
20 # other sundry sources.  Files within this library are copyright by their
21 # respective copyright holders.
22
23 #--------------------------------------------------------
24 #
25 #There are a number of configurable options in "Config"
26 #
27 #--------------------------------------------------------
28
29 include Rules.mak
30
31
32 DIRS = extra misc pwd_grp stdio string termios inet signal stdlib sysdeps unistd
33
34 ifeq ($(strip $(HAS_MMU)),true)
35         DO_SHARED=shared
36 endif
37
38 all: $(STATIC_NAME) $(DO_SHARED) done
39
40 $(STATIC_NAME): halfclean headers uClibc_config.h subdirs
41         $(CROSS)ranlib $(STATIC_NAME)
42
43 # Surely there is a better way to do this then dumping all 
44 # the objects into a tmp dir.  Please -- someone enlighten me.
45 shared: $(STATIC_NAME)
46         @rm -rf tmp
47         @mkdir tmp
48         @(cd tmp; CC=$(CC) /bin/sh ../extra/scripts/get-needed-libgcc-objects.sh)
49         if [ -s ./tmp/libgcc-need.a ] ; then \
50                 $(CC) -g $(LDFLAGS) -shared -o $(SHARED_NAME) \
51                     -Wl,-soname,$(SHARED_NAME) -Wl,--whole-archive \
52                     ./libc.a ./tmp/libgcc-need.a ; \
53         else \
54                 $(CC) -g $(LDFLAGS) -shared -o $(SHARED_NAME) \
55                     -Wl,-soname,$(SHARED_NAME) -Wl,--whole-archive ./libc.a ; \
56         fi
57         @rm -rf tmp
58
59 done: $(STATIC_NAME) $(DO_SHARED)
60         @echo
61         @echo Finally finished compiling...
62         @echo
63
64 halfclean:
65         @rm -f $(STATIC_NAME) $(SHARED_NAME) crt0.o uClibc_config.h
66
67 headers: dummy
68         @rm -f include/asm include/linux include/bits
69         @ln -s $(KERNEL_SOURCE)/include/asm include/asm
70         @if [ ! -f include/asm/unistd.h ] ; then \
71             echo " "; \
72             echo "The path '$(KERNEL_SOURCE)/include/asm' doesn't exist."; \
73             echo "I bet you didn't set KERNEL_SOURCE, TARGET_ARCH or HAS_MMU in \`Config'"; \
74             echo "correctly.  Please edit \`Config' and fix these settings."; \
75             echo " "; \
76             /bin/false; \
77         fi;
78         @if [ $(HAS_MMU) != "true" ]  && [ $(TARGET_ARCH) = "i386" ] ; then \
79             echo "WARNING: I bet your x86 system really has an MMU, right?"; \
80             echo "         malloc and friends won't work unless you fix \`Config'"; \
81             echo " "; \
82             sleep 10; \
83         fi;
84         @ln -s $(KERNEL_SOURCE)/include/linux include/linux
85         @ln -s ../sysdeps/linux/$(TARGET_ARCH)/bits include/bits
86         @ln -sf ../../../../uClibc_config.h sysdeps/linux/$(TARGET_ARCH)/bits/uClibc_config.h
87
88
89 tags:
90         ctags -R
91
92 clean: subdirs_clean
93         @rm -rf tmp
94         rm -f $(STATIC_NAME) crt0.o $(SHARED_NAME) uClibc_config.h
95         rm -f include/asm include/linux include/bits
96
97 subdirs: $(patsubst %, _dir_%, $(DIRS))
98 subdirs_clean: $(patsubst %, _dirclean_%, $(DIRS) test)
99
100 $(patsubst %, _dir_%, $(DIRS)) : dummy
101         $(MAKE) -C $(patsubst _dir_%, %, $@)
102
103 $(patsubst %, _dirclean_%, $(DIRS) test) : dummy
104         $(MAKE) -C $(patsubst _dirclean_%, %, $@) clean
105
106 install_new: install_runtime install_dev
107
108 # Installs shared library
109 install_runtime:
110 ifneq ($(DO_SHARED),)
111         install -d $(INSTALL_DIR)/lib
112         install -m 644 $(SHARED_NAME) $(INSTALL_DIR)/lib/
113         (cd $(INSTALL_DIR)/lib;ln -sf $(SHARED_NAME) libuClibc.so)
114 # ldconfig is really not necessary, and impossible to cross
115 ifeq ($(INSTALL_DIR),)
116         /sbin/ldconfig -n $(INSTALL_DIR)/lib
117 endif
118 else
119         echo shared library not installed
120 endif
121
122 # Installs development library and headers
123 # This is done with the assumption that it can blow away anything
124 # in $(INSTALL_DIR)/include.  Probably true only if you're using
125 # a packaging system.
126 install_dev:
127         install -d $(INSTALL_DIR)/include
128         install -d $(INSTALL_DIR)/include/bits
129         rm -f $(INSTALL_DIR)/include/asm
130         rm -f $(INSTALL_DIR)/include/linux
131         ln -s $(KERNEL_SOURCE)/include/asm $(INSTALL_DIR)/include/asm
132         ln -s $(KERNEL_SOURCE)/include/linux $(INSTALL_DIR)/include/linux
133         find include/ -type f -depth -exec install -m 644 {} $(INSTALL_DIR)/include/ ';'
134         find include/bits/ -type f -depth -exec install -m 644 {} $(INSTALL_DIR)/include/bits/ ';'
135         install -d $(INSTALL_DIR)/lib
136         rm -f $(INSTALL_DIR)/lib/$(STATIC_NAME)
137         install -m 644 $(STATIC_NAME) $(INSTALL_DIR)/lib/
138         @if [ -f crt0.o ] ; then install -m 644 crt0.o $(INSTALL_DIR)/lib/; fi
139
140 install:
141         echo Consider using 'make install_new'
142         @if [ `id -u` -ne 0 ]; then \
143             echo "Aborting install -- You must be root."; \
144             /bin/false; \
145         fi;
146         @if [ -n "$(DO_SHARED)" ] ; then \
147             set -x; \
148             mv -f $(INSTALL_DIR)/lib/$(SHARED_NAME) \
149                 $(INSTALL_DIR)/lib/$(SHARED_NAME).old > /dev/null 2>&1; \
150             rm -f $(INSTALL_DIR)/lib/$(SHARED_NAME).old; \
151             cp $(SHARED_NAME) $(INSTALL_DIR)/lib; \
152             chmod 644 $(INSTALL_DIR)/lib/$(SHARED_NAME); \
153             chown -R root.root $(INSTALL_DIR)/lib/$(SHARED_NAME); \
154             rm -f $(INSTALL_DIR)/lib/libuClibc.so; \
155             ln -s $(INSTALL_DIR)/lib/$(SHARED_NAME) \
156                     $(INSTALL_DIR)/lib/libuClibc.so; \
157             /sbin/ldconfig; \
158         fi;
159         @if [ "$(HAS_MMU)" = "false" ] ; then \
160             set -x; \
161             rm -f $(INSTALL_DIR)/include/asm; \
162             rm -f $(INSTALL_DIR)/include/linux; \
163             mkdir -p $(INSTALL_DIR)/include/bits; \
164             ln -s $(KERNEL_SOURCE)/include/asm $(INSTALL_DIR)/include/asm; \
165             ln -s $(KERNEL_SOURCE)/include/linux $(INSTALL_DIR)/include/linux; \
166             find include/ -type f -depth -print | cpio -pdmu $(INSTALL_DIR); \
167             find include/bits/ -depth -print | cpio -pdmu $(INSTALL_DIR); \
168             rm -f $(INSTALL_DIR)/lib/$(STATIC_NAME); \
169             cp $(STATIC_NAME) $(INSTALL_DIR)/lib; \
170             chmod 644 $(INSTALL_DIR)/lib/$(STATIC_NAME); \
171             chown -R root.root $(INSTALL_DIR)/lib/$(STATIC_NAME); \
172             if [ -f crt0.o ] ; then \
173                 rm -f $(INSTALL_DIR)/lib/crt0.o; \
174                 cp crt0.o $(INSTALL_DIR)/lib ; \
175                 chmod 644 $(INSTALL_DIR)/lib/crt0.o; \
176                 chown -R root.root $(INSTALL_DIR)/lib/crt0.o; \
177             fi; \
178             chmod -R 775 `find $(INSTALL_DIR)/include -type d`; \
179             chmod -R 644 `find $(INSTALL_DIR)/include -type f`; \
180             chown -R root.root $(INSTALL_DIR)/include; \
181         fi;
182
183 uClibc_config.h: Config
184         @echo "/* WARNING!!! AUTO-GENERATED FILE!!! DO NOT EDIT!!! */" > uClibc_config.h
185         @echo "#if !defined __FEATURES_H && !defined __need_uClibc_config_h" >> uClibc_config.h
186         @echo "#error Never include <bits/uClibc_config.h> directly; use <features.h> instead." >> uClibc_config.h
187         @echo "#endif" >> uClibc_config.h
188         @echo "#define linux 1" >> uClibc_config.h 
189         @echo "#define __linux__ 1" >> uClibc_config.h 
190         @if [ "$(HAS_MMU)" = "true" ] ; then \
191             echo "#define __UCLIBC_HAS_MMU__ 1" >> uClibc_config.h ; \
192         else \
193             echo "#undef __UCLIBC_HAS_MMU__" >> uClibc_config.h ; \
194         fi
195         @if [ "$(HAS_FLOATS)" = "true" ] ; then \
196             echo "#define __UCLIBC_HAS_FLOATS__ 1" >> uClibc_config.h ; \
197         else \
198             echo "#undef __UCLIBC_HAS_FLOATS__" >> uClibc_config.h ; \
199         fi
200         @if [ "$(HAS_LONG_LONG)" = "true" ] ; then \
201             echo "#define __UCLIBC_HAS_LONG_LONG__ 1" >> uClibc_config.h ; \
202         else \
203             echo "#undef __UCLIBC_HAS_LONG_LONG__" >> uClibc_config.h ; \
204         fi
205         @if [ "$(HAS_LOCALE)" = "true" ] ; then \
206             echo "#define __UCLIBC_HAS_LOCALE__ 1" >> uClibc_config.h ; \
207             echo "#define __UCLIBC_LOCALE_DIR \""$(LOCALE_DIR)"\"" >> uClibc_config.h ; \
208         else \
209             echo "#undef __UCLIBC_HAS_LOCALE__" >> uClibc_config.h ; \
210         fi
211         @if [ "$(TARGET_ARCH)" = "m68k" ] ; then \
212             echo "#define __VFORK_MACRO__ 1" >> uClibc_config.h ; \
213             if [ `expr match "$(CC)" ".*\(m68k-elf-.*\)"`x = x ]; then \
214                 echo "#define const" >> uClibc_config.h ; \
215                 echo "#define __const" >> uClibc_config.h ; \
216                 echo "#define __extension" >> uClibc_config.h ; \
217             fi; \
218         else \
219             echo "#undef __VFORK_MACRO__" >> uClibc_config.h ; \
220         fi
221         @if [ "$(TARGET_ARCH)" = "sh" ] ; then \
222             echo "#define NO_UNDERSCORES 1" >> uClibc_config.h ; \
223         else \
224             echo "#undef NO_UNDERSCORES" >> uClibc_config.h ; \
225         fi
226
227 .PHONY: dummy
228