summaryrefslogtreecommitdiff
path: root/newlib/Makefile.am
blob: 99cfa692f8cdd0b037f5c670079bc2ede5817241 (plain)
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
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
# 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

include $(top_srcdir)/Makefoo.am

# Remark: given that the newlib build system doesn't do any form of dependency
# tracking, it is correct to completely rebuild everything as soon as one of
# the $patch_files or $addon files changes.  Also it may be necessary to force
# a complete rebuild if one of the header files the newlib build depends on
# changes.  This is currently not being tracked in here.

# Patches to apply to newlib's source tree.
patch_files = \
	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 \
	05-newlib-newlib-libc-include-machine-setjmp-h.patch \
	06-newlib-newlib-libc-machine-i386-i386mach-h.patch \
	07-newlib-newlib-libm-machine-i386-i386mach-h.patch

# Files to link into newlib's source tree (relative to $(srcdir)/addon)
addon = \
	newlib/libc/sys/hurd/configure.ac \
	newlib/libc/sys/hurd/Makefile.am \
	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/include/signal.h \
	newlib/libc/sys/hurd/sys/lock.h \
	newlib/libc/sys/hurd/sys/config.h \
	newlib/libc/sys/hurd/sys/errno.h \
	newlib/libc/sys/hurd/access.c \
	newlib/libc/sys/hurd/fsync.c \
	newlib/libc/sys/hurd/ftruncate.c \
	newlib/libc/sys/hurd/getcwd.c \
	newlib/libc/sys/hurd/getpwuid.c \
	newlib/libc/sys/hurd/getrusage.c \
	newlib/libc/sys/hurd/getuid.c \
	newlib/libc/sys/hurd/sleep.c \
	newlib/libc/sys/hurd/fd.h \
	newlib/libc/sys/hurd/pipefile.c \
	newlib/libc/sys/hurd/memfile.c

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/unpack.stamp: $(srcdir)/$(newlib_tarball)
	if test -d $(srcdir)/newlib/.; then \
		echo "Refusing to extract over $(srcdir)/newlib"; \
		exit 1; \
	fi
	( cd $(srcdir) \
		&& tar xfvz $(newlib_tarball) \
		&& mv $(subst .tar.gz,,$(newlib_tarball)) newlib )
	touch $@

# Apply any local patches.  (Revert any applied older version.)
$(addprefix $(srcdir)/newlib/,$(addsuffix .applied,$(patch_files))): $(srcdir)/newlib/unpack.stamp
$(addprefix $(srcdir)/newlib/,$(addsuffix .applied,$(patch_files))): $(srcdir)/newlib/%.applied: $(srcdir)/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

# Link the addon files into the source tree.
$(addprefix $(srcdir)/newlib/, $(addon)): $(srcdir)/newlib/unpack.stamp
$(addprefix $(srcdir)/newlib/, $(addon)): $(srcdir)/newlib/%: $(srcdir)/addon/%
	mkdir -p $(dir $@)
	$(LN_S) -f $(abspath $<) $@
# Touch the file, as Make follows symlinks, the source file for sure is younger
# than the unpack.stamp and thus those files will get linked again and again.
	touch $@

$(srcdir)/newlib/patch.stamp: $(srcdir)/newlib/unpack.stamp \
  $(addprefix $(srcdir)/newlib/,$(addsuffix .applied,$(patch_files))) \
  $(addprefix $(srcdir)/newlib/,$(addon))
	cd $(srcdir)/newlib/ && \
	$(fix_config_guess_and_sub)
	cd $(srcdir)/newlib/newlib/ && \
	autoreconf
# PACKAGE_* are not supposed to be defined in such public header files.
	cd $(srcdir)/newlib/newlib/ && \
	$(SED) /PACKAGE_/d < newlib.hin > newlib.hin.tmp && \
	mv newlib.hin.tmp newlib.hin
	touch $@

newlib-build/configure.stamp: $(srcdir)/newlib/patch.stamp
	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 \
	--host=$(host_alias) CC=$(host_alias)-gcc \
	)
	touch $@

if ARCH_X86_64
  # Without -fPIC, when linking Viengoos against libc-routines, we get
  # errors of the following form:
  #
  #   ../newlib/libc-routines.a(lib_a-strcpy.o):(.eh_frame+0x20): 
  #         relocation truncated to fit: R_X86_64_32 against `.text'
  EXTRA_CFLAGS = -fPIC
else
  EXTRA_CFLAGS =
endif

.PHONY: newlib-build/build.stamp
newlib-build/build.stamp: newlib-build/configure.stamp
	cd newlib-build && \
	  make \
	    TARGET_CFLAGS='$(EXTRA_CFLAGS) $(USER_CPPFLAGS) $(USER_CFLAGS) $(USER_LDFLAGS)' \
	    all
	if test newlib-build/libc.a -nt newlib-build/build.stamp; then \
	  ( cd newlib-build \
	    && make \
	      TARGET_CFLAGS='$(USER_CPPFLAGS) $(USER_CFLAGS) $(USER_LDFLAGS)' \
	      install ); \
	  touch $@; \
	fi

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

all-local: newlib-build/build.stamp libc.a libm.a libc-routines.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 \
	strcpy 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-build/configure.stamp
	ln -sf newlib-install/$(host_alias)/include include

#TODO.
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