|
| 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 | + if [ ! -d temp/${x} ]; then |
| 57 | + cd temp |
| 58 | + LOCATION=`find . | grep ${x}` |
| 59 | + cd .. |
| 60 | + else |
| 61 | + LOCATION=${x} |
| 62 | + fi |
| 63 | + cp -r temp/${LOCATION} ../objdir/avr/lib/${LOCATION} |
| 64 | +done |
| 65 | + |
| 66 | +# 4 - extract the correct includes and add them to io.h |
| 67 | +# ARGH! difficult! |
| 68 | +for x in $ALL_DEVICE_SPECS; do |
| 69 | + DEFINITION=`cat ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/${x} | grep __AVR_DEVICE_NAME__ | cut -f1 -d" " | cut -f2 -d"D"` |
| 70 | + FANCY_NAME=`cat ../objdir/lib/gcc/avr/${GCC_VERSION}/device-specs/${x} | grep __AVR_DEVICE_NAME__ | cut -f2 -d"="` |
| 71 | + LOWERCASE_DEFINITION="${DEFINITION,,}" |
| 72 | + HEADER_TEMP="${LOWERCASE_DEFINITION#__avr_atmega}" |
| 73 | + HEADER="${HEADER_TEMP%__}" |
| 74 | + _DEFINITION="#elif defined (${DEFINITION})" |
| 75 | + _HEADER="# include <avr/iom${HEADER}.h>" |
| 76 | + if [ "$(grep -c "${DEFINITION}" ../objdir/avr/include/avr/io.h)" == 0 ]; then |
| 77 | + 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"` |
| 78 | + echo "$NEWFILE" > ../objdir/avr/include/avr/io.h |
| 79 | + fi |
| 80 | +done |
| 81 | + |
| 82 | +#NEW_ALL_FILES=`find ../objdir` |
| 83 | + |
| 84 | +#echo "NEW FILES ADDED: " |
| 85 | +#diff <(echo "$ALL_FILES" ) <(echo "$NEW_ALL_FILES") |
| 86 | + |
| 87 | +cd .. |
| 88 | + |
0 commit comments