Mac OS: installing ngspice, magic, netgen, xschem

Install Homebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

To check the version of Homebrew installed use the command:

brew --version

After installation, to keep your Homebrew system always current is recommended that you run on a regular basis

brew update
brew upgrade

To install/uninstall a package use:

brew install <package>
brew uninstall <package>

To check if a brew is installed use:

brew list | grep <package>

To check the location where a brew is installed use:

brew list <package>

To search for available packages with name containing TEXT use:

brew search TEXT | /TEXT/

If TEXT is flanked by slashes, it is interpreted as a regular expression

Example:
search all possible brew packages starting with tcl

brew search /^tcl/

To learn more about brew use:

man brew

or take a look at this user guide or the official documentation

Apple Silicon Mac vs. Intel Mac

  • On Intel Macs, Homebrew installs files into the /usr/local/ folder, which is by default configured in the shell $PATH variable.

  • On Apple silicon Macs, Homebrew installs files into the /opt/homebrew/ folder, which is not part of the default shell $PATH.
    You'll need to configure your shell environment so that Homebrew packages are found and have the desired priority.
    Homebrew installation takes care of configuring the shell environment adding the following line at the top of the .zprofile

eval "$(/opt/homebrew/bin/brew shellenv)"

The brew shellenv command sets the following environment variables:

export HOMEBREW_PREFIX="/opt/homebrew";
export HOMEBREW_CELLAR="/opt/homebrew/Cellar";
export HOMEBREW_REPOSITORY="/opt/homebrew";
export PATH="/opt/homebrew/bin:/opt/homebrew/sbin${PATH+:$PATH}";
export MANPATH="/opt/homebrew/share/man${MANPATH+:$MANPATH}:";
export INFOPATH="/opt/homebrew/share/info:${INFOPATH:-}";

Install MacPorts for your version of Mac OS


1. Install Apple's Command Line Developer Tools:

xcode-select --install

2. Install MacPorts for your version of Mac operating system:
The easiest way to install MacPorts is by downloading the pkg or dmg for your version of OS at this link

Macport installation adds the following two variables settings in the .zprofile

export PATH="/opt/local/bin:/opt/local/sbin:$PATH"
export MANPATH="/opt/local/share/man:$MANPATH"

After installation is done, to keep your MacPorts system always current, is recommended that you you run on a regular basis::

sudo port -v selfupdate

To check the version of Macports installed use the command:

port version

To install/uninstall a package

sudo port install <package>
sudo port uninstall <package>

To check if a macport is installed use:

port installed | grep <package>

To check the content of a package use:

port -q content <package>

To check the location where a package is installed use:

port -q content <package> | grep -E '/s?bin/'

To check the version of a package avaliable w/o installing it use:

port list <package>

For a nice thorough documentation check out the Mac Port Guide at this link

3. (optional) When building some ports from source you may need to install Apple's Xcode Developer Tools.
MacPorts will let you know if this is the case. Using the latest available version that will run on your OS is highly recommended

  • 14.1 or later for Ventura

  • 13.1 or later for Monterey

  • 12.2 or later for Big Sur

Link to (all) Xcode Developer Tools

To check the version of Xcode Tools installed use the following commands:

xcodebuild -version
xcode-select --version
softwareupdate --history

4. (optional) Install the X11 windowing environment (needed for ports that depend on this functionality).
You have multiple choices:

  • c1 - Install the latest version of XQuartz (version 2.8.5) -> Recommended option!
    The Xquartz Project provides a complete X11 release for macOS including server and client libraries and applications.

  • c2 - Install the X11 environment with MacPorts

    • sudo port -v install xorg-server

    • sudo port -v install xorg

  • c3 - Install the X11 environment with Homebrew

    • brew install --cask xquartz

Required packages


By default, both Homebrew and Macports install a number of common base packages (and their dependencies).
The CAD softwares we are going to install may require additional packages.
The additional packages may vary depending on the OS distribution.


Note: before starting to build from source ngspice, magic, netgen and xschem I installed icarus-verilog and ngspice-36
This triggers the installation of a number of additional packages on top of the base packages. Some of them are also required
for building ngspice, magic, netgen and xschem from source. If I didn't install ngspice-36 and icarus-verilog I would have
had to install them manually.

brew install icarus-verilog
sudo port install ngspice


To start with, let's install also these common additional packages

brew install libxaw
brew install libxpm
brew install libxft
brew install libxcb

Install ngspice using Homebrew

This is the fastest approach, but requires a few tweaks and the result has a few oddities

1. Google for homebrew ngspice
2. Download the raw formula file ngspice.rb in the Downloads folder
3. Run the following steps:

cd ~/Downloads
brew edit ngspice.rb

change:

--without-x into --with-x

and add the lines:

--enable-predictor
--enable-osdi
brew install ncurses
brew install libxt
brew install libxaw
brew reinstall --build-from-source ngspice.rb

NOTE: In some case libxft causes issues with the Homebrew installation! If needed uninstall it!

Ngspice gets successfully installed in the following location:
On macOS Ventura 13.5.1 with M1 processor:

/opt/homebrew/bin/ngspice

On macOS with intel processor

/usr/local/bin/ngspice

There are a couple of Warnings that come up when running ngspice but they are innocuous: (at least as far as I can tell)

Warning: locale not supported by Xlib, locale set to C
Warning: X locale modifiers not supported, using default
Warning: Unable to load any usable fontset

Download and compile ngspice from source

installation verified on

  • i7 with macOS Big Sur ver. 11.7.10 (ngspice-41)

  • i7 with macOS Monterey ver. 12.7.2 (ngspice-41)

  • apple Silicon M1 with macOS Ventura 13.5.2 (ngspice-41)


1. browse to the home directory

cd ~

2. Download the latest ngspice from this link

3. expand the tarball

tar -xzvf ngspice-41.tar.gz
cd ngspice-41

read carefully the instructions in the file INSTALL

4. Install an X11 interface (like Xquartz)

  • Download and install Xquartz latest version (2.8.5) from this link

  • reboot the mac

5. Install the following additional packages

sudo port install autoconf automake libtool bison flex ncurses xorg-libXaw \
   readline fontconfig freetype libomp

6. Compile ngspice using the script compile_macos_clang.sh

ngspice-41 on i7 with OS Big Sur and Monterey

Before running the script compile_macos_clang.sh make sure to add the following line to the command ../configure :

--prefix=/Users/$(whoami)/opt/ngspice --enable-predictor --enable-osdi

The ../configure command looks as follow:

 ../configure --prefix=/Users/$(whoami)/opt/ngspice --enable-predictor --enable-osdi \
 --with-x --enable-xspice --enable-cider \
 --with-readline=/usr/local/opt/readline --disable-debug \
 CFLAGS="-m64 -O2 -I/opt/X11/include/freetype2 \
 -I/usr/local/opt/readline/include -I/usr/local/opt/ncurses/include" \
 LDFLAGS="-m64 -L/usr/local/opt/readline/lib -L/usr/local/opt/ncurses/lib -L/opt/X11/lib"

ngspice-41 on Apple Silicon with OS Ventura 13.5.2

Before running the script compile_mac_clang.sh make sure to modify the ../configure command as follows:

../configure --prefix=/Users/$(whoami)/opt/ngspice --enable-predictor --enable-osdi \
--with-x --enable-xspice --enable-cider \
--with-readline=yes --disable-debug \
CFLAGS="-m64 -O2 -I/opt/X11/include/freetype2 \
-I/usr/local/opt/readline/include -I/usr/local/opt/ncurses/include" \
LDFLAGS="-m64 -L/usr/local/opt/readline/lib -L/usr/local/opt/ncurses/lib -L/opt/X11/lib"

Download and compile magic from source

installation verified on

  • i7 with macOS Big Sur ver. 11.7.10

  • i7 with macOS Monterey ver. 12.7.2,

  • apple Silicon M1 with macOS Ventura 13.5.2


1. install the following additional packages

sudo port install m4
sudo port install tcsh
sudo port install blt
sudo port install freeglut
sudo port install mesa
sudo port install libGLU
sudo port install cairo
sudo port install tcl
sudo port install tk
sudo port install sqlite3-tcl
sudo port install tclreadline

2. download magic using git

cd ~
git clone git://opencircuitdesign.com/magic magic_git
cd magic_git

3. configure and compile magic

./configure --prefix=/Users/$(whoami)/opt/magic --with-tcl=/opt/local/lib \
--with-tk=/opt/local/lib --x-includes=/opt/local/include --x-libraries=/opt/local/lib
make
make install

In the past before running make was necessary to edit the file defs.mak and add to the CFLAGS

-O2 -Wno-error -Wno-implicit-function-declaration

4. set up the techfiles of the processes you plan to use

cd $CAD_ROOT/magic/sys
mkdir current
cd current

copy the tech files you plan to use in the directory current

Examples

  • SCN3ME_SUBM.30.tech

  • sample6m.tech

the variable $CAD_ROOT is set as follows:

export $CAD_ROOT=$HOME/opt/magic/lib

5. link the skywater 130nm PDK with magic

sudo ln -s $PDK_ROOT/sky130A/libs.tech/magic/* $CAD_ROOT/magic/sys/

the variable $PDK_ROOT is the PDKs installation directory

Example

export PDK_ROOT=$HOME/share/pdks

Download and compile netgen from source

installation verified on

  • i7 with macOS Big Sur ver. 11.7.10

  • i7 with macOS Monterey ver. 12.7.2,

  • apple Silicon M1 with macOS Ventura 13.5.2


1. download the latest source distribution using git

cd ~
git clone git://opencircuitdesign.com/netgen git_netgen
cd git_netgen

2. configure and compile netgen

./configure --prefix=/Users/$(whoami)/opt/netgen --with-tcl=/opt/local/lib --with-tk=/opt/local/lib
make
make install

Download and compile xschem from source


Old-fashioned way of installing xschem on macOS Big Sur

installation verified on

  • i7 with macOS Big Sur ver. 11.7.10

  • i7 with macOS Monterey ver. 12.7.2

  • xschem v3.4.5 on apple Silicon M1 with macOS Ventura 13.5.2


1. install the following additional packages

sudo port install gawk
brew install macvim
sudo port install gaw
sudo port install dbus

2. download and configure the latest source distribution using git

git clone https://github.com/StefanSchippers/xschem.git xschem_git
cd xschem_git
## set prefix to the base directory where xschem and his support files will be installed
## if unspecified default is /usr/local
./configure --prefix=/Users/$(whoami)/opt/xschem

3. compile and install xschem
Before building the application, we need to adjust Makefile.conf
We need to replace the CFLAGS and LDFLAGS variables in that file as follows:

CFLAGS=-std=c99 -I/opt/X11/include -I/opt/X11/include/cairo \
-I/opt/local/include -O2
LDFLAGS=-L/opt/X11/lib -L/opt/local/lib -lm -lcairo -ljpeg\
-lX11 -lXrender -lxcb -lxcb-render -lX11-xcb -lXpm -ltcl8.6 -ltk8.6
make
make install

NOTE:

With Ventura 13.3 on Apple Silicon xschem has issues with the mapping of the colors. This makes xschem "unusable".
With Xschem 3.4.4 on Ventura 13.5.2 the issue with the mapping of the colors is SOLVED!".
With Big Sur and Monterey on i7 there are no issues.


4. create a .Xdefaults file

Since xschem's default terminal is xterm it is worth to create in the home directory a file .Xdefaults with your favorite preferences:

.Xdefaults
xterm*Background: lightblue
xterm*Foreground: black
xterm*VT100*geometry: 80x20
xterm*faceName: Monospace
xterm*faceSize: 10
xterm*scrollBar: true
xterm*saveLines: 1000
xterm*rightScrollBar: true
xterm*multiScroll: on
xterm*jumpScroll: on