One problem I see often with local builds are Makefiles that use modern GNU features in common commands like sed
, awk
, and tar
. If the product only runs on Linux, writing backwards compatible versions for the older BSD-based commands on Macs may not be an effective use of time.
A simple fix is to libexec/gnubin
directory to your path as documented here: Install and Use GNU Command Line Tools on macOS. However this changes your active environment, which might break scripts expecting to run on macOS. Further, this isn’t a repeatable configuration that can be safely used by others.
A better way is to explicitly configure the GNU versions to ensure they are used during the build. Shown here is a Makefile
snippet that can be included to add the specified utilities to the path only while running make
:
# On Mac OS X, require GNU versions of programs instead of dealing with BSD utility incompatibilityifeq ($(shell uname),Darwin)# These can be set to a smaller or larger list in the project MakefileBREWPKGS ?= make coreutils findutils gawk grep gnu-getopt gnu-indent gnu-sed gnu-tar gnutls gpatch m4define BREW_HAS_INSTALLEDifeq ($(shell brew ls --versions $1),)$(error Missing package $1 from Homebrew [http://brew.sh]. Please run: `brew install $1`)elsePATH := $(shell brew --prefix $1)/libexec/gnubin:$(PATH)endifendef# Iterate through packagesignore:= $(foreach pkg, $(BREWPKGS), $(eval $(call BREW_HAS_INSTALLED,${pkg})))# /Darwinendif
I found this idea in a Makefile in HazyResearch/deepdive and tweaked it to handle all the necessary packages.