Fix compilation on OS X in order to support both MacPorts and Homebrew
authorSteffen Vogel <post@steffenvogel.de>
Tue, 7 Feb 2017 14:12:12 +0000 (11:12 -0300)
committerSteffen Vogel <post@steffenvogel.de>
Tue, 7 Feb 2017 14:16:56 +0000 (11:16 -0300)
Makefile

index 280c9d6a1172271f1c2e60d6281b5633d11f8141..11cef84a2aebb461d13ce8e5acef8ed27ea21722 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -62,20 +62,32 @@ SED ?= sed
 BISON ?= bison
 
 ifeq (Darwin,$(findstring Darwin,$(shell uname)))
-       BREW := $(shell command -v brew 2> /dev/null)
-       ifdef BREW
-               export PKG_CONFIG_PATH = $(shell $(BREW) list libffi | grep pkgconfig | xargs dirname)
-               BISON = $(shell $(BREW) list bison | grep -m1 "bin/bison")
-       endif
-       # add macports/homebrew include and library path to search directories, don't use '-rdynamic' and '-lrt':
-       CXXFLAGS += -I/opt/local/include -I/usr/local/opt/readline/include
-       LDFLAGS += -L/opt/local/lib -L/usr/local/opt/readline/lib
-       # add macports/homebrew's libffi include and library path
-       CXXFLAGS += $(shell pkg-config --silence-errors --cflags libffi)
-       LDFLAGS += $(shell pkg-config --silence-errors --libs libffi)
+
+# homebrew search paths
+ifneq ($(shell which brew),)
+BREW_PREFIX := $(shell brew --prefix)/opt
+
+CXXFLAGS += -I$(BREW_PREFIX)/readline/include
+LDFLAGS += -L$(BREW_PREFIX)/readline/lib
+
+export PKG_CONFIG_PATH := $(BREW_PREFIX)/libffi/lib/pkgconfig:$(PKG_CONFIG_PATH)
+export PATH := $(BREW_PREFIX)/bison/bin:$(BREW_PREFIX)/gettext/bin:$(BREW_PREFIX)/flex/bin:$(PATH)
+endif
+
+# macports search paths
+ifneq ($(shell which port),)
+PORT_PREFIX := $(patsubst %/bin/port,%,$(shell which port))
+
+CXXFLAGS += -I$(PORT_PREFIX)/include
+LDFLAGS += -L$(PORT_PREFIX)/lib
+
+export PKG_CONFIG_PATH := $(PORT_PREFIX)/lib/pkgconfig:$(PKG_CONFIG_PATH)
+export PATH := $(PORT_PREFIX)/bin:$(PATH)
+endif
+
 else
-       LDFLAGS += -rdynamic
-       LDLIBS += -lrt
+LDFLAGS += -rdynamic
+LDLIBS += -lrt
 endif
 
 YOSYS_VER := 0.7+$(shell cd $(YOSYS_SRC) && test -e .git && { git log --author=clifford@clifford.at --oneline 61f6811.. | wc -l; })