Subversion Repositories avr32-toolchain

Rev

Rev 10 | Rev 12 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
4 jasmin 1
# AVR32 Toolchain Makefile
2
#
3
# Copyright (C) 2011 by James Snyder <jbsnyder@fanplastic.org>
4
#
5
# Permission is hereby granted, free of charge, to any person obtaining a copy
6
# of this software and associated documentation files (the "Software"), to deal
7
# in the Software without restriction, including without limitation the rights
8
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
# copies of the Software, and to permit persons to whom the Software is
10
# furnished to do so, subject to the following conditions:
11
#
12
# The above copyright notice and this permission notice shall be included in
13
# all copies or substantial portions of the Software.
14
#
15
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
# THE SOFTWARE.
22
 
23
#### PRIMARY TOOLCHAIN VERSIONS #####
24
 
7 jasmin 25
GCC_VERSION       = 4.4.3
26
GDB_VERSION_DLOAD = 6.7.1a
27
GDB_VERSION       = 6.7.1
28
BINUTILS_VERSION  = 2.20.1
29
NEWLIB_VERSION    = 1.16.0
30
DFU_VERSION       = 0.5.4
31
AVR_PATCH_REV	  = 3.2.3.261
32
AVR_HEADER_REV    = 3.2.3.258
4 jasmin 33
 
34
 
35
#### PATHS AND ENVIRONMENT VARIABLES #####
36
 
37
SHELL       = /bin/bash
38
TARGET      = avr32
39
 
40
TODAY = $(shell date "+%Y%m%d")
9 jasmin 41
GIT_REV	    = $(shell git rev-parse --verify HEAD --short 2> /dev/null)
42
SVN_REV	    = $(shell head -1 ReleaseNotes 2> /dev/null | cut -f 1 -d " ")
4 jasmin 43
 
44
ifeq ($(strip $(GIT_REV)),)
9 jasmin 45
ifeq ($(strip $(SVN_REV)),)
4 jasmin 46
PREFIX     ?= $(HOME)/avr32-tools-$(TODAY)
9 jasmin 47
TOOL_REV   = $(TODAY)
4 jasmin 48
else
9 jasmin 49
PREFIX     ?= $(HOME)/avr32-tools-$(SVN_REV)
50
TOOL_REV   = $(SVN_REV)
51
BUG_URL = jasmin@anw.at
52
endif
53
else
4 jasmin 54
PREFIX     ?= $(HOME)/avr32-tools-$(GIT_REV)
9 jasmin 55
TOOL_REV   = $(GIT_REV)
4 jasmin 56
endif
57
 
58
ifeq ($(UNAME), Linux)
59
PROCS  ?= $(shell grep -c ^processor /proc/cpuinfo)
60
else ifeq ($(UNAME), Darwin)
61
PROCS  ?= $(shell sysctl hw.ncpu | awk '{print $$2}')
62
else
63
PROCS  ?= 2
64
endif
65
 
66
SUPP_PREFIX = $(CURDIR)/supp
67
PATH       := ${PREFIX}/bin:${SUPP_PREFIX}/bin:${PATH}
68
AUTOCONF    = $(SUPP_PREFIX)/bin/autoconf
69
AUTOMAKE    = $(SUPP_PREFIX)/bin/automake
70
 
10 jasmin 71
STAMP_DIR  := $(CURDIR)/stamps
72
DOWNLOAD_DIR := $(CURDIR)/downloads
73
 
9 jasmin 74
ifeq ($(strip $(BUG_URL)),)
4 jasmin 75
BUG_URL = https://github.com/jsnyder/avr32-toolchain
9 jasmin 76
endif
77
PKG_VERSION = "AVR 32 bit GNU Toolchain-$(AVR_PATCH_REV)-$(TOOL_REV)"
4 jasmin 78
 
79
 
80
#### PRIMARY TOOLCHAIN URLS #####
81
 
82
GCC_ARCHIVE = gcc-$(GCC_VERSION).tar.bz2
83
GCC_URL = http://mirror.anl.gov/pub/gnu/gcc/gcc-$(GCC_VERSION)/$(GCC_ARCHIVE)
84
GCC_MD5 = fe1ca818fc6d2caeffc9051fe67ff103
85
 
7 jasmin 86
GDB_ARCHIVE = gdb-$(GDB_VERSION_DLOAD).tar.bz2
4 jasmin 87
GDB_URL = http://mirror.anl.gov/pub/gnu/gdb/$(GDB_ARCHIVE)
7 jasmin 88
GDB_MD5 = 3564f308f3e4d4f2750891bc2ce9b214
4 jasmin 89
 
90
BINUTILS_ARCHIVE = binutils-$(BINUTILS_VERSION).tar.bz2
91
BINUTILS_URL = http://mirror.anl.gov/pub/gnu/binutils/$(BINUTILS_ARCHIVE)
92
BINUTILS_MD5 = 2b9dc8f2b7dbd5ec5992c6e29de0b764
93
 
94
NEWLIB_ARCHIVE = newlib-$(NEWLIB_VERSION).tar.gz
95
NEWLIB_URL = ftp://sources.redhat.com/pub/newlib/$(NEWLIB_ARCHIVE)
96
NEWLIB_MD5 = bf8f1f9e3ca83d732c00a79a6ef29bc4
97
 
98
AVR32PATCHES_ARCHIVE = avr32-gnu-toolchain-$(AVR_PATCH_REV)-source.zip
99
AVR32PATCHES_URL=http://www.atmel.com/dyn/resources/prod_documents/$(AVR32PATCHES_ARCHIVE)
100
AVR32PATCHES_MD5 = 69a03828a328068f25d457cfd8341857
101
 
102
AVR32HEADERS_ARCHIVE = avr32-headers-$(AVR_HEADER_REV).zip
103
AVR32HEADERS_URL=http://www.atmel.com/dyn/resources/prod_documents/$(AVR32HEADERS_ARCHIVE)
104
AVR32HEADERS_MD5 = 3293d70a46e460d342e1f939b8e0d228
105
 
106
DFU_ARCHIVE = dfu-programmer-$(DFU_VERSION).tar.gz
107
DFU_URL = http://surfnet.dl.sourceforge.net/project/dfu-programmer/dfu-programmer/$(DFU_VERSION)/$(DFU_ARCHIVE)
108
DFU_MD5 = 707dcd0f957a74e92456ea6919faa772
109
 
110
 
111
##### SUPPORT TOOLS VERSIONS / URLS ######
112
AUTOCONF_VERSION = 2.64
113
AUTOMAKE_VERSION = 1.11
114
MPC_VERSION = 0.8.1
115
 
116
AUTOCONF_ARCHIVE = autoconf-$(AUTOCONF_VERSION).tar.bz2
117
AUTOCONF_URL = http://mirror.anl.gov/pub/gnu/autoconf/$(AUTOCONF_ARCHIVE)
118
AUTOCONF_MD5 = ef400d672005e0be21e0d20648169074
119
 
120
AUTOMAKE_ARCHIVE = automake-$(AUTOMAKE_VERSION).tar.bz2
121
AUTOMAKE_URL = http://mirror.anl.gov/pub/gnu/automake/$(AUTOMAKE_ARCHIVE)
122
AUTOMAKE_MD5 = 4db4efe027e26b33930a7e151de19d0f
123
 
124
 
125
 
126
.PHONY: install-tools
7 jasmin 127
install-tools: install-binutils install-final-gcc install-newlib install-headers
4 jasmin 128
 
129
.PHONY: install-cross
130
install-cross: install-tools install-note
131
 
132
 
133
.PHONY: sudomode
134
sudomode:
135
ifneq ($(USER),root)
136
	@echo Please run this target with sudo!
137
	@echo e.g.: sudo make targetname
138
	@exit 1
139
endif
140
 
141
 
142
.PHONY: tst
143
tst:
9 jasmin 144
	@echo "PREFIX=$(PREFIX)"
145
	@echo "PKG_VERSION=$(PKG_VERSION)"
146
	@echo "BUG_URL=$(BUG_URL)"
4 jasmin 147
 
10 jasmin 148
 
149
############ MACROS for the lazy people ;-) ############
150
 
151
ifeq ($(strip $(MAKEFLAGS)),s)
152
define quiet_text
153
	@echo "$1"
154
endef
155
else
156
define quiet_text
157
endef
158
endif
159
 
160
## remove a stamp
161
define rm_stamp
162
	rm -f $(STAMP_DIR)/$(1)
163
endef
164
 
165
## create the stamp directory if not existing and the stamp
166
define make_stamp
167
	@[ -d $(STAMP_DIR) ] || mkdir $(STAMP_DIR)
168
	date > $(STAMP_DIR)/$(1)
169
endef
170
 
11 jasmin 171
define GET_MY_VARS
172
UP_$(1):=$$(shell echo "$(1)" | tr '[a-z]' '[A-Z]')
173
MY_ARCHIVE:=$$($$(UP_$(1))_ARCHIVE)
174
MY_URL:=$$($$(UP_$(1))_URL)
175
MY_MD5:=$$($$(UP_$(1))_MD5)
176
endef
177
 
10 jasmin 178
## create the download rule and force download rule
179
define DOWNLOAD_template
11 jasmin 180
$(call GET_MY_VARS,$(1))
181
download-$(1): $(DOWNLOAD_DIR)/$$(MY_ARCHIVE)
182
download-$(1)-f $(DOWNLOAD_DIR)/$$(MY_ARCHIVE): $(DOWNLOAD_DIR)
183
	cd $(DOWNLOAD_DIR) && curl -LO $$(MY_URL)
10 jasmin 184
PHONY += download-$(1) download-$(1)-f
185
endef
186
 
187
## extract commands
188
EXT_BZ2 := tar -jxf
189
EXT_TGZ := tar -xf
190
EXT_ZIP := unzip -o
191
 
192
## create the extract rule and force extract rule
193
define EXTRACT_template
11 jasmin 194
$(call GET_MY_VARS,$(1))
10 jasmin 195
extract-$(1): $(STAMP_DIR)/extract-$(1)
11 jasmin 196
extract-$(1)-f $(STAMP_DIR)/extract-$(1): $(DOWNLOAD_DIR)/$$(MY_ARCHIVE)
10 jasmin 197
	@(rm -rf autoconf-*; \
198
	t1=`openssl md5 $$< | cut -f 2 -d " " -` && \
11 jasmin 199
	[ "$$$$t1" = "$$(MY_MD5)" ] || \
10 jasmin 200
	( echo "Bad Checksum! Please remove the following file and retry: $$<" && false ))
11 jasmin 201
	$(call quiet_text,"Extracting $$(MY_ARCHIVE)")
10 jasmin 202
	$($(2)) $$<
203
	$(call make_stamp,extract-$(1))
204
PHONY += extract-$(1) extract-$(1)-f
205
endef
206
 
207
$(DOWNLOAD_DIR):
208
	mkdir $(DOWNLOAD_DIR)
209
 
11 jasmin 210
$(eval $(call DOWNLOAD_template,autoconf))
211
$(eval $(call EXTRACT_template,autoconf,EXT_BZ2))
10 jasmin 212
 
213
.PHONY: $(PHONY)
214
 
215
 
216
.PHONY: tst2 tst3
217
tst2:
218
	$(call make_stamp,JES)
219
tst3:
220
	$(call rm_stamp,JES)
221
 
222
 
4 jasmin 223
.PHONY: install-note
224
install-note: install-tools
225
	@echo
226
	@echo ====== INSTALLATION NOTE ======
227
	@echo Your tools have now been installed at the following prefix:
228
	@echo $(PREFIX)
229
	@echo
230
	@echo Please be sure to add something similar to the following to your .bash_profile, .zshrc, etc:
231
	@echo export PATH=$(PREFIX)/bin:'$$PATH'
232
 
233
 
7 jasmin 234
.PHONY: install-supp-tools install-supp-tools-force
235
install-supp-tools: stamps/install-supp-tools
236
install-supp-tools-force stamps/install-supp-tools: stamps/install-autoconf stamps/install-automake
237
	[ -d stamps ] || mkdir stamps ;
238
	touch stamps/install-supp-tools;
4 jasmin 239
 
7 jasmin 240
.PHONY: clean-supp-tools
241
clean-supp-tools: clean-autoconf clean-automake
242
	rm stamps/install-supp-tools;
4 jasmin 243
 
7 jasmin 244
.PHONY: realclean-supp-tools
245
realclean-supp-tools: realclean-autoconf realclean-automake
246
	rm stamps/install-supp-tools;
4 jasmin 247
 
248
 
249
############# SUPP: AUTOCONF ############
250
 
10 jasmin 251
##.PHONY: download-autoconf download-autoconf-force
252
##download-autoconf: downloads/$(AUTOCONF_ARCHIVE)
253
##download-autoconf-force downloads/$(AUTOCONF_ARCHIVE):
254
##	[ -d downloads ] || mkdir downloads ;
255
##	cd downloads && curl -LO $(AUTOCONF_URL)
4 jasmin 256
 
10 jasmin 257
##.PHONY: extract-autoconf extract-autoconf-force
258
##extract-autoconf: stamps/extract-autoconf
259
##extract-autoconf-force stamps/extract-autoconf: downloads/$(AUTOCONF_ARCHIVE)
260
##	@(t1=`openssl md5 $< | cut -f 2 -d " " -` && \
261
##	[ "$$t1" = "$(AUTOCONF_MD5)" ] || \
262
##	( echo "Bad Checksum! Please remove the following file and retry: $<" && false ))
263
##	tar -jxf $< ;
264
##	[ -d stamps ] || mkdir stamps ;
265
##	touch stamps/extract-autoconf;
4 jasmin 266
 
7 jasmin 267
.PHONY: build-autoconf build-autoconf-force
268
build-autoconf: stamps/build-autoconf
269
build-autoconf-force stamps/build-autoconf: stamps/extract-autoconf
4 jasmin 270
	mkdir -p build/autoconf && cd build/autoconf && \
271
	../../autoconf-$(AUTOCONF_VERSION)/configure --prefix="$(SUPP_PREFIX)" && \
272
	$(MAKE) -j$(PROCS)
273
	[ -d stamps ] || mkdir stamps
274
	touch stamps/build-autoconf;
275
 
7 jasmin 276
.PHONY: install-autoconf install-autoconf-force
277
install-autoconf: stamps/install-autoconf
278
install-autoconf-force stamps/install-autoconf:  stamps/build-autoconf
4 jasmin 279
	cd build/autoconf && \
280
	$(MAKE) install
281
	[ -d stamps ] || mkdir stamps
282
	touch stamps/install-autoconf;
283
 
7 jasmin 284
.PHONY: clean-autoconf
285
clean-autoconf:
286
	rm -rf build/autoconf stamps/*-autoconf autoconf-*
4 jasmin 287
 
7 jasmin 288
.PHONY: realclean-autoconf
9 jasmin 289
realclean-autoconf: clean-autoconf
7 jasmin 290
	rm downloads/$(AUTOCONF_ARCHIVE)
4 jasmin 291
 
7 jasmin 292
 
4 jasmin 293
############ SUPP: AUTOMAKE ############
294
 
7 jasmin 295
.PHONY: download-automake download-automake-force
296
download-automake: downloads/$(AUTOMAKE_ARCHIVE)
297
download-automake-force downloads/$(AUTOMAKE_ARCHIVE):
4 jasmin 298
	[ -d downloads ] || mkdir downloads ;
299
	cd downloads && curl -LO $(AUTOMAKE_URL)
300
 
7 jasmin 301
.PHONY: extract-automake extract-automake-force
302
extract-automake: stamps/extract-automake
303
extract-automake-force stamps/extract-automake: downloads/$(AUTOMAKE_ARCHIVE)
4 jasmin 304
	@(t1=`openssl md5 $< | cut -f 2 -d " " -` && \
305
	[ "$$t1" = "$(AUTOMAKE_MD5)" ] || \
306
	( echo "Bad Checksum! Please remove the following file and retry: $<" && false ))
307
	tar -jxf $< ;
308
	[ -d stamps ] || mkdir stamps ;
309
	touch stamps/extract-automake;
310
 
7 jasmin 311
.PHONY: build-automake build-automake-force
312
build-automake: stamps/build-automake
313
build-automake-force stamps/build-automake: stamps/extract-automake stamps/install-autoconf
4 jasmin 314
	mkdir -p build/automake && cd build/automake && \
315
	../../automake-$(AUTOMAKE_VERSION)/configure --prefix="$(SUPP_PREFIX)" && \
316
	$(MAKE) -j$(PROCS)
317
	[ -d stamps ] || mkdir stamps
318
	touch stamps/build-automake;
319
 
7 jasmin 320
.PHONY: install-automake install-automake-force
321
install-automake: stamps/install-automake
322
install-automake-force stamps/install-automake: stamps/build-automake
4 jasmin 323
	cd build/automake && \
324
	$(MAKE) install
325
	[ -d stamps ] || mkdir stamps
326
	touch stamps/install-automake;
327
 
7 jasmin 328
.PHONY: clean-automake
329
clean-automake:
330
	rm -rf build/automake stamps/*-automake automake-*
4 jasmin 331
 
7 jasmin 332
.PHONY: realclean-automake
333
realclean-automake: clean-automake
334
	rm downloads/$(AUTOMAKE_ARCHIVE)
4 jasmin 335
 
7 jasmin 336
 
4 jasmin 337
############# AVR32 PATCHES ############
338
 
7 jasmin 339
.PHONY: download-avr32patches download-avr32patches-force
340
download-avr32patches: downloads/$(AVR32PATCHES_ARCHIVE)
341
download-avr32patches-force downloads/$(AVR32PATCHES_ARCHIVE):
4 jasmin 342
	cd downloads && curl -LO $(AVR32PATCHES_URL)
343
 
7 jasmin 344
.PHONY: extract-avr32patches extract-avr32patches-force
345
extract-avr32patches: stamps/extract-avr32patches
346
extract-avr32patches-force stamps/extract-avr32patches: downloads/$(AVR32PATCHES_ARCHIVE)
4 jasmin 347
	@(t1=`openssl md5 $< | cut -f 2 -d " " -` && \
348
	[ "$$t1" = "$(AVR32PATCHES_MD5)" ] || \
349
	( echo "Bad Checksum! Please remove the following file and retry: $<" && false ))
350
	unzip -o $<
351
	[ -d stamps ] || mkdir stamps
352
	touch stamps/extract-avr32patches;
353
 
7 jasmin 354
.PHONY: clean-avr32patches
355
clean-avr32patches:
356
	rm -rf stamps/*-avr32patches source
4 jasmin 357
 
7 jasmin 358
.PHONY: realclean-avr32patches
359
realclean-avr32patches: clean-avr32patches
360
	rm downloads/$(AVR32PATCHES_ARCHIVE)
361
 
362
 
4 jasmin 363
############# AVR32 HEADERS ############
364
 
7 jasmin 365
.PHONY: download-avr32headers download-avr32headers-force
366
download-avr32headers: downloads/$(AVR32HEADERS_ARCHIVE)
367
download-avr32headers-force downloads/$(AVR32HEADERS_ARCHIVE):
4 jasmin 368
	cd downloads && curl -LO $(AVR32HEADERS_URL)
369
 
7 jasmin 370
.PHONY: install-headers install-headers-force
371
install-headers: stamps/install-headers
372
install-headers-force stamps/install-headers: downloads/$(AVR32HEADERS_ARCHIVE) stamps/install-final-gcc
4 jasmin 373
	@(t1=`openssl md5 $< | cut -f 2 -d " " -` && \
374
	[ "$$t1" = "$(AVR32HEADERS_MD5)" ] || \
375
	( echo "Bad Checksum! Please remove the following file and retry: $<" && false ))
376
	unzip -o $< -d "$(PREFIX)/$(TARGET)/include/" && \
377
	[ -d stamps ] || mkdir stamps
378
	touch stamps/install-headers;
379
 
7 jasmin 380
.PHONY: clean-headers
381
clean-headers:
382
	rm -rf stamps/*-headers $(PREFIX)/$(TARGET)/include/avr32
4 jasmin 383
 
7 jasmin 384
.PHONY: realclean-headers
385
realclean-headers: clean-headers
386
	rm downloads/$(AVR32HEADERS_ARCHIVE)
387
 
388
 
4 jasmin 389
################ NEWLIB ################
390
 
7 jasmin 391
.PHONY: download-newlib download-newlib-force
392
download-newlib: downloads/$(NEWLIB_ARCHIVE)
393
download-newlib-force downloads/$(NEWLIB_ARCHIVE):
4 jasmin 394
	[ -d downloads ] || mkdir downloads ;
395
	cd downloads && curl -LO $(NEWLIB_URL)
396
 
7 jasmin 397
.PHONY: extract-newlib extract-newlib-force
398
extract-newlib: stamps/extract-newlib
399
extract-newlib-force stamps/extract-newlib : downloads/$(NEWLIB_ARCHIVE)
4 jasmin 400
	@(t1=`openssl md5 $< | cut -f 2 -d " " -` && \
401
	[ "$$t1" = "$(NEWLIB_MD5)" ] || \
402
	( echo "Bad Checksum! Please remove the following file and retry: $<" && false ))
403
	tar -xf $<
404
	[ -d stamps ] || mkdir stamps
405
	touch stamps/extract-newlib;
406
 
407
 
7 jasmin 408
.PHONY: patch-newlib patch-newlib-force
409
patch-newlib: stamps/patch-newlib
410
patch-newlib-force stamps/patch-newlib: stamps/extract-newlib stamps/extract-avr32patches
4 jasmin 411
	pushd newlib-$(NEWLIB_VERSION) ; \
412
	for f in ../source/avr32/newlib/*.patch; do \
413
	patch -N -p0 <$${f} ; \
414
	done ; \
415
	popd ;
416
	[ -d stamps ] || mkdir stamps
417
	touch stamps/patch-newlib;
418
 
7 jasmin 419
.PHONY: regen-newlib regen-newlib-force
420
regen-newlib: stamps/regen-newlib
421
regen-newlib-force stamps/regen-newlib: stamps/patch-newlib stamps/install-supp-tools
4 jasmin 422
	pushd newlib-$(NEWLIB_VERSION) ; \
423
	"$(SUPP_PREFIX)/bin/autoconf"; "$(SUPP_PREFIX)/bin/automake" ; \
424
	for dir in newlib/libc/machine/avr32 newlib/libc/machine newlib/libc/sys/avr32 newlib/libc/sys; do \
425
	  pushd $$dir ; \
426
	  "$(SUPP_PREFIX)/bin/aclocal" -I ../.. -I ../../.. -I ../../../.. ; \
427
	  "$(SUPP_PREFIX)/bin/autoconf"; "$(SUPP_PREFIX)/bin/automake"; \
428
	  popd ; \
429
	done; \
430
	popd;
431
	[ -d stamps ] || mkdir stamps
432
	touch stamps/regen-newlib;
433
 
434
NEWLIB_FLAGS="-ffunction-sections -fdata-sections	\
435
-DPREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__ -g -Os	\
436
-fomit-frame-pointer -fno-unroll-loops -D__BUFSIZ__=128	\
437
-DSMALL_MEMORY"
438
 
7 jasmin 439
.PHONY: build-newlib build-newlib-force
440
build-newlib: stamps/build-newlib
441
build-newlib-force stamps/build-newlib: stamps/regen-newlib stamps/install-binutils stamps/install-gcc
4 jasmin 442
	mkdir -p build/newlib && cd build/newlib && \
443
	pushd ../../newlib-$(NEWLIB_VERSION) ; \
444
	make clean ; \
445
	popd ; \
446
	../../newlib-$(NEWLIB_VERSION)/configure --prefix=$(PREFIX)	\
447
	--with-build-time-tools=$(PREFIX)				\
448
	--target=$(TARGET) --disable-newlib-supplied-syscalls		\
449
	--disable-libgloss --disable-nls --disable-shared		\
450
	--enable-newlib-io-long-long --enable-newlib-io-long-double	\
451
	--enable-target-optspace --enable-newlib-io-pos-args		\
452
	--enable-newlib-reent-small  && \
453
	$(MAKE) -j$(PROCS) CFLAGS_FOR_TARGET=$(NEWLIB_FLAGS) CCASFLAGS=$(NEWLIB_FLAGS) && \
454
	[ -d stamps ] || mkdir stamps
455
	touch stamps/build-newlib;
456
 
7 jasmin 457
.PHONY: install-newlib install-newlib-force
458
install-newlib: stamps/install-newlib
459
install-newlib-force stamps/install-newlib: stamps/build-newlib
4 jasmin 460
	cd build/newlib && \
461
	$(MAKE) install
462
	[ -d stamps ] || mkdir stamps
463
	touch stamps/install-newlib;
464
 
7 jasmin 465
.PHONY: clean-newlib
466
clean-newlib:
467
	rm -rf build/newlib stamps/*-newlib newlib-*
468
 
469
.PHONY: realclean-newlib
470
realclean-newlib: clean-newlib
471
	rm downloads/$(NEWLIB_ARCHIVE)
472
 
473
 
4 jasmin 474
################ BINUTILS ################
475
 
7 jasmin 476
.PHONY: download-binutils download-binutils-force
477
download-binutils: downloads/$(BINUTILS_ARCHIVE)
478
download-binutils-force downloads/$(BINUTILS_ARCHIVE):
4 jasmin 479
	[ -d downloads ] || mkdir downloads ;
480
	cd downloads && curl -LO $(BINUTILS_URL)
481
 
7 jasmin 482
.PHONY: extract-binutils extract-binutils-force
483
extract-binutils: stamps/extract-binutils
484
extract-binutils-force stamps/extract-binutils: downloads/$(BINUTILS_ARCHIVE)
4 jasmin 485
	@(t1=`openssl md5 $< | cut -f 2 -d " " -` && \
486
	[ "$$t1" = "$(BINUTILS_MD5)" ] || \
487
	( echo "Bad Checksum! Please remove the following file and retry: $<" && false ))
488
	tar -jxf $< ;
489
	[ -d stamps ] || mkdir stamps ;
490
	touch stamps/extract-binutils;
491
 
7 jasmin 492
.PHONY: patch-binutils patch-binutils-force
493
patch-binutils: stamps/patch-binutils
494
patch-binutils-force stamps/patch-binutils: stamps/extract-binutils stamps/extract-avr32patches
4 jasmin 495
	pushd binutils-$(BINUTILS_VERSION) ; \
496
	for f in ../source/avr32/binutils/*.patch; do \
497
	patch -N -p0 <$${f} ; \
498
	done ; \
499
	popd ; \
500
	[ -d stamps ] || mkdir stamps
501
	touch stamps/patch-binutils;
502
 
7 jasmin 503
.PHONY: regen-binutils regen-binutils-force
504
regen-binutils: stamps/regen-binutils
505
regen-binutils-force stamps/regen-binutils: stamps/patch-binutils stamps/install-supp-tools
4 jasmin 506
	pushd binutils-$(BINUTILS_VERSION) ; \
507
	"$(SUPP_PREFIX)/bin/aclocal" -I config ; \
508
	"$(SUPP_PREFIX)/bin/autoconf" ; \
509
	"$(SUPP_PREFIX)/bin/automake" ; \
510
	"$(SUPP_PREFIX)/bin/autoheader" ; \
511
	for dir in bfd opcodes binutils gas ld; do \
512
	  pushd $$dir ; \
513
	  "$(SUPP_PREFIX)/bin/autoconf"; \
514
	  "$(SUPP_PREFIX)/bin/automake"; \
515
	  "$(SUPP_PREFIX)/bin/autoheader"; \
516
	  popd ; \
517
	done; \
518
	popd; \
519
	[ -d stamps ] || mkdir stamps ;
520
	touch stamps/regen-binutils;
521
 
7 jasmin 522
.PHONY: build-binutils build-binutils-force
523
build-binutils: stamps/build-binutils
524
build-binutils-force stamps/build-binutils: stamps/regen-binutils stamps/install-supp-tools
4 jasmin 525
	cd binutils-$(BINUTILS_VERSION) ; \
526
	./configure   --enable-maintainer-mode		\
527
	--prefix="$(PREFIX)" --target=$(TARGET) --disable-nls		\
528
	--disable-shared --disable-werror				\
529
	--with-sysroot="$(PREFIX)/$(TARGET)" --with-bugurl=$(BUG_URL) &&	\
530
	$(MAKE) all-bfd TARGET-bfd=headers; \
531
	rm bfd/Makefile; \
532
	make configure-bfd; \
533
	$(MAKE)
534
	[ -d stamps ] || mkdir stamps ;
535
	touch stamps/build-binutils;
536
 
7 jasmin 537
.PHONY: install-binutils install-binutils-force
538
install-binutils: stamps/install-binutils
539
install-binutils-force stamps/install-binutils: stamps/build-binutils
4 jasmin 540
	cd binutils-$(BINUTILS_VERSION) && \
541
	$(MAKE) installdirs install-host install-target
542
	[ -d stamps ] || mkdir stamps ;
543
	touch stamps/install-binutils;
544
 
7 jasmin 545
 
546
.PHONY: clean-binutils
547
clean-binutils:
548
	rm -rf build/binutils stamps/*-binutils binutils-*
549
 
550
.PHONY: realclean-binutils
551
realclean-binutils: clean-binutils
552
	rm downloads/$(BINUTILS_ARCHIVE)
553
 
554
 
4 jasmin 555
########## DFU PROGRAMMER ###########
556
 
7 jasmin 557
.PHONY: download-dfu download-dfu-force
558
download-dfu: downloads/$(DFU_ARCHIVE)
559
download-dfu-force downloads/$(DFU_ARCHIVE):
4 jasmin 560
	[ -d downloads ] || mkdir downloads ;
561
	cd downloads && curl -LO $(DFU_URL)
562
 
7 jasmin 563
.PHONY: extract-dfu extract-dfu-force
564
extract-dfu: stamps/extract-dfu
565
extract-dfu-force stamps/extract-dfu: downloads/$(DFU_ARCHIVE)
4 jasmin 566
	@(t1=`openssl md5 $< | cut -f 2 -d " " -` && \
567
	[ "$$t1" = "$(DFU_MD5)" ] || \
568
	( echo "Bad Checksum! Please remove the following file and retry: $<" && false ))
569
	tar -zxf $< ;
570
	[ -d stamps ] || mkdir stamps ;
571
	touch stamps/extract-dfu;
572
 
7 jasmin 573
.PHONY: build-dfu build-dfu-force
574
build-dfu: stamps/build-dfu
575
build-dfu-force stamps/build-dfu: stamps/extract-dfu
4 jasmin 576
	mkdir -p build/dfu-programmer && cd build/dfu-programmer && \
577
	../../dfu-programmer-$(DFU_VERSION)/configure --prefix="$(PREFIX)" && \
578
	$(MAKE) -j$(PROCS)
579
	[ -d stamps ] || mkdir stamps
580
	touch stamps/build-dfu;
581
 
7 jasmin 582
.PHONY: install-dfu install-dfu-force
583
install-dfu: stamps/install-dfu
584
install-dfu-force stamps/install-dfu: stamps/build-dfu
4 jasmin 585
	cd build/dfu-programmer && \
586
	$(MAKE) install
587
	[ -d stamps ] || mkdir stamps
588
	touch stamps/install-dfu;
589
 
7 jasmin 590
.PHONY: clean-dfu
591
clean-dfu:
592
	rm -rf build/dfu stamps/*-dfu dfu-*
4 jasmin 593
 
7 jasmin 594
.PHONY: realclean-dfu
595
realclean-dfu: clean-dfu
596
	rm downloads/$(DFU_ARCHIVE)
597
 
598
 
4 jasmin 599
################ Bootstrap GCC ################
600
 
7 jasmin 601
.PHONY: download-gcc download-gcc-force
602
download-gcc: downloads/$(GCC_ARCHIVE)
603
download-gcc-force downloads/$(GCC_ARCHIVE):
4 jasmin 604
	[ -d downloads ] || mkdir downloads ;
605
	cd downloads && curl -LO $(GCC_URL)
606
 
7 jasmin 607
.PHONY: extract-gcc extract-gcc-force
608
extract-gcc: stamps/extract-gcc
609
extract-gcc-force stamps/extract-gcc: downloads/$(GCC_ARCHIVE)
4 jasmin 610
	@(t1=`openssl md5 $< | cut -f 2 -d " " -` && \
611
	[ "$$t1" = "$(GCC_MD5)" ] || \
612
	( echo "Bad Checksum! Please remove the following file and retry: $<" && false ))
613
	tar -jxf $< ;
614
	[ -d stamps ] || mkdir stamps ;
615
	touch stamps/extract-gcc;
616
 
7 jasmin 617
.PHONY: patch-gcc patch-gcc-force
618
patch-gcc: stamps/patch-gcc
619
patch-gcc-force stamps/patch-gcc: stamps/extract-gcc stamps/extract-avr32patches
4 jasmin 620
	pushd gcc-$(GCC_VERSION) ; \
621
	for f in ../source/avr32/gcc/*.patch; do \
622
	patch -N -p0 <$${f} ; \
623
	done ; \
624
	popd ;
625
	[ -d stamps ] || mkdir stamps
626
	touch stamps/patch-gcc;
627
 
628
CFLAGS_FOR_TARGET="-ffunction-sections -fdata-sections			\
629
-fomit-frame-pointer -DPREFER_SIZE_OVER_SPEED -D__OPTIMIZE_SIZE__ -g	\
630
-Os -fno-unroll-loops"
631
 
7 jasmin 632
.PHONY: build-gcc build-gcc-force
633
build-gcc: stamps/build-gcc
634
build-gcc-force stamps/build-gcc: stamps/install-binutils stamps/patch-gcc
4 jasmin 635
	mkdir -p build/gcc && cd build/gcc && \
636
	pushd ../../gcc-$(GCC_VERSION) ; \
637
	make clean ; \
638
	popd ; \
639
	../../gcc-$(GCC_VERSION)/configure --prefix="$(PREFIX)"		\
640
	--target=$(TARGET) --enable-languages="c" --with-gnu-ld		\
641
	--with-gnu-as --with-newlib --disable-nls --disable-libssp	\
642
	--with-dwarf2 --enable-sjlj-exceptions				\
643
	--enable-version-specific-runtime-libs --disable-libstdcxx-pch	\
644
	--disable-shared						\
645
	--with-build-time-tools="$(PREFIX)/$(TARGET)/bin"		\
646
	--enable-cxx-flags=$(CFLAGS_FOR_TARGET)				\
647
	--with-sysroot="$(PREFIX)/$(TARGET)"				\
648
	--with-build-sysroot="$(PREFIX)/$(TARGET)"			\
649
	--with-build-time-tools="$(PREFIX)/$(TARGET)/bin"		\
650
	CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET)				\
651
	LDFLAGS_FOR_TARGET="--sysroot=\"$(PREFIX)/$(TARGET)\""		\
652
	CPPFLAGS_FOR_TARGET="--sysroot=\"$(PREFIX)/$(TARGET)\""		\
653
	--with-bugurl=$(BUG_URL) \
654
	--with-pkgversion=$(PKG_VERSION) && \
655
	$(MAKE) -j$(PROCS)
656
	[ -d stamps ] || mkdir stamps
657
	touch stamps/build-gcc;
658
 
7 jasmin 659
.PHONY: install-gcc install-gcc-force
660
install-gcc: stamps/install-gcc
661
install-gcc-force stamps/install-gcc: stamps/build-gcc
4 jasmin 662
	cd build/gcc && \
663
	$(MAKE) installdirs install-target && \
664
	$(MAKE) -C gcc install-common install-cpp install- install-driver install-headers install-man
665
	[ -d stamps ] || mkdir stamps
666
	touch stamps/install-gcc;
667
 
7 jasmin 668
.PHONY: clean-gcc
669
clean-gcc:
670
	rm -rf build/gcc stamps/*-gcc gcc-*
4 jasmin 671
 
7 jasmin 672
.PHONY: realclean-gcc
673
realclean-gcc: clean-gcc
674
	rm downloads/$(GCC_ARCHIVE)
675
 
676
 
4 jasmin 677
################ Final GCC ################
678
 
7 jasmin 679
.PHONY: build-final-gcc build-final-gcc-force
680
build-final-gcc: stamps/build-final-gcc
681
build-final-gcc-force stamps/build-final-gcc: stamps/install-binutils stamps/install-gcc stamps/install-newlib stamps/patch-gcc
4 jasmin 682
	mkdir -p build/final-gcc && cd build/final-gcc && \
683
	pushd ../../gcc-$(GCC_VERSION) ; \
684
	make clean ; \
685
	popd ; \
686
	../../gcc-$(GCC_VERSION)/configure --prefix=$(PREFIX) \
687
	--target=$(TARGET) $(DEPENDENCIES) --enable-languages="c,c++" --with-gnu-ld \
688
	--with-gnu-as --with-newlib --disable-nls --disable-libssp \
689
	--with-dwarf2 --enable-sjlj-exceptions \
690
	--enable-version-specific-runtime-libs --disable-libstdcxx-pch \
691
	--disable-shared --enable-__cxa_atexit \
692
	--with-build-time-tools=$(PREFIX)/$(TARGET)/bin \
693
	--enable-cxx-flags=$(CFLAGS_FOR_TARGET) \
694
	--with-sysroot=$(PREFIX)/$(TARGET) \
695
	--with-build-sysroot=$(PREFIX)/$(TARGET) \
696
	--with-build-time-tools=$(PREFIX)/$(TARGET)/bin \
697
	CFLAGS_FOR_TARGET=$(CFLAGS_FOR_TARGET) \
698
	LDFLAGS_FOR_TARGET="--sysroot=$(PREFIX)/$(TARGET)" \
699
	CPPFLAGS_FOR_TARGET="--sysroot=$(PREFIX)/$(TARGET)" \
700
	--with-bugurl=$(BUG_URL) \
701
	--with-pkgversion=$(PKG_VERSION) && \
702
	$(MAKE) -j$(PROCS)
703
	[ -d stamps ] || mkdir stamps
704
	touch stamps/build-final-gcc;
705
 
7 jasmin 706
.PHONY: install-final-gcc install-final-gcc-force
707
install-final-gcc: stamps/install-final-gcc
708
install-final-gcc-force stamps/install-final-gcc: stamps/build-final-gcc
4 jasmin 709
	cd build/final-gcc && \
710
	$(MAKE) installdirs install-target && \
711
	$(MAKE) -C gcc install-common install-cpp install- install-driver install-headers install-man
712
	[ -d stamps ] || mkdir stamps
713
	touch stamps/install-final-gcc;
714
 
7 jasmin 715
.PHONY: clean-final-gcc
716
clean-final-gcc: clean-gcc
717
	rm -rf build/final-gcc stamps/*-final-gcc
4 jasmin 718
 
7 jasmin 719
.PHONY: realclean-final-gcc
720
realclean-final-gcc: realclean-gcc
721
 
722
 
723
########## GDB ###########
724
 
725
.PHONY: download-gdb download-gdb-force
726
download-gdb: downloads/$(GDB_ARCHIVE)
727
download-gdb-force downloads/$(GDB_ARCHIVE):
728
	[ -d downloads ] || mkdir downloads ;
729
	cd downloads && curl -LO $(GDB_URL)
730
 
731
.PHONY: extract-gdb extract-gdb-force
732
extract-gdb: stamps/extract-gdb
733
extract-gdb-force stamps/extract-gdb: downloads/$(GDB_ARCHIVE)
734
	@(t1=`openssl md5 $< | cut -f 2 -d " " -` && \
735
	[ "$$t1" = "$(GDB_MD5)" ] || \
736
	( echo "Bad Checksum! Please remove the following file and retry: $<" && false ))
737
	tar -jxf $< ;
738
	[ -d stamps ] || mkdir stamps ;
739
	touch stamps/extract-gdb;
740
 
741
.PHONY: patch-gdb patch-gdb-force
742
patch-gdb: stamps/patch-gdb
743
patch-gdb-force stamps/patch-gdb: stamps/extract-gdb stamps/extract-avr32patches
744
	pushd gdb-$(GDB_VERSION) ; \
745
	for f in ../source/avr32/gdb/*.patch; do \
746
	patch -N -p0 <$${f} ; \
747
	done ; \
748
	popd ; \
749
	[ -d stamps ] || mkdir stamps
750
	touch stamps/patch-gdb;
751
 
752
.PHONY: regen-gdb regen-gdb-force
753
regen-gdb: stamps/regen-gdb
754
regen-gdb-force stamps/regen-gdb: stamps/patch-gdb stamps/install-supp-tools
755
	pushd gdb-$(GDB_VERSION) ; \
756
	"$(SUPP_PREFIX)/bin/aclocal" -I config ; \
757
	"$(SUPP_PREFIX)/bin/autoconf" ; \
758
	"$(SUPP_PREFIX)/bin/automake" ; \
759
	"$(SUPP_PREFIX)/bin/autoheader" ; \
760
	for dir in bfd opcodes gdb; do \
761
	  pushd $$dir ; \
762
	  echo "JESS 1: $$dir" >&2 ; \
763
	  "$(SUPP_PREFIX)/bin/autoconf"; \
764
	  "$(SUPP_PREFIX)/bin/automake"; \
765
	  "$(SUPP_PREFIX)/bin/autoheader"; \
766
	  echo "JESS 2: $$dir" >&2 ; \
767
	  popd ; \
768
	done; \
769
	popd; \
770
	[ -d stamps ] || mkdir stamps ;
771
	touch stamps/regen-gdb;
772
 
773
.PHONY: build-gdb build-gdb-force
774
build-gdb: stamps/build-gdb
775
build-gdb-force stamps/build-gdb: stamps/regen-gdb stamps/install-supp-tools
776
	echo "JESS 3" >&2 ; \
777
	mkdir -p build/gdb && cd build/gdb && \
778
	../../gdb-$(GDB_VERSION)/configure --prefix="$(PREFIX)" --target=$(TARGET) --disable-werror && \
779
	$(MAKE) -j$(PROCS)
780
	$(MAKE) installdirs install-host install-target
781
	[ -d stamps ] || mkdir stamps
782
	touch stamps/build-gdb;
783
 
784
.PHONY: install-gdb install-gdb-force
785
install-gdb: stamps/install-gdb
786
install-gdb-force stamps/install-gdb: stamps/build-gdb
787
	cd build/gdb && \
788
	$(MAKE) install
789
	[ -d stamps ] || mkdir stamps
790
	touch stamps/install-gdb;
791
 
792
.PHONY: clean-gdb
793
clean-gdb:
794
	rm -rf build/gdb stamps/*-gdb gdb-*
795
 
796
.PHONY: realclean-gdb
797
realclean-gdb: clean-gdb
798
	rm downloads/$(GDB_ARCHIVE)
799
 
4 jasmin 800
################ NON-WORKING/NON-ADJUSTED TARGETS ################
801
 
802
 
803
gcc-optsize-patch: gcc-$(GCC_VERSION)-$(CS_BASE)/
804
	pushd gcc-$(GCC_VERSION)-$(CS_BASE) ; \
805
	patch -N -p1 < ../patches/gcc-optsize.patch ; \
806
	popd ;
807
 
808
gmp: gmp-$(CS_BASE)/ sudomode
809
	sudo -u $(SUDO_USER) mkdir -p build/gmp && cd build/gmp ; \
810
	pushd ../../gmp-$(CS_BASE) ; \
811
	make clean ; \
812
	popd ; \
813
	sudo -u $(SUDO_USER) ../../gmp-$(CS_BASE)/configure --disable-shared && \
814
	sudo -u $(SUDO_USER) $(MAKE) -j$(PROCS) all && \
815
	$(MAKE) install
816
 
817
mpc: mpc-$(MPC_VERSION)/ sudomode
818
	sudo -u $(SUDO_USER) mkdir -p build/gmp && cd build/gmp ; \
819
	pushd ../../mpc-$(MPC_VERSION) ; \
820
	make clean ; \
821
	popd ; \
822
	sudo -u $(SUDO_USER) ../../mpc-$(MPC_VERSION)/configure --disable-shared && \
823
	sudo -u $(SUDO_USER) $(MAKE) -j$(PROCS) all && \
824
	$(MAKE) install
825
 
826
mpc-$(MPC_VERSION) : $(LOCAL_BASE)/mpc-$(CS_VERSION).tar.bz2
827
ifeq ($(USER),root)
828
	sudo -u $(SUDO_USER) tar -jxf $<
829
else
830
	tar -jxf $<
831
endif
832
 
833
mpfr: gmp mpfr-$(CS_BASE)/ sudomode
834
	sudo -u $(SUDO_USER) mkdir -p build/mpfr && cd build/mpfr && \
835
	pushd ../../mpfr-$(CS_BASE) ; \
836
	make clean ; \
837
	popd ; \
838
	sudo -u $(SUDO_USER) ../../mpfr-$(CS_BASE)/configure LDFLAGS="-Wl,-search_paths_first" --disable-shared && \
839
	sudo -u $(SUDO_USER) $(MAKE) -j$(PROCS) all && \
840
	$(MAKE) install
841
 
842
cross-gdb: gdb-$(CS_BASE)/
843
	mkdir -p build/gdb && cd build/gdb && \
844
	pushd ../../gdb-$(CS_BASE) ; \
845
	make clean ; \
846
	popd ; \
847
	../../gdb-$(CS_BASE)/configure --prefix="$(PREFIX)" --target=$(TARGET) --disable-werror && \
848
	$(MAKE) -j$(PROCS) && \
849
	$(MAKE) installdirs install-host install-target && \
850
	mkdir -p "$(PREFIX)/man/man1" && \
851
	cp ../../gdb-$(CS_BASE)/gdb/gdb.1 "$(PREFIX)/man/man1/arm-none-eabi-gdb.1"
852
 
853
.PHONY : clean
854
clean:
855
	rm -rf build *-$(CS_BASE) binutils-* gcc-* gdb-* newlib-* mpc-* $(LOCAL_BASE) dfu-programmer-* autoconf-* automake-* stamps/* source supp