Skip to content

Commit f9bd9e2

Browse files
committed
Automatically apply patches from atpack file (if present)
1 parent 1a6e09b commit f9bd9e2

File tree

3 files changed

+94
-0
lines changed

3 files changed

+94
-0
lines changed

atpack.build.bash

Lines changed: 84 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
#!/bin/bash -ex
2+
# Copyright (c) 2017 Arduino LLC
3+
#
4+
# This program is free software; you can redistribute it and/or
5+
# modify it under the terms of the GNU General Public License
6+
# as published by the Free Software Foundation; either version 2
7+
# of the License, or (at your option) any later version.
8+
#
9+
# This program is distributed in the hope that it will be useful,
10+
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11+
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12+
# GNU General Public License for more details.
13+
#
14+
# You should have received a copy of the GNU General Public License
15+
# along with this program; if not, write to the Free Software
16+
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17+
18+
source build.conf
19+
20+
mkdir -p atpack
21+
cd atpack
22+
rm -rf *
23+
mv ../*.atpack .
24+
25+
mv ${ATMEL_ATMEGA_PACK_FILENAME}.atpack ${ATMEL_ATMEGA_PACK_FILENAME}.zip
26+
unzip ${ATMEL_ATMEGA_PACK_FILENAME}.zip
27+
28+
ALL_FILES=`find ../objdir`
29+
30+
#copy relevant files to the right folders
31+
# 1- copy includes definitions
32+
EXTRA_INCLUDES=`diff -q ../objdir/avr/include/avr ../atpack/include/avr | grep "Only in" | grep atpack | cut -f4 -d" "`
33+
for x in $EXTRA_INCLUDES; do
34+
cp include/avr/${x} ../objdir/avr/include/avr
35+
done
36+
37+
# 2 - compact specs into a single folder
38+
SPECS_FOLDERS=`ls gcc/dev`
39+
mkdir temp
40+
for folder in $SPECS_FOLDERS; do
41+
cp -r gcc/dev/${folder}/* temp/
42+
done
43+
44+
# 3 - find different files (device-specs)
45+
EXTRA_SPECS=`diff -q ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/ temp/device-specs | grep "Only in" | grep temp | cut -f4 -d" "`
46+
for x in $EXTRA_SPECS; do
47+
cp temp/device-specs/${x} ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/
48+
done
49+
50+
#since https://github.com/gcc-mirror/gcc/commit/21a6b87b86defda10ac903a9cd49e34b1f8ce6fb a lot of devices has specs but avr-libc doesn't support them yet
51+
ALL_DEVICE_SPECS=`ls temp/device-specs`
52+
rm -rf temp/device-specs
53+
54+
EXTRA_LIBS=`diff -r -q ../objdir/avr/lib temp/ | grep "Only in" | grep temp | cut -f4 -d" "`
55+
for x in $EXTRA_LIBS; do
56+
cd temp
57+
LOCATION=`find . | grep ${x}`
58+
cd ..
59+
cp -r temp/${LOCATION} ../objdir/avr/lib/${LOCATION}
60+
done
61+
62+
# 4 - extract the correct includes and add them to io.h
63+
# ARGH! difficult!
64+
for x in $ALL_DEVICE_SPECS; do
65+
DEFINITION=`cat ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/${x} | grep __AVR_DEVICE_NAME__ | cut -f1 -d" " | cut -f2 -d"D"`
66+
FANCY_NAME=`cat ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/${x} | grep __AVR_DEVICE_NAME__ | cut -f2 -d"="`
67+
LOWERCASE_DEFINITION="${DEFINITION,,}"
68+
HEADER_TEMP="${LOWERCASE_DEFINITION#__avr_atmega}"
69+
HEADER="${HEADER_TEMP%__}"
70+
_DEFINITION="#elif defined (${DEFINITION})"
71+
_HEADER="# include <avr/iom${HEADER}.h>"
72+
if [ "$(grep -c "${DEFINITION}" ../objdir/avr/include/avr/io.h)" == 0 ]; then
73+
NEWFILE=`awk '/iom3000.h/ { print; print "____DEFINITION____"; print "____HEADER____"; next }1' ../objdir/avr/include/avr/io.h | sed "s/____DEFINITION____/$_DEFINITION/g" | sed "s@____HEADER____@$_HEADER@g"`
74+
echo "$NEWFILE" > ../objdir/avr/include/avr/io.h
75+
fi
76+
done
77+
78+
NEW_ALL_FILES=`find ../objdir`
79+
80+
echo "NEW FILES ADDED: "
81+
diff <(echo "$ALL_FILES" ) <(echo "$NEW_ALL_FILES")
82+
83+
cd ..
84+

build.conf

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ AVR_VERSION=3.6.0
22
BUILD_NUMBER=arduino
33

44
AVR_SOURCES="http://distribute.atmel.no/tools/opensource/Atmel-AVR-GNU-Toolchain/${AVR_VERSION}"
5+
ATMEL_PACKS_SOURCES="http://packs.download.atmel.com/"
56
GNU_SOURCES="http://mirror.switch.ch/ftp/mirror/gnu"
67
MPC_SOURCES="http://www.multiprecision.org/mpc/download"
78

@@ -15,6 +16,10 @@ MPC_SOURCES="http://www.multiprecision.org/mpc/download"
1516
# MPFR_VERSION=3.0.0
1617
# MPC_VERSION=0.9
1718

19+
ATMEL_ATMEGA_PACK_VERSION=1.2.132
20+
ATMEL_ATMEGA_PACK_FILENAME=Atmel.ATmega_DFP.${ATMEL_ATMEGA_PACK_VERSION}
21+
ATMEL_ATMEGA_PACK_URL=${ATMEL_PACKS_SOURCES}/${ATMEL_ATMEGA_PACK_FILENAME}.atpack
22+
1823
# With any luck, you don't need to edit the below
1924
################################################################################
2025

package-avr-gcc.bash

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,11 @@ rm -rf toolsdir objdir *-build
8181

8282
rm -rf objdir/{info,man,share}
8383

84+
if [[ -f ${ATMEL_ATMEGA_PACK_FILENAME}.atpack ]] ; then
85+
#add extra files from atpack (only if the package is altrady there)
86+
./atpack.build.bash
87+
fi
88+
8489
# if producing a windows build, compress as zip and
8590
# copy *toolchain-precompiled* content to any folder containing a .exe
8691
if [[ ${OUTPUT_TAG} == *"mingw"* ]] ; then

0 commit comments

Comments
 (0)