Skip to content

Commit fd9406d

Browse files
Refactor and add other support tools
1 parent 74a4bee commit fd9406d

File tree

3 files changed

+117
-47
lines changed

3 files changed

+117
-47
lines changed

build

Lines changed: 74 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,12 @@ lto=${lto:-false}
2323
# Default to linux building if nothing else set
2424
host=${host:-linux}
2525
EXE=""
26+
MKSPIFFSTGT="linux"
2627
case "$host" in
2728
linux) HOST="x86_64-linux-gnu"; AHOST="x86_64-pc-linux-gnu"; EXT=".x86_64";;
28-
win32) HOST="i686-w64-mingw32"; AHOST="i686-mingw32"; EXT=".win32"; EXE=".exe";;
29-
win64) HOST="x86_64-w64-mingw32"; AHOST="x86_64-mingw32"; EXT=".win64"; EXE=".exe";;
30-
osx) HOST="x86_64-apple-darwin14"; AHOST="x86_64-apple-darwin"; EXT=".osx";;
29+
win32) HOST="i686-w64-mingw32"; AHOST="i686-mingw32"; EXT=".win32"; EXE=".exe"; MKSPIFFSTGT='windows';;
30+
win64) HOST="x86_64-w64-mingw32"; AHOST="x86_64-mingw32"; EXT=".win64"; EXE=".exe"; MKSPIFFSTGT='windows';;
31+
osx) HOST="x86_64-apple-darwin14"; AHOST="x86_64-apple-darwin"; EXT=".osx"; MKSPIFFSTGT='osx';;
3132
arm64) HOST="aarch64-linux-gnu"; AHOST="aarch64-linux-gnu"; EXT=".arm64";;
3233
rpi) HOST="arm-linux-gnueabihf"; AHOST="arm-linux-gnueabihf"; EXT=".rpi";;
3334
*) echo "Specify host as linux, win32, win64, osx, arm64, or rpi"; exit 2;;
@@ -49,8 +50,51 @@ clean()
4950
cleangit gcc-xtensa
5051
cleangit newlib-xtensa
5152
cleangit lx106-hal
53+
cleangit mkspiffs
54+
cleangit esptool
5255
}
5356

57+
distclean()
58+
{
59+
clean
60+
rm -rf *.json *.tar.gz *.zip xtensa-lx106-elf.*
61+
}
62+
63+
maketool()
64+
{
65+
if [ ! -r arena/jobdone-${tool} ]; then
66+
echo "-------- ${tool}"
67+
( rm -rf arena/${tool};
68+
cp -a dl/${tool} arena/${tool};
69+
pushd arena/${tool};
70+
TARGET_OS=${MKSPIFFSTGT} CC=${HOST}-gcc CXX=${HOST}-g++ STRIP=${HOST}-strip \
71+
make clean ${tool}${EXE} BUILD_CONFIG_NAME="-arduino-esp8266" ${extra_opts};
72+
popd;
73+
mkdir -p ${install}/${tool};
74+
cp -a arena/${tool}/${tool}${EXE} ${install}/${tool}/.;
75+
pushd arena/${tool} && name=${tool}-$(git rev-parse --short HEAD) && popd;
76+
pushd ${install};
77+
tarball=${HOST}-$name.${tarext};
78+
${tarcmd} ${taropts} ../${tarball} ${tool};
79+
popd;
80+
makejson;
81+
touch arena/jobdone-${tool};
82+
) >& $log.${tool}.log
83+
fi
84+
}
85+
86+
makejson()
87+
{
88+
tarballsize=$(stat -c%s ${tarball})
89+
tarballsha256=$(sha256sum ${tarball} | cut -f1 -d" ")
90+
( echo '{' &&
91+
echo ' "host": "'$AHOST'",' &&
92+
echo ' "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/'${rel}-${subrel}'/'${tarball}'",' &&
93+
echo ' "archiveFileName": "'${tarball}'",' &&
94+
echo ' "checksum": "SHA-256:'${tarballsha256}'",' &&
95+
echo ' "size": "'${tarballsize}'"' &&
96+
echo '}') > ${tarball}.json
97+
}
5498

5599
install()
56100
{
@@ -80,27 +124,9 @@ install()
80124
git=$(git rev-parse --short HEAD)
81125
ver=${rel}-${git}-${subrel}
82126
pkgfile=${arduino}/package/package_esp8266com_index.template.json
83-
(cat <<EOF
84-
import glob
85-
import json
86-
import os
87-
with open("$pkgfile") as f:
88-
data = json.load(f)
89-
for i in range(0, len(data["packages"][0]["platforms"][0]["toolsDependencies"])):
90-
if data["packages"][0]["platforms"][0]["toolsDependencies"][i]["name"] == "xtensa-lx106-elf-gcc":
91-
data["packages"][0]["platforms"][0]["toolsDependencies"][i]["version"] = "$ver"
92-
for i in range(0, len(data["packages"][0]["tools"])):
93-
if data["packages"][0]["tools"][i]["name"] == "xtensa-lx106-elf-gcc":
94-
data["packages"][0]["tools"][i]["version"] = "$ver"
95-
data["packages"][0]["tools"][i]["systems"] = []
96-
for j in glob.glob("*xtensa-lx106-elf*"+"$git"+"*json"):
97-
with open(j) as s:
98-
part = json.load(s)
99-
data["packages"][0]["tools"][i]["systems"].append(part)
100-
print json.dumps(data, indent=3, separators=(',',': '))
101-
EOF
102-
) | python > $pkgfile.new
103-
mv -f ${pkgfile}.new ${pkgfile}
127+
./patch_json.py --pkgfile "${pkgfile}" --tool xtensa-lx106-elf-gcc --ver "${ver}" --glob '*xtensa-lx106-elf*.json'
128+
./patch_json.py --pkgfile "${pkgfile}" --tool esptool --ver "${ver}" --glob '*esptool*json'
129+
./patch_json.py --pkgfile "${pkgfile}" --tool mkspiffs --ver "${ver}" --glob '*mkspiffs*json'
104130
echo "Install done"
105131
}
106132

@@ -141,6 +167,17 @@ configurenewlibinstall+=${configurenewlibcom}
141167
configurenewlib="--prefix=${install}"
142168
configurenewlib+=${configurenewlibcom}
143169

170+
171+
if [ "${EXE}" == "" ]; then
172+
tarext="tar.gz"
173+
tarcmd="tar"
174+
taropts="zcf"
175+
else
176+
tarext="zip"
177+
tarcmd="zip"
178+
taropts="-rq"
179+
fi
180+
144181
if $lto; then
145182
export CFLAGS_FOR_TARGET='-mlongcalls -flto -Wl,-flto -Os -g'
146183
export CXXFLAGS_FOR_TARGET='-mlongcalls -flto -Wl,-flto -Os -g'
@@ -157,9 +194,10 @@ export LD_LIBRARY_PATH="${installnative}/lib"
157194

158195
case "$1" in
159196
clean) clean; exit 0;;
197+
distclean) distclean; exit 0;;
160198
build) :;;
161199
install) install; exit 0;;
162-
*) echo "need 'clean', 'build', or 'install'"; exit 1;;
200+
*) echo "need 'clean', 'distclean', 'build', or 'install'"; exit 1;;
163201
esac
164202

165203

@@ -185,10 +223,13 @@ if [ ! -r arena/downloaded ]; then
185223
test -d binutils-gdb-xtensa || git clone ${gitopt} https://github.com/earlephilhower/binutils-gdb-xtensa.git
186224
test -d gcc-xtensa || git clone https://github.com/earlephilhower/gcc-xtensa.git
187225
test -d newlib-xtensa || git clone ${gitopt} https://github.com/earlephilhower/newlib-xtensa.git
188-
test -d lx106-hal || git clone ${gitopt} https://github.com/earlephilhower/lx106-hal.git
226+
test -d lx106-hal || git clone https://github.com/earlephilhower/lx106-hal.git
227+
test -d mkspiffs || git clone https://github.com/earlephilhower/mkspiffs.git
228+
test -d esptool || git clone https://github.com/earlephilhower/esptool-ck.git esptool
189229
)
190230

191231
( cd dl/gcc-xtensa && git reset --hard && git checkout ${xtensa_branch} )
232+
( cd dl/mkspiffs && git submodule update )
192233

193234
# download and put tools directly in gcc directory
194235
# let gcc's configure deal with them in place
@@ -259,7 +300,6 @@ EOF
259300
touch arena/patched
260301
fi
261302

262-
263303
# configure build install binutils
264304
if [ ! -r arena/binutils/jobdone ]; then
265305
echo "-------- gdb+binutils"
@@ -292,7 +332,6 @@ if [ ! -r arena/gcc/jobdone-newlib ]; then
292332
touch arena/gcc/jobdone-newlib
293333
fi
294334

295-
296335
if [ ! -r arena/gcc/jobdone-stage2 ]; then
297336
echo "-------- gcc-stage2"
298337
# stage 2 (build libstdc++)
@@ -330,23 +369,13 @@ for sh in post/${gcc}*.sh; do
330369
done
331370

332371
echo "-------- creating package tgz"
333-
if [ "$EXE" == ".exe" ]; then
334-
tarball=$HOST.xtensa-lx106-elf-$(git rev-parse --short HEAD).zip
335-
(rm -rf pkg && mkdir pkg && cd pkg && cp -a ../xtensa-lx106-elf${EXT} xtensa-lx106-elf && zip -rq ../${tarball} xtensa-lx106-elf/)
336-
else
337-
tarball=$HOST.xtensa-lx106-elf-$(git rev-parse --short HEAD).tar.gz
338-
(rm -rf pkg && mkdir pkg && cd pkg && cp -a ../xtensa-lx106-elf${EXT} xtensa-lx106-elf && tar zcf ../${tarball} xtensa-lx106-elf/)
339-
fi
340-
tarballsize=$(stat -c%s ${tarball})
341-
tarballsha256=$(sha256sum ${tarball} | cut -f1 -d" ")
342-
( echo ' {' &&
343-
echo ' "host": "'$AHOST'",' &&
344-
echo ' "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/'${rel}-${subrel}'/'${tarball}'",' &&
345-
echo ' "archiveFileName": "'${tarball}'",' &&
346-
echo ' "checksum": "SHA-256:'${tarballsha256}'",' &&
347-
echo ' "size": "'${tarballsize}'"' &&
348-
echo ' }') > ${tarball}.json
349-
rm -rf pkg
372+
tarball=$HOST.xtensa-lx106-elf-$(git rev-parse --short HEAD).${tarext}
373+
(rm -rf pkg && mkdir pkg && cd pkg && cp -a ../xtensa-lx106-elf${EXT} xtensa-lx106-elf && ${tarcmd} ${taropts} ../${tarball} xtensa-lx106-elf/)
374+
makejson
375+
376+
tool=mkspiffs CPPFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0 -DSPIFFS_ALIGNED_OBJECT_INDEX_TABLES=1" maketool
377+
378+
tool=esptool extra_opts='' maketool
350379

351380
echo "all done (${install})"
352381
rm -f ${unfinished}

buildall.sh

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,15 @@
11
#/bin/bash
22

33
gcc=${1:-4.8}
4-
echo Multiarch build for: $gcc
4+
rel=${rel:-2.5.0}
5+
subrel=${subrel:-2}
6+
7+
echo Multiarch build for: ${gcc} ${rel}-${subrel}
58

69
cd /workdir
710

11+
./build distclean
812
for host in linux win64 win32 osx arm64 rpi; do
13+
gcc=$gcc host=$host rel=$rel subrel=$subrel ./build build
914
./build clean
10-
gcc=$gcc host=$host ./build build
1115
done

patch_json.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#!/usr/bin/env python
2+
3+
import argparse
4+
import collections
5+
import glob
6+
import json
7+
import os
8+
9+
parser = argparse.ArgumentParser(description='Patch in a section of the Arduino tools JSON')
10+
parser.add_argument('--pkgfile', help="Arduino JSON file to update", type=str, required=True)
11+
parser.add_argument('--tool', help="Name of tool to update", type=str, required=True)
12+
parser.add_argument('--ver', help="Version of tool to update", type=str, required=True)
13+
parser.add_argument('--glob', help="Glob to match for tool", type=str, required=True)
14+
args = parser.parse_args()
15+
16+
# Load the JSON
17+
with open(args.pkgfile) as f:
18+
data = json.load(f, object_pairs_hook=collections.OrderedDict)
19+
20+
for i in range(0, len(data["packages"][0]["platforms"][0]["toolsDependencies"])):
21+
if data["packages"][0]["platforms"][0]["toolsDependencies"][i]["name"] == args.tool:
22+
data["packages"][0]["platforms"][0]["toolsDependencies"][i]["version"] = args.ver
23+
24+
for i in range(0, len(data["packages"][0]["tools"])):
25+
if data["packages"][0]["tools"][i]["name"] == args.tool:
26+
print "Patching tool: " + args.tool
27+
data["packages"][0]["tools"][i]["version"] = args.ver
28+
data["packages"][0]["tools"][i]["systems"] = []
29+
for j in glob.glob(args.glob):
30+
with open(j) as s:
31+
print "Adding: " + j
32+
part = json.load(s, object_pairs_hook=collections.OrderedDict)
33+
data["packages"][0]["tools"][i]["systems"].append(part)
34+
35+
print "Writing new file " + args.pkgfile
36+
with open(args.pkgfile, "w") as f:
37+
f.write(json.dumps(data, indent=3, separators=(',',': ')))

0 commit comments

Comments
 (0)