This is an old revision of the document!
Build system setup macOS
This method is NOT OFFICIALLY supported. A native GNU/Linux environment is recommended.
Tested with macOS 10.15.7, Xcode 12.1 build 12A7403, & packages from homebrew.
Tested with macOS 11.6, Xcode 13.0 build 13A233, arm64 kernel, & packages from homebrew.
A. Obtain build toolchain:
Obtain build toolchain that is more suitable for Apple hardware & macOS:
- Install Xcode or CLT:
- If you prefer to not obtain Xcode, then one of the alternative is:
- obtain Command-Line-Tools1 (CLT) from here, or Load it from
App Storein macOS, or use below command, or obtain apple-gcc package via package manager software. CLT is also known as Command Line Developer Tools. Note: installer download is under/near 300 MB, and may need around ~ 2 GB space.
- Build toolchain from apple is used (in first stage) to create a software components for openwrt build purpose, then (in second stage) those software components are used to create the final openwrt components, in order to create openwrt firmware, etc, that are widely compatible with cross-platform.
B. View hidden files/folders:
- We need to view full filename, file extensions, all files & directories, etc including hidden ones, very accurately, so that there is lesser mistakes.
- Use Finder to start Terminal in macOS:
Finderis very similar toWindows-Explorerfile-browser app/tool. In macOS > click on any empty area in Desktop screen > in top-side menu click onWindow> click onBring All to Front> in left-pane (in left side column) ofFinder, go underFavoritesand click on theApplications> then scroll down & go intoUtilitiessub-folder > then click onTerminalorTerminal.appto start it. macOSTerminalis very similar to WindowsCommand-Prompt, a command-line interface (CLI) tool.- Hotkeys to start
Finderinstantly :[Alt/Option⌥]+[Command⌘]+[Space-bar]then close the Search tab. - Hotkeys to start
Terminalinstantly : None. ( Note: KeepTerminalrunning, after a rebootTerminalwill auto-start if you check-marked the option: Load previous running apps after reboot ).
- Run below command inside
Terminal:defaults write com.apple.Finder AppleShowAllFiles true
- above only makes the files viewable inside file-browser software, it does not actually change any file-attributes.
- then you must reboot Mac-computer OR run (any one of the) below command:
/usr/bin/sudo /usr/bin/killall Finder /System/Library/CoreServices/Finder.app
or, run just this:
/usr/bin/sudo /usr/bin/killall Finder
or, just this:
sudo killall Finder
- then
Finderwill auto start, and all hidden files+folders will by-default begin to be shown to user in macOS Finder. - in macOS
Finderor inside any other file browsing window in macOS, user can also press below THREE buttons altogether ONCE to show all HIDDEN files/folders:[Command⌘]+[Shift⇧]+[.>]- if user press-es above three buttons again, file-browsing-window will HIDE the HIDDEN files/folders.
- By default in macOS,
Finderwill keep most of the file extension hidden. But we need to see all file's extension to see FULL filename, so we can be sure & not make mistake. To view all file's extension, do below steps:- in macOS > start “Finder” app > goto main menu >
Finder>Preferences>Advanced> select theShow All Filename Extensionsoption.
C. Install Package-Manager:
Install any one of the (3rd-party) package manager (pkg-mngr) software in macOS:
- Homebrew : Note: it shares user's usage/private data with Ggl.
-
- download/obtain MacPorts installer dmg/pkg file, install it.
- Before MacPorts is installed, your
~/.bash_profilefile (inside your home directory) may look close to like this:# .bash_profile for BASH # PROMPT_COMMAND=update_terminal_cwd PS1='\h:\W \u\$ ' PS2='> ' PS4='+ ' PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" export PATH
- MacPorts installer webpage will instruct you to add
macportspkg-mngr executable file locations in the end of your PATH variable, like this:PATH="$PATH:/opt/macports/bin:/opt/macports/sbin"
- after you add above line manually in
~/.bash_profilefile, it will look like below:# .bash_profile for BASH # PROMPT_COMMAND=update_terminal_cwd PS1='\h:\W \u\$ ' PS2='> ' PS4='+ ' PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" PATH="$PATH:/opt/macports/bin:/opt/macports/sbin" export PATH
- you can use this command to edit the
~/.bash_profilefile:sudo nano ~/.bash_profile
- When MacPorts is installed, installer will add locations in PATH where macports port package executables are stored, inside the
~/.bash_profilefile. In that way, your macOS user account can find+use the installed macports port package files, after you login. But we have to change it little bit.
Here is what you will usually see in~/.bash_profilefile:# .bash_profile for BASH # PROMPT_COMMAND=update_terminal_cwd PS1='\h:\W \u\$ ' PS2='> ' PS4='+ ' PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" PATH="$PATH:/opt/macports/bin:/opt/macports/sbin" ## # Your previous /Users/<YOUR-USER-NAME>/.bash_profile file was backed up as /Users/<YOUR-USER-NAME>/.bash_profile.macports-saved_2021-08-29_at_16:38:31 ## # MacPorts Installer addition on 2021-08-29_at_16:38:31: adding an appropriate PATH variable for use with MacPorts. export PATH="/opt/local/bin:/opt/local/sbin:$PATH" # Finished adapting your PATH environment variable for use with MacPorts.
- Change above codes, into below code:
# .bash_profile for BASH # PROMPT_COMMAND=update_terminal_cwd PS1='\h:\W \u\$ ' PS2='> ' PS4='+ ' PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" PATH="$PATH:/opt/macports/bin:/opt/macports/sbin" ## # Your previous /Users/<YOUR-USER-NAME>/.bash_profile file was backed up as /Users/<YOUR-USER-NAME>/.bash_profile.macports-saved_2021-08-29_at_16:38:31 ## # MacPorts Installer addition on 2021-08-29_at_16:38:31: adding an appropriate PATH variable for use with MacPorts. # export PATH="/opt/local/bin:/opt/local/sbin:$PATH" export PATH # Finished adapting your PATH environment variable for use with MacPorts.
- in above we have removed MacPorts package file locations from PATH, but locations of MacPorts pkg-mngr are kept in PATH. In this way, newly installed packages are kept out of touch of other software which does not need to use them. These packages are needed for development purpose of openwrt, so we will create a separate executable file (
env.sh) to load PATH, which is suitable only for using inside a shell-manager's specific shell TAB, for openwrt build/development purpose. See step/section F in below for details on creating thisenv.shfile. - macOS keeps the default PATH in
/etc/pathsfile, but do not edit/change it, because such change can affect entire or many parts of macOS system. We only need to change build environment only for 1 or 2 shell instance(s), and not for entire macOS system, and also not for all other apps in macOS.
D. Create dedicated case-sensitive filesystem:
Create a dedicated case-sensitive filesystem for OpenWRT build/compile purpose:
- We will be using a sparsebundle to allow us to have a case sensitive filesystem.
- The size that you provide will be the max size of the volume for working with OpenWrt. Execute below commands inside a Terminal shell instance:
cd ~ hdiutil create -size 20g -type SPARSE -fs "Case-sensitive HFS+" -volname OpenWrt OpenWrt.sparseimage hdiutil attach OpenWrt.sparseimage
- Optional/Informational:
- if you want to open the
OpenWRTVolume (aka: Drive, aka: Disk) after creating then use below command as 3rd-command line in above:hdiutil attach OpenWrt.sparseimage -autoopenrw - after a reboot, if
OpenWRTvolume is not available in your macOS, then run:cd ~ && hdiutil attach OpenWrt.sparseimage -autoopenrw
- if you want to keep the
OpenWRTvolume always attached, then:cd ~ && sudo hdiutil attach OpenWrt.sparseimage -notremovable -autoopenrw
- if you want to detach (aka: unmount) the
OpenWRTvolume, then:hdiutil detach /Volumes/OpenWrt
- More info on
hdiutilis here.
E. Goto OpenWRT build volume:
Go inside the OpenWRT build volume, with below command, in Terminal:
cd /Volumes/OpenWrt
F. Create location indicator & build environment file:
- Create a file called
env.shinside/Volumes/OpenWrtto indicate location of installed packages. It will also help us to create openwrt build friendly environment inside a specific shell TAB/instance.- This is to allow the utilities (aka: packages) we just installed to be used, instead of the macOS provided ones.
- For x86_64 Apple hardware, & when you have MacPorts, then create
env.shfile with below content, save it inside/Volumes/OpenWrtlocation:- env.sh
#!/opt/local/bin/bash PS1='\h:\W \u\$ ';PS2='> ';PS4='+ '; # Bring PATH lines from the ~/.bash_profile file into below: PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" PATH="$PATH:/opt/macports/bin:/opt/macports/sbin" # Adding path of macports port packages, in ahead of others: PATH="/opt/local/libexec/gnubin:/opt/local/bin:/opt/local/sbin:/opt/local/libexec:/opt/local/x86_64-apple-darwin19.6.0/bin:$PATH"; # Load PATH into currently running shell: export PATH; # Load other environment variables: export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk7-zulu/Contents/Home
- turn the
env.shfile an executable shell script file with this command:chmod +x /Volumes/OpenWrt/env.sh
- For MacPorts create
MacPorts.shfile in your home~/directory with this command:sudo nano ~/MacPorts.sh
- find the PATH variables lines in your
~/.bash_profilefile, and add into below content, then copy all from below & paste into~/MacPorts.shfile. You can also download below code as a file, then change upper 2 PATH variables, to match with your PATH inside your~/.bash_profilefile:- MacPorts.sh
#!/opt/local/bin/bash PS1='\h:\W \u\$ ';PS2='> ';PS4='+ '; # Bring PATH lines from the ~/.bash_profile file into below: PATH="/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin" PATH="$PATH:/opt/macports/bin:/opt/macports/sbin" # Bring last PATH line from the /Volumes/OpenWrt/env.sh file into below: PATH="/opt/local/libexec/gnubin:/opt/local/bin:/opt/local/sbin:/opt/local/libexec:/opt/local/x86_64-apple-darwin19.6.0/bin:$PATH"; # Load PATH into currently running shell program: export PATH; # Load other environment variables: export JAVA_HOME=/Library/Java/JavaVirtualMachines/openjdk7-zulu/Contents/Home
- turn the
MacPorts.shfile an executable shell script file with this command:chmod +x ~/MacPorts.sh
- For x86_64 Apple hardware, & when you have homebrew, then create
env.shfile with below content:PATH="/usr/local/opt/make/libexec/gnubin:$PATH" PATH="/usr/local/opt/gnu-getopt/bin:$PATH" PATH="/usr/local/opt/gettext/bin:$PATH" PATH="/usr/local/opt/coreutils/libexec/gnubin:$PATH" PATH="/usr/local/opt/findutils/libexec/gnubin:$PATH" export PATH
- For arm64 (Apple Silicon(M1)) Apple hardware, & when you have homebrew, then create
env.shfile with below content:PATH="/opt/homebrew/opt/make/libexec/gnubin:$PATH" PATH="/opt/homebrew/opt/gnu-getopt/bin:$PATH" PATH="/opt/homebrew/opt/gettext/bin:$PATH" PATH="/opt/homebrew/opt/coreutils/libexec/gnubin:$PATH" PATH="/opt/homebrew/opt/findutils/libexec/gnubin:$PATH" export PATH
- Optional : you may check homebrew official page or MacPorts-guide if you need more information related to PATH variable, or other info on pkg-mngr.
- Optional : turn
env.shfile an executable shell script file:chmod +x /Volumes/OpenWrt/env.sh
G. Install necessary packages:
Install necessary packages which helps to build openwrt components. Use below commands inside a shell instance in Terminal. Note: Packages will be installed inside macOS default volume, not inside /Volumes/OpenWrt
- if you have homebrew pkg-mngr then run this command:
brew install coreutils findutils gawk grep gnu-getopt gnu-tar wget diffutils git-extras quilt svn make ncurses pkg-config
- in above, homebrew command does not include the pre-requisites (aka: dependencies) packages mentioned here.
- if you have MacPorts pkg-mngr then run below 2 commands:
source ~/MacPorts.sh sudo port install libiconv gettext-runtime coreutils findutils gwhich gawk zlib pcre bzip2 ncurses grep getopt gettext-tools-libs gettext diffutils sharutils util-linux libxslt libxml2 help2man readline gtime gnutar unzip zip lzma xz libelf fastjar libusb libftdi0 expat sqlite3 openssl3 openssl kerberos5 dbus lz4 libunistring nettle icu gnutls p11-kit wget quilt subversion gmake pkgconfig libzip cdrtools ccache curl xxhashlib rsync libidn perl5 p5.28-xml-parser p5.30-xml-parser p5-extutils-makemaker p5-data-dumper boost-jam boost boost-build bash bash-completion binutils m4 flex intltool patchutils swig git-extras git openjdk17 openjdk7-zulu luajit libtool glib2 file python27 python310 libzzip mercurial asciidoc sdcc gnu-classpath
- in above, MacPorts command includes the pre-requisites (aka: dependencies) packages mentioned here. Space initially used by all of these packages : 4,190,442,792 bytes (2.57 GB on disk) for 129,623 items, (as of March-11, 2022). Note: As different packages are continuously modified & improved by their devs or releaser or adopter or maintainer, so their occupying space size & items count will be different in your computer in different time.
- if you need
picocomtool to communicate with router via serial adapter/cable connection, then:sudo port install picocom
- if you need last stable
openssh(aka:ssh),sftp,scptools for secure communication or file-transfer, then:sudo port install openssh
- if you need TFTP daemon/server (
tftpd) to receive files from router, then:sudo port install tftp-hpa
- if you need last stable
telnet,ftp,rsh,rlogin,tftptools and corresponding daemons, then:sudo port install inetutils
- if you need these type of tools, (more info: 1), then:
sudo port install arm-elf-binutils i386-elf-binutils m68k-elf-binutils mips-elf-binutils x86_64-elf-binutils
H. Optional-step: Start build friendly shell:
macOS by default uses a very old version of bash shell. So, we can start a build/compile friendly common last+stable version of bash shell inside macOS-Terminal's specific tab, as such version can be obtained & used by most developer users. Shell-manager software Terminal can run multiple shell instances, by using multiple Terminal-tabs. Select one (or more) Terminal-tab(s) to use for openwrt build purpose, then run below command to have same (last+stable) build environment.
- If you installed new bash package, then start new bash shell inside a specific tab in Terminal, (when you have MacPorts based bash package), with this command:
exec /opt/local/bin/bash
- optional : approve/permit new bash shell in macOS with this command:
echo “/opt/local/bin/bash” | sudo tee -a /private/etc/shells - optional : if you want to continue to use the new bash always, then: click on apple symbol in topside apple menu-bar >
System Preferences...>Users & Groups> Unlock the 🔒pane > control click on your user-name > selectAdvanced Options...> then update/change theLogin shellinto/opt/local/bin/bash>ok.
I. Load build environment:
We need to load build package locations indicator file as shell environment. OpenWRT developing (aka: building, aka: compiling, aka: compilation) is done inside a suitable (aka: build friendly) shell environment. So, we have to allow openwrt build commands to find packages that we installed via pkg-mngr, by loading build package location indicator file env.sh into one of the Terminal shell environment tab, to create that openwrt build friendly & suitable shell environment.
- When developing (aka: building, aka: compiling), run below command to set up build-friendly PATH (and other) variable(s). This leaves your system in a clean state without symlinking.
source /Volumes/OpenWrt/env.sh
- Optional : So from next time or after a reboot, when you want to enter into openwrt build mode, then run below 2 commands inside a specific tab in Terminal, when you have MacPorts based bash package:
exec /opt/local/bin/bash source /Volumes/OpenWrt/env.sh
J. Build:
Now proceed normally, (that is: follow build related procedures).
B43-FWCutter
Users who are developing openwrt firmware for Broadcom (BCM) 43xx chipset, need this b43-fwcutter tool to extract wireless drivers from firmware.
- More info here.
- Package manager
homebrewhas this tool, andMacPortsdoes not.
Golang related
Golang1: For darwin/arm64 and linux/aarch64 golang package (feed “packages”) golang C-bootstrap method doesn't work, but it is possible to use external golang bootstrap. On MacOS arm64 the easiest way is to install golang using brew and use installed golang as bootstrap:
brew install golang- Then set CONFIG_GOLANG_EXTERNAL_BOOTSTRAP_ROOT=“/opt/homebrew/opt/go/libexec” in .config file