Skip to content

Commit 2ef4ca0

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

File tree

3 files changed

+137
-58
lines changed

3 files changed

+137
-58
lines changed

build

Lines changed: 94 additions & 56 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;;
@@ -39,7 +40,7 @@ cleangit ()
3940
echo "cleaning $1"
4041
cd dl/$1
4142
git reset --hard HEAD
42-
git clean -f -d
43+
git clean -f -d >& /dev/null
4344
)}
4445

4546
clean()
@@ -49,8 +50,62 @@ 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+
# Put an artifact in a target dir describing what was built
64+
markrevinfo()
65+
{(
66+
git rev-parse HEAD
67+
git remote -v
68+
uname -a
69+
git diff
70+
)}
71+
72+
73+
maketool()
74+
{
75+
if [ ! -r arena/jobdone-${tool} ]; then
76+
echo "-------- ${tool}"
77+
( rm -rf arena/${tool};
78+
cp -a dl/${tool} arena/${tool};
79+
pushd arena/${tool};
80+
TARGET_OS=${MKSPIFFSTGT} CC=${HOST}-gcc CXX=${HOST}-g++ STRIP=${HOST}-strip \
81+
make clean ${tool}${EXE} BUILD_CONFIG_NAME="-arduino-esp8266" ${extra_opts};
82+
markrevinfo >& build-rev-info
83+
popd;
84+
mkdir -p ${install}/${tool};
85+
cp -a arena/${tool}/${tool}${EXE} arena/${tool}/build-rev-info ${install}/${tool}/.;
86+
pushd arena/${tool} && name=${tool}-$(git rev-parse --short HEAD) && popd;
87+
pushd ${install};
88+
tarball=${HOST}-$name.${tarext};
89+
${tarcmd} ${taropts} ../${tarball} ${tool};
90+
popd;
91+
makejson;
92+
touch arena/jobdone-${tool};
93+
) >& $log.${tool}.log
94+
fi
95+
}
96+
97+
makejson()
98+
{
99+
tarballsize=$(stat -c%s ${tarball})
100+
tarballsha256=$(sha256sum ${tarball} | cut -f1 -d" ")
101+
( echo '{' &&
102+
echo ' "host": "'$AHOST'",' &&
103+
echo ' "url": "https://github.com/earlephilhower/esp-quick-toolchain/releases/download/'${rel}-${subrel}'/'${tarball}'",' &&
104+
echo ' "archiveFileName": "'${tarball}'",' &&
105+
echo ' "checksum": "SHA-256:'${tarballsha256}'",' &&
106+
echo ' "size": "'${tarballsize}'"' &&
107+
echo '}') > ${tarball}.json
108+
}
54109

55110
install()
56111
{
@@ -80,27 +135,9 @@ install()
80135
git=$(git rev-parse --short HEAD)
81136
ver=${rel}-${git}-${subrel}
82137
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}
138+
./patch_json.py --pkgfile "${pkgfile}" --tool xtensa-lx106-elf-gcc --ver "${ver}" --glob '*xtensa-lx106-elf*.json'
139+
./patch_json.py --pkgfile "${pkgfile}" --tool esptool --ver "${ver}" --glob '*esptool*json'
140+
./patch_json.py --pkgfile "${pkgfile}" --tool mkspiffs --ver "${ver}" --glob '*mkspiffs*json'
104141
echo "Install done"
105142
}
106143

@@ -141,6 +178,17 @@ configurenewlibinstall+=${configurenewlibcom}
141178
configurenewlib="--prefix=${install}"
142179
configurenewlib+=${configurenewlibcom}
143180

181+
182+
if [ "${EXE}" == "" ]; then
183+
tarext="tar.gz"
184+
tarcmd="tar"
185+
taropts="zcf"
186+
else
187+
tarext="zip"
188+
tarcmd="zip"
189+
taropts="-rq"
190+
fi
191+
144192
if $lto; then
145193
export CFLAGS_FOR_TARGET='-mlongcalls -flto -Wl,-flto -Os -g'
146194
export CXXFLAGS_FOR_TARGET='-mlongcalls -flto -Wl,-flto -Os -g'
@@ -157,16 +205,14 @@ export LD_LIBRARY_PATH="${installnative}/lib"
157205

158206
case "$1" in
159207
clean) clean; exit 0;;
208+
distclean) distclean; exit 0;;
160209
build) :;;
161210
install) install; exit 0;;
162-
*) echo "need 'clean', 'build', or 'install'"; exit 1;;
211+
*) echo "need 'clean', 'distclean', 'build', or 'install'"; exit 1;;
163212
esac
164213

165-
166-
echo "Building GCC-$gcc"
167-
echo "For architecture: $host"
168-
169-
214+
echo "-----------------------------------------------------------------------------"
215+
echo "Building GCC-${gcc} for architecture ${host} and release ${rel}-${subrel}"
170216

171217
echo "-------- Checking for required tools"
172218
MISS=0
@@ -185,10 +231,13 @@ if [ ! -r arena/downloaded ]; then
185231
test -d binutils-gdb-xtensa || git clone ${gitopt} https://github.com/earlephilhower/binutils-gdb-xtensa.git
186232
test -d gcc-xtensa || git clone https://github.com/earlephilhower/gcc-xtensa.git
187233
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
234+
test -d lx106-hal || git clone https://github.com/earlephilhower/lx106-hal.git
235+
test -d mkspiffs || git clone https://github.com/earlephilhower/mkspiffs.git
236+
test -d esptool || git clone https://github.com/earlephilhower/esptool-ck.git esptool
189237
)
190238

191239
( cd dl/gcc-xtensa && git reset --hard && git checkout ${xtensa_branch} )
240+
( cd dl/mkspiffs && git submodule update )
192241

193242
# download and put tools directly in gcc directory
194243
# let gcc's configure deal with them in place
@@ -226,15 +275,15 @@ if [ ! -r arena/patched ]; then
226275

227276
for p in patches/gcc-*.patch patches/gcc${gcc}/gcc-*.patch; do
228277
test -r "$p" || continue
229-
(cd dl/gcc-xtensa; echo "---- $p:"; patch -p1 < ../../$p)
278+
(cd dl/gcc-xtensa; echo "---- $p:"; patch -s -p1 < ../../$p)
230279
done
231280
for p in patches/bin-*.patch; do
232281
test -r "$p" || continue
233-
(cd dl/binutils-gdb-xtensa; echo "---- $p:"; patch -p1 < ../../$p)
282+
(cd dl/binutils-gdb-xtensa; echo "---- $p:"; patch -s -p1 < ../../$p)
234283
done
235284
for p in patches/lib-*.patch; do
236285
test -r "$p" || continue
237-
(cd dl/newlib-xtensa; echo "---- $p: "; patch -p1 < ../../$p)
286+
(cd dl/newlib-xtensa; echo "---- $p: "; patch -s -p1 < ../../$p)
238287
done
239288

240289
# dirty-force HAL definition to binutils and gcc
@@ -259,7 +308,6 @@ EOF
259308
touch arena/patched
260309
fi
261310

262-
263311
# configure build install binutils
264312
if [ ! -r arena/binutils/jobdone ]; then
265313
echo "-------- gdb+binutils"
@@ -292,7 +340,6 @@ if [ ! -r arena/gcc/jobdone-newlib ]; then
292340
touch arena/gcc/jobdone-newlib
293341
fi
294342

295-
296343
if [ ! -r arena/gcc/jobdone-stage2 ]; then
297344
echo "-------- gcc-stage2"
298345
# stage 2 (build libstdc++)
@@ -324,29 +371,20 @@ fi
324371
echo "-------- Stripping binaries"
325372
(${HOST}-strip ${install}/bin/* ${install}/libexec/gcc/xtensa-lx106-elf/*/c* ${install}/libexec/gcc/xtensa-lx106-elf/*/lto1 || true) >& $log.16.strip.log
326373

327-
echo "-------- applying post"
374+
echo "-------- Applying post"
328375
for sh in post/${gcc}*.sh; do
329376
[ -x "$sh" ] && $sh ${EXT}
330377
done
331378

332-
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
379+
echo "-------- Creating package tgz"
380+
markrevinfo >& build-rev-info
381+
tarball=$HOST.xtensa-lx106-elf-$(git rev-parse --short HEAD).${tarext}
382+
(rm -rf pkg && mkdir pkg && markrevinfo > pkg/build-rev-info && cd pkg && cp -a ../xtensa-lx106-elf${EXT} xtensa-lx106-elf && ${tarcmd} ${taropts} ../${tarball} xtensa-lx106-elf/)
383+
makejson
384+
385+
tool=mkspiffs CPPFLAGS="-DSPIFFS_USE_MAGIC_LENGTH=0 -DSPIFFS_ALIGNED_OBJECT_INDEX_TABLES=1" maketool
386+
387+
tool=esptool extra_opts='' maketool
350388

351389
echo "all done (${install})"
352390
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 + " to ver: " + args.ver
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)