summarylogtreecommitdiffstats
path: root/PKGBUILD
blob: 5ea1496bcb9b1ee5f82bf23370add925f2abea3d (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Maintainer: Manuel Reimer <manuel.reimer@gmx.de>

pkgname=arduino-esp8266-core-git
pkgver=20201205
pkgrel=1
pkgdesc="Arduino ESP8266 core based on esp-quick-toolchain"
arch=('x86_64')
url="https://github.com/earlephilhower/esp-quick-toolchain"
license=('GPL2' 'LGPL2') # and probably others...
depends=('python' 'source-highlight' 'flex' 'libmpc')
makedepends=('git')
options=(!strip !emptydirs !buildflags staticlibs)
conflicts=('arduino-esp8266-core')
provides=('arduino-esp8266-core')
source=("git+https://github.com/earlephilhower/esp-quick-toolchain.git")
md5sums=('SKIP')

pkgver() {
  # Multiple GIT repositories are involved --> no specific pkgver
  date +%Y%m%d
}

prepare() {
  cd "$srcdir/esp-quick-toolchain"

  # Prepare a custom "bin" directory for esp-quick-toolchain which expects
  # a build toolchain with "architecture prefixes" even when not crossbuilding
  mkdir -p "bin"
  ln -sf "/usr/bin/g++" "bin/x86_64-linux-gnu-g++"
  ln -sf "/usr/bin/gcc" "bin/x86_64-linux-gnu-gcc"
  ln -sf "/usr/bin/strip" "bin/x86_64-linux-gnu-strip"

  # Request esp-quick-toolchain to do its downloads
  make GCC=10.2 GHUSER=earlephilhower GHTOKEN=none download
}

build() {
  cd "$srcdir/esp-quick-toolchain"

  # Include our custom "bin" directory into the PATH variable
  export PATH=$PATH:$PWD/bin

  # Cleanup prior building to prevent duplicates on rebuild
  rm -f *.tar.gz *.tar.gz.json

  # Compile toolchain. Clear "LINUX_BFLGS" to allow dynamic linking
  make GCC=10.2 GHUSER=earlephilhower GHTOKEN=none LINUX_BFLGS=" "

  # "make install" does actually compile additional parts of the toolchain
  make GCC=10.2 GHUSER=earlephilhower GHTOKEN=none LINUX_BFLGS=" " install

  # Insert a custom name to distinguish from official builds
  sed -ri "s/^(name=).*/\1Arch Linux ESP8266 Boards/" arduino/platform.txt
}

package() {
  cd "$srcdir/esp-quick-toolchain"

  # Prepare target directory for our system-global Arduino core
  _targetdir="$pkgdir/usr/share/arduino/hardware/archlinux-esp8266/esp8266"
  mkdir -p "$_targetdir"

  # Start off with the Arduino stuff already prepared by "make install"
  cp -r arduino/* "$_targetdir"

  # Some cleanup
  find "$_targetdir" -name '*.o' -delete
  find "$_targetdir" -type d -name '.git*' -prune -exec rm -r '{}' \;

  # Extract missing tools into the "tools" directory
  _tools="$_targetdir/tools"
  tar --no-same-owner -xf "x86_64-linux-gnu.esptool-"*".tar.gz" -C "$_tools"
  tar --no-same-owner -xf "x86_64-linux-gnu.mklittlefs-"*".tar.gz" -C "$_tools"
  tar --no-same-owner -xf "x86_64-linux-gnu.mkspiffs-"*".tar.gz" -C "$_tools"

  # The toolchain expects a "python3/python3" in the tools directory
  mkdir "$_tools/python3"
  ln -s "/usr/bin/python3" "$_tools/python3/"
}