1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
# Makefile.am - Makefile template for newlib's libc
# Copyright (C) 2003, 2005, 2008 Free Software Foundation, Inc.
# Written by Neal H. Walfield
#
# This file is part of the GNU Hurd.
#
# The GNU Hurd is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# The GNU Hurd is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
noinst_LIBRARIES = libc.a libm.a libc-routines.a
# Patches to apply to newlib's source tree.
patch_files = 00-newlib-configure-ac.patch \
01-newlib-libc-sys-configure-in.patch \
02-newlib-newlib-libc-string-makefile-am.patch \
03-newlib-newlib-configure-host.patch \
04-newlib-newlib-configure-ac.patch
# Files to link into newlib's source tree (relative to $(srcdir)/addon)
addon = newlib/libc/sys/hurd/configure.ac \
newlib/libc/sys/hurd/configure \
newlib/libc/sys/hurd/Makefile.am \
newlib/libc/sys/hurd/Makefile.in \
newlib/libc/sys/hurd/aclocal.m4 \
newlib/libc/sys/hurd/closer.c \
newlib/libc/sys/hurd/reent.c \
newlib/libc/sys/hurd/fcntlr.c \
newlib/libc/sys/hurd/fstatr.c \
newlib/libc/sys/hurd/gettimeofdayr.c \
newlib/libc/sys/hurd/linkr.c \
newlib/libc/sys/hurd/lseekr.c \
newlib/libc/sys/hurd/openr.c \
newlib/libc/sys/hurd/readr.c \
newlib/libc/sys/hurd/renamer.c \
newlib/libc/sys/hurd/signalr.c \
newlib/libc/sys/hurd/sbrkr.c \
newlib/libc/sys/hurd/statr.c \
newlib/libc/sys/hurd/timesr.c \
newlib/libc/sys/hurd/unlinkr.c \
newlib/libc/sys/hurd/writer.c \
newlib/libc/sys/hurd/isatty.c \
newlib/libc/sys/hurd/getreent.c \
newlib/libc/sys/hurd/malloc.c \
newlib/libc/sys/hurd/mallocr.c \
newlib/libc/sys/hurd/lock.c \
newlib/libc/sys/hurd/crt0.c \
newlib/libc/sys/hurd/include/pthread.h \
newlib/libc/sys/hurd/include/assert.h \
newlib/libc/sys/hurd/sys/lock.h \
newlib/libc/sys/hurd/sys/config.h \
newlib/libc/sys/hurd/sys/errno.h
EXTRA_DIST = $(addprefix patches/, $(patch_files)) \
$(addprefix addon/, $(addon))
# The newlib C library version that we build against.
newlib_tarball = newlib-1.16.0.tar.gz
newlib_snapshot = ftp://sources.redhat.com/pub/newlib/$(newlib_tarball)
# Grab the snapshot
$(srcdir)/$(newlib_tarball):
wget $(newlib_snapshot) -O $(srcdir)/$(newlib_tarball)
# Extract it.
$(srcdir)/newlib $(srcdir)/newlib-stamp: $(srcdir)/$(newlib_tarball)
if test -e $(srcdir)/newlib; then \
echo "Refusing to extract over $(srcdir)/newlib"; \
exit 1; \
fi
rm -f $(builddir)/*-applied
( cd $(srcdir) \
&& tar xfvz $(newlib_tarball) \
&& mv $(subst .tar.gz,,$(newlib_tarball)) newlib )
touch $(srcdir)/newlib
touch $(srcdir)/newlib-stamp
# Apply any local patches. (Revert any applied older version.)
$(addsuffix -applied,$(patch_files)): $(srcdir)/newlib
$(addsuffix -applied,$(patch_files)): %-applied: patches/%
if test -e "$@"; \
then \
( cd $(srcdir)/newlib && sh /dev/stdin -R ) < $@ && rm -f $@; \
fi
( cd $(srcdir)/newlib && sh /dev/stdin ) < $<
cp $< $@
rpatch:
for p in $(shell tac -s ' ' $(patch_files)) ; do \
(cd $(srcdir)/newlib; sh ../$(srcdir)/$${p} -R) || exit 1 ; \
done
# Don't use in-place evaluation, as the referenced values may not yet be
# available.
abs_top_builddir = $(abspath $(top_builddir))
abs_srcdir = $(abspath $(srcdir))
abs_top_srcdir = $(abspath $(top_srcdir))
# Link the addon files into the source tree.
$(addprefix $(srcdir)/newlib/, $(addon)): $(srcdir)/newlib-stamp
$(addprefix $(srcdir)/newlib/, $(addon)): $(srcdir)/newlib/%: $(srcdir)/addon/%
mkdir -p $(dir $@)
$(LN_S) -f $(abspath $<) $@
newlib-configure-stamp: $(addsuffix -applied,$(patch_files)) \
$(addprefix $(srcdir)/newlib/, $(addon))
( cd $(srcdir)/newlib/newlib && autoreconf )
rm -rf newlib-build
mkdir newlib-build
(cd newlib-build && $(abs_srcdir)/newlib/newlib/configure \
--enable-maintainer-mode \
--disable-shared --disable-newlib-iconv --disable-multilib \
--enable-newlib-hw-fp --enable-newlib-io-pos-args \
--enable-newlib-io-c99-formats --enable-newlib-io-long-long \
--enable-newlib-io-long-double \
--enable-newlib-multithread \
--prefix=$(abs_top_builddir)/newlib/newlib-install \
--build=$(build_alias) --host=$(host_alias))
touch newlib-configure-stamp
# Ripped from glibc.
ccheaders := $(shell $(CC) -print-file-name=include)
SYSINCLUDES := -nostdinc -isystem $(ccheaders) -isystem $(ccheaders)-fixed
newlib-build/libc.a newlib-build/libm.a: newlib-configure-stamp
cd newlib-build && \
make \
TARGET_CFLAGS='\
-I$(abs_top_builddir)/include \
-I$(abs_top_srcdir)/libc-parts \
$(SYSINCLUDES) \
-nostdlib \
-fno-stack-protector' \
all install
libc.a: newlib-build/libc.a
ln -sf newlib-build/libc.a libc.a
libm.a: newlib-build/libm.a
ln -sf newlib-build/libm.a libm.a
# The following routines (should be) fine to be used in non-libc-linked code as
# well, so there's no need in duplicating their code somewhere else.
#routines := \
# memcpy memmove memset bcopy bzero memchr rawmemchr \
# strstr strtok strchr strrchr strchrnul strcpy stpcpy \
# strcat strcmp strncmp strlen strnlen \
# atoi atoll strtoimax strtoumax \
# htonl htons ntohl ntohs ffs
routines := \
memcpy memmove memset \
strcmp strncmp strlen
# We have to find all modules in the archive which contain the above functions.
routines_subexp := 's/^\($(shell echo $(routines) \
| $(SED) -e 's/ \+/\\|/g')\) in \(.*\)$$/\2/p'
libc-routines.a: libc.a Makefile
rm -rf '$@'.d
mkdir '$@'.d
{ $(NM) --print-armap '$<' \
|| echo CHOKE/ME; } | \
{ $(SED) -n -e $(routines_subexp) \
|| echo CHOKE/ME/2; } | \
{ $(SORT) -u \
|| echo CHOKE/ME/3; } | \
( cd '$@'.d/ && \
xargs $(AR) -x ../'$<' \
)
$(AR) qc '$@'.new '$@'.d/*
rm -rf '$@'.d
$(RANLIB) '$@'.new
mv -f '$@'.new '$@'
all: include
include: newlib-configure-stamp
ln -sf newlib-install/$(host_alias)/include include
clean-local:
rm -rf newlib-build
rm -rf newlib-install
rm -rf $(srcdir)/newlib
rm -rf libc-routines.a libc-routines.a.d
CLEANFILES = newlib-configure-stamp \
$(srcdir)/newlib-stamp $(addsuffix -applied,$(patch_files)) \
include
DISTCLEANFILES = $(srcdir)/$(newlib_tarball) \
$(srcdir)/newlib-configure-stamp
|