Skip to content

Instantly share code, notes, and snippets.

@johnnyman727
Last active June 16, 2019 19:29
Show Gist options
  • Save johnnyman727/e04c51fe579bbdc672a7a834ebf0a14f to your computer and use it in GitHub Desktop.
Save johnnyman727/e04c51fe579bbdc672a7a834ebf0a14f to your computer and use it in GitHub Desktop.
Steps for compiling the OpenWRT SDK on OSX
  1. Install dependencies: brew install sdl openssl gettext
  2. Add the bin folder of gettext to your path: export PATH=$PATH:/usr/local/Cellar/gettext/0.19.4/bin
  3. Go through steps 1-9 here
  4. git clone --recursive https://github.com/tessel/openwrt-tessel.git
  5. cd openwrt-tessel
  6. Replace openwrt/tools/mkimage/Makefile with the file included in this Gist of the similar name (an artifact of OSX being unable to link against SSL development headers). Make sure to change lines 35 and 36 with a valid link to the openssl library brew installed in the previous step, if necessary. I created it by combining this debugging suggestion which didn't work and this updated file on master which also didn't work on its own.
  7. make V=99
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C out BUILDTYPE=Release V=99
  LD_LIBRARY_PATH=/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/lib.host:/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../deps/v8/tools/gyp; mkdir -p /Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/obj/gen; python ../../tools/js2c.py "/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/obj/gen/libraries.cc" CORE ../../src/macros.py ../../src/messages.h ../../src/runtime.js ../../src/prologue.js ../../src/v8natives.js ../../src/symbol.js ../../src/array.js ../../src/string.js ../../src/uri.js ../../src/math.js ../../src/third_party/fdlibm/fdlibm.js ../../src/date.js ../../src/regexp.js ../../src/arraybuffer.js ../../src/typedarray.js ../../src/iterator-prototype.js ../../src/generator.js ../../src/object-observe.js ../../src/collection.js ../../src/weak-collection.js ../../src/collection-iterator.js ../../src/promise.js ../../src/messages.js ../../src/json.js ../../src/array-iterator.js ../../src/string-iterator.js ../../src/debug-debugger.js ../../src/mirror-debugger.js ../../src/liveedit-debugger.js ../../src/templates.js ../../src/harmony-array.js ../../src/harmony-typedarray.js
Traceback (most recent call last):
  File "../../tools/js2c.py", line 37, in <module>
    import bz2
ImportError: No module named bz2
make[6]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/obj/gen/libraries.cc] Error 1
make[5]: *** [node] Error 2
make[4]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/.built] Error 2
make[4]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/package/node/node'
make[3]: *** [package/feeds/tessel/node/compile] Error 2
make[3]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[2]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.package_compile] Error 2
make[2]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[1]: *** [world] Error 2
make: *** [world] Error 2

Then the compilation will probably fail after a while with:

make[4]: Entering directory `/Volumes/OpenWrt/openwrt-tessel/openwrt/package/utils/bzip2'
/Applications/Xcode.app/Contents/Developer/usr/bin/make -j1 -C /Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/host/bzip2-1.0.6  -f Makefile-libbz2_so
gcc -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.6 blocksort.o huffman.o crctable.o randtable.o compress.o decompress.o bzlib.o
ld: unknown option: -soname
clang: error: linker command failed with exit code 1 (use -v to see invocation)
make[5]: *** [all] Error 1
make[4]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/host/bzip2-1.0.6/.built] Error 2
make[4]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt/package/utils/bzip2'
make[3]: *** [package/utils/bzip2/host/compile] Error 2
make[3]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[2]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.package_compile] Error 2
make[2]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[1]: *** [world] Error 2
make: *** [world] Error 2
  1. To fix this, open up openwrt/build_dir/host/bzip2-1.0.6/Makefile-libbz2.so and replace line 38:
	$(CC) -shared -Wl,-soname -Wl,libbz2.so.1.0 -o libbz2.so.1.0.6 $(OBJS)

With the following:

	$(CC) -shared -Wl, -install_name -Wl,libbz2.so.1.0 -o libbz2.so.1.0.6 $(OBJS)

Apparently this Makefile is using a flag (-soname) that doesn't work on OSX so we replace it with an equivalent flag. I don't think this is the best way to fix it but I'm not sure how this file gets generated.

  1. Then compilation will fail because of this issue with libpcap trying to reference "linux/types.h" To fix that, I added an include flag to the MAKE_FLAGS section of the upstream-packages/lib/libcap/Makefile with I$(BUILD_DIR_TOOLCHAIN)/linux-dev/include. I included the entire Makefile in this Gist for convenience. I also deleted openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libcap-2.24 and dl/libcap-2.24.tar.xz just to make sure it was downloaded fresh and rebuilt.
  2. Then I recompiled and hit this error message:
cc -fpic -I/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libcap-2.24/libcap/include -I/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/linux-dev/include _makenames.c -o _makenames
In file included from _makenames.c:10:
In file included from /Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libcap-2.24/libcap/include/sys/capability.h:24:
In file included from /Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/linux-dev/include/linux/types.h:8:
In file included from /Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/linux-dev/include/linux/posix_types.h:35:
In file included from /Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/linux-dev/include/asm/posix_types.h:12:
/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/linux-dev/include/asm/sgidefs.h:18:2: error:
      Use a Linux compiler or give up.
#error Use a Linux compiler or give up.
 ^
1 error generated.
make[6]: *** [_makenames] Error 1
make[5]: *** [all] Error 2
make[4]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/libcap-2.24/.built] Error 2
make[4]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/upstream-packages/libs/libcap'
make[3]: *** [package/feeds/packages/libcap/compile] Error 2
make[3]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[2]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.package_compile] Error 2
make[2]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[1]: *** [world] Error 2
make: *** [world] Error 2
  1. Take a brief moment to appreciate the snarkiness of that error
  2. Open openwrt/build_dir/toolchain-mipsel_24kec+dsp_gcc-4.8-linaro_uClibc-0.9.33.2/linux-dev/include/asm/sgidefs.h and delete or comment out the entire #ifndef __linux__ block.
  3. Recompile and you'll run into an issue where mDNS Responder won't compile properly:
mipsel-openwrt-linux-uclibc-gcc -I../mDNSCore -I../mDNSShared -Iobjects/prod -fwrapv -W -Wall -DPID_FILE=\"/var/run/mdnsd.pid\" -DMDNS_UDS_SERVERPATH=\"/var/run/mdnsd\" -D_GNU_SOURCE -DHAVE_IPV6 -DNOT_HAVE_SA_LEN -DUSES_NETLINK -DHAVE_LINUX -DTARGET_OS_LINUX -fno-strict-aliasing -Os -pipe -mno-branch-likely -mips32r2 -mtune=24kec -mdsp -fno-caller-saves -fhonour-copts -Wno-error=unused-but-set-variable -msoft-float dns-sd.c ClientCommon.c  -I../mDNSShared -Wall -o build/dns-sd
dns-sd.c: In function 'base64Encode':
dns-sd.c:382:58: warning: unused parameter 'rdata' [-Wunused-parameter]
 static void base64Encode(char *buffer, int buflen, void *rdata, unsigned int rdlen)
                                                          ^
dns-sd.c:382:78: warning: unused parameter 'rdlen' [-Wunused-parameter]
 static void base64Encode(char *buffer, int buflen, void *rdata, unsigned int rdlen)
                                                                              ^
/var/folders/s2/tcwl1vwx0m5d0z4xlwxx6_c00000gn/T//ccoPqd6B.o: In function `zonedata_resolve':
dns-sd.c:(.text+0x7bc): undefined reference to `DNSServiceRefDeallocate'
/var/folders/s2/tcwl1vwx0m5d0z4xlwxx6_c00000gn/T//ccoPqd6B.o: In function `zonedata_browse':
dns-sd.c:(.text+0x13f8): undefined reference to `DNSServiceResolve'
/var/folders/s2/tcwl1vwx0m5d0z4xlwxx6_c00000gn/T//ccoPqd6B.o: In function `RegisterService.constprop.8':
dns-sd.c:(.text+0x1bb8): undefined reference to `DNSServiceRegister'
/var/folders/s2/tcwl1vwx0m5d0z4xlwxx6_c00000gn/T//ccoPqd6B.o: In function `qr_reply':
dns-sd.c:(.text+0x2650): undefined reference to `DNSServiceReconfirmRecord'
/var/folders/s2/tcwl1vwx0m5d0z4xlwxx6_c00000gn/T//ccoPqd6B.o: In function `main':
dns-sd.c:(.text.startup+0x404): undefined reference to `DNSServiceEnumerateDomains'
dns-sd.c:(.text.startup+0x57c): undefined reference to `DNSServiceCreateConnection'
dns-sd.c:(.text.startup+0x5b0): undefined reference to `DNSServiceBrowse'
dns-sd.c:(.text.startup+0x68c): undefined reference to `DNSServiceResolve'
dns-sd.c:(.text.startup+0x768): undefined reference to `DNSServiceCreateConnection'
dns-sd.c:(.text.startup+0x8b8): undefined reference to `DNSServiceRegisterRecord'
dns-sd.c:(.text.startup+0xef8): undefined reference to `DNSServiceQueryRecord'
dns-sd.c:(.text.startup+0x1014): undefined reference to `DNSServiceRegister'
dns-sd.c:(.text.startup+0x10a0): undefined reference to `DNSServiceRegister'
dns-sd.c:(.text.startup+0x10d0): undefined reference to `DNSServiceAddRecord'
dns-sd.c:(.text.startup+0x1150): undefined reference to `DNSServiceRegister'
dns-sd.c:(.text.startup+0x1178): undefined reference to `DNSServiceUpdateRecord'
dns-sd.c:(.text.startup+0x1294): undefined reference to `DNSServiceNATPortMappingCreate'
dns-sd.c:(.text.startup+0x1314): undefined reference to `DNSServiceGetAddrInfo'
dns-sd.c:(.text.startup+0x1360): undefined reference to `DNSServiceCreateConnection'
dns-sd.c:(.text.startup+0x13b8): undefined reference to `DNSServiceBrowse'
dns-sd.c:(.text.startup+0x1404): undefined reference to `DNSServiceBrowse'
dns-sd.c:(.text.startup+0x1478): undefined reference to `DNSServiceRegister'
dns-sd.c:(.text.startup+0x14ac): undefined reference to `DNSServiceUpdateRecord'
dns-sd.c:(.text.startup+0x14ec): undefined reference to `DNSServiceAddRecord'
dns-sd.c:(.text.startup+0x1514): undefined reference to `DNSServiceRemoveRecord'
dns-sd.c:(.text.startup+0x1558): undefined reference to `DNSServiceGetProperty'
dns-sd.c:(.text.startup+0x1640): undefined reference to `DNSServiceRefSockFD'
dns-sd.c:(.text.startup+0x1664): undefined reference to `DNSServiceRefSockFD'
dns-sd.c:(.text.startup+0x1788): undefined reference to `DNSServiceProcessResult'
dns-sd.c:(.text.startup+0x1820): undefined reference to `DNSServiceAddRecord'
dns-sd.c:(.text.startup+0x1860): undefined reference to `DNSServiceUpdateRecord'
dns-sd.c:(.text.startup+0x1890): undefined reference to `DNSServiceRemoveRecord'
dns-sd.c:(.text.startup+0x1914): undefined reference to `DNSServiceUpdateRecord'
dns-sd.c:(.text.startup+0x1958): undefined reference to `DNSServiceAddRecord'
dns-sd.c:(.text.startup+0x1a2c): undefined reference to `DNSServiceRefDeallocate'
dns-sd.c:(.text.startup+0x1a40): undefined reference to `DNSServiceRefDeallocate'
collect2: error: ld returned 1 exit status
make[6]: *** [build/dns-sd] Error 1
make[5]: *** [../Clients/build/dns-sd] Error 2
make[4]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/mDNSResponder-567/.built] Error 2
make[4]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/upstream-packages/net/mdnsresponder'
make[3]: *** [package/feeds/packages/mdnsresponder/compile] Error 2
make[3]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[2]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.package_compile] Error 2
make[2]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[1]: *** [world] Error 2
make: *** [world] Error 2
  1. I removed PACKAGES += tessel-mdns and PACKAGES += mdns-utils from packages.mk to avoid building mdnsresponder.
  2. Recompiled again with make world and... fail:
/Applications/Xcode.app/Contents/Developer/usr/bin/make -C out BUILDTYPE=Release V=99
  LD_LIBRARY_PATH=/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/lib.host:/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/lib.target:$LD_LIBRARY_PATH; export LD_LIBRARY_PATH; cd ../deps/v8/tools/gyp; mkdir -p /Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/obj/gen; python ../../tools/js2c.py "/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/obj/gen/libraries.cc" CORE ../../src/macros.py ../../src/messages.h ../../src/runtime.js ../../src/prologue.js ../../src/v8natives.js ../../src/symbol.js ../../src/array.js ../../src/string.js ../../src/uri.js ../../src/math.js ../../src/third_party/fdlibm/fdlibm.js ../../src/date.js ../../src/regexp.js ../../src/arraybuffer.js ../../src/typedarray.js ../../src/iterator-prototype.js ../../src/generator.js ../../src/object-observe.js ../../src/collection.js ../../src/weak-collection.js ../../src/collection-iterator.js ../../src/promise.js ../../src/messages.js ../../src/json.js ../../src/array-iterator.js ../../src/string-iterator.js ../../src/debug-debugger.js ../../src/mirror-debugger.js ../../src/liveedit-debugger.js ../../src/templates.js ../../src/harmony-array.js ../../src/harmony-typedarray.js
Traceback (most recent call last):
  File "../../tools/js2c.py", line 37, in <module>
    import bz2
ImportError: No module named bz2
make[6]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/out/Release/obj/gen/libraries.cc] Error 1
make[5]: *** [node] Error 2
make[4]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/build_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/node-v4.4.3/.built] Error 2
make[4]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/package/node/node'
make[3]: *** [package/feeds/tessel/node/compile] Error 2
make[3]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[2]: *** [/Volumes/OpenWrt/openwrt-tessel/openwrt/staging_dir/target-mipsel_24kec+dsp_uClibc-0.9.33.2/stamp/.package_compile] Error 2
make[2]: Leaving directory `/Volumes/OpenWrt/openwrt-tessel/openwrt'
make[1]: *** [world] Error 2
make: *** [world] Error 2

Still investigating...

#
# Copyright (C) 2006-2014 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=mkimage
PKG_VERSION:=2014.10
PKG_SOURCE:=u-boot-$(PKG_VERSION).tar.bz2
PKG_SOURCE_URL:=\
http://mirror2.openwrt.org/sources \
ftp://ftp.denx.de/pub/u-boot
PKG_MD5SUM:=3ddcaee2f05b7c464778112ec83664b5
PKG_CAT:=bzcat
HOST_BUILD_DIR:=$(BUILD_DIR_HOST)/u-boot-$(PKG_VERSION)
include $(INCLUDE_DIR)/host-build.mk
define Host/Prepare
$(Host/Prepare/Default)
rm -f \
$(HOST_BUILD_DIR)/include/errno.h \
$(HOST_BUILD_DIR)/include/malloc.h \
$(HOST_BUILD_DIR)/tools/.depend
touch $(HOST_BUILD_DIR)/include/config.mk
touch $(HOST_BUILD_DIR)/include/config.h
endef
define Host/Compile
$(MAKE) -C $(HOST_BUILD_DIR) defconfig HOSTCFLAGS="$(HOST_CPPFLAGS) $(HOST_CFLAGS) -I/usr/local/Cellar/openssl/1.0.2h_1/include" HOSTLDFLAGS="$(HOST_LDFLAGS) -L/usr/local/Cellar/openssl/1.0.2h_1/lib"
$(MAKE) -C $(HOST_BUILD_DIR) tools-only HOSTCFLAGS="$(HOST_CPPFLAGS) $(HOST_CFLAGS) -I/usr/local/Cellar/openssl/1.0.2h_1/include" HOSTLDFLAGS="$(HOST_LDFLAGS) -L/usr/local/Cellar/openssl/1.0.2h_1/lib"
endef
define Host/Install
$(CP) $(HOST_BUILD_DIR)/tools/mkimage $(STAGING_DIR_HOST)/bin/
endef
define Host/Clean
rm -f $(STAGING_DIR_HOST)/bin/mkimage
endef
$(eval $(call HostBuild))
#
# Copyright (C) 2011 OpenWrt.org
#
# This is free software, licensed under the GNU General Public License v2.
# See /LICENSE for more information.
#
include $(TOPDIR)/rules.mk
PKG_NAME:=libcap
PKG_VERSION:=2.24
PKG_RELEASE:=1
PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz
PKG_SOURCE_URL:=http://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/
PKG_MD5SUM:=d43ab9f680435a7fff35b4ace8d45b80
PKG_MAINTAINER:=Steven Barth <cyrus@openwrt.org>
PKG_INSTALL:=1
include $(INCLUDE_DIR)/package.mk
include $(INCLUDE_DIR)/kernel.mk
define Package/libcap
TITLE:=Linux capabilities library
SECTION:=libs
CATEGORY:=Libraries
URL:=http://www.kernel.org/pub/linux/libs/security/linux-privs/libcap2/
endef
MAKE_FLAGS += \
CFLAGS="$(TARGET_CFLAGS)" \
BUILD_CC="$(CC)" \
BUILD_CFLAGS="$(FPIC) -I$(BUILD_DIR_TOOLCHAIN)/linux-dev/include -I$(PKG_BUILD_DIR)/libcap/include" \
CFLAGS="$(TARGET_CFLAGS)" \
LD="$(TARGET_CC)" \
LDFLAGS="$(TARGET_LDFLAGS) -shared" \
INDENT="| true" \
PAM_CAP="no" \
LIBATTR="no" \
DYNAMIC="yes" \
lib="lib"
define Build/InstallDev
$(INSTALL_DIR) $(1)/usr/include/sys
$(CP) $(PKG_INSTALL_DIR)/usr/include/* $(1)/usr/include/
$(INSTALL_DIR) $(1)/usr/lib/
$(CP) $(PKG_INSTALL_DIR)/lib/* $(1)/usr/lib/
endef
define Package/libcap/install
$(INSTALL_DIR) $(1)/usr/lib
$(CP) $(PKG_INSTALL_DIR)/lib/libcap.so* $(1)/usr/lib/
endef
$(eval $(call BuildPackage,libcap))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment