To build a .pkg installer (for macOS) for your C program (fetch_addr), we’ll follow this outline:
- Xcode Command Line Tools (for
gcc,pkgbuild, etc.)
xcode-select --install- Homebrew dependencies:
brew install curl cjsonCreate fetch_addr.c from the code above, then compile:
gcc fetch_addr.c -o fetch_addr -lcurl -lcjsonYou should now have a binary called fetch_addr.
Make a clean package layout:
mkdir -p pkg_root/usr/local/bin
cp fetch_addr pkg_root/usr/local/bin/Set permissions:
chmod 755 pkg_root/usr/local/bin/fetch_addrUse pkgbuild to make a simple installer:
pkgbuild \
--identifier com.yourname.fetchaddr \
--version 1.0.0 \
--install-location /usr/local/bin \
--root pkg_root \
fetch_addr.pkgThis will generate fetch_addr.pkg in the current directory.
Now you can run the .pkg installer on any macOS system. After install, fetch_addr will be available in terminal via:
fetch_addrIf you want:
- A prettier GUI installer: Use
productbuild+distribution.xml - To notarize and sign: You'll need an Apple Developer ID and codesigning tools