Fix compilation on OS X in order to support both MacPorts and Homebrew

This commit is contained in:
Steffen Vogel 2017-02-07 11:12:12 -03:00
parent 19f36271c2
commit 7e08e37961
1 changed files with 25 additions and 13 deletions

View File

@ -62,17 +62,29 @@ SED ?= sed
BISON ?= bison BISON ?= bison
ifeq (Darwin,$(findstring Darwin,$(shell uname))) ifeq (Darwin,$(findstring Darwin,$(shell uname)))
BREW := $(shell command -v brew 2> /dev/null)
ifdef BREW # homebrew search paths
export PKG_CONFIG_PATH = $(shell $(BREW) list libffi | grep pkgconfig | xargs dirname) ifneq ($(shell which brew),)
BISON = $(shell $(BREW) list bison | grep -m1 "bin/bison") 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 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 # macports search paths
LDFLAGS += -L/opt/local/lib -L/usr/local/opt/readline/lib ifneq ($(shell which port),)
# add macports/homebrew's libffi include and library path PORT_PREFIX := $(patsubst %/bin/port,%,$(shell which port))
CXXFLAGS += $(shell pkg-config --silence-errors --cflags libffi)
LDFLAGS += $(shell pkg-config --silence-errors --libs libffi) 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 else
LDFLAGS += -rdynamic LDFLAGS += -rdynamic
LDLIBS += -lrt LDLIBS += -lrt