@@ -56,6 +56,11 @@ SHELL = bash
5656CXX ?= g++
5757PREFIX ?= /usr/local
5858LLVM_CONFIG ?= llvm-config
59+
60+ ifneq ($(shell $(LLVM_CONFIG ) --version > /dev/null && echo OK) ,OK)
61+ $(error "Error : could not find or run llvm-config. Set LLVM_CONFIG to point to the llvm-config binary for the version of llvm you want to build Halide against, and set CLANG to point to the corresponding version of clang.")
62+ endif
63+
5964LLVM_COMPONENTS = $(shell $(LLVM_CONFIG ) --components)
6065LLVM_VERSION = $(shell $(LLVM_CONFIG ) --version | sed 's/\([0-9][0-9]* \) \.\([0-9]\).*/\1.\2/')
6166
@@ -64,7 +69,11 @@ LLVM_BINDIR = $(shell $(LLVM_CONFIG) --bindir | sed -e 's/\\/\//g' -e 's/\([a-zA
6469LLVM_LIBDIR = $(shell $(LLVM_CONFIG ) --libdir | sed -e 's/\\/\//g' -e 's/\([a-zA-Z]\) :/\/\1/g')
6570# Apparently there is no llvm_config flag to get canonical paths to tools,
6671# so we'll just construct one relative to --src-root and hope that is stable everywhere.
67- LLVM_SYSTEM_LIBS =$(shell ${LLVM_CONFIG} --system-libs --link-static | sed -e 's/[\/&]/\\&/g' | sed 's/-llibxml2.tbd/-lxml2/')
72+ LLVM_SYSTEM_LIBS = $(shell ${LLVM_CONFIG} --system-libs --link-static | sed -e 's/[\/&]/\\&/g' | sed 's/-llibxml2.tbd/-lxml2/')
73+ ifeq ($(UNAME ) , Darwin)
74+ # homebrew LLVM on macos likes to depend on things in /opt/homebrew/lib without explicitly adding that linker flag
75+ LLVM_SYSTEM_LIBS += -L$(shell brew --prefix | sed -e 's/[\/&]/\\&/g') \/lib
76+ endif
6877LLVM_AS = $(LLVM_BINDIR ) /llvm-as
6978LLVM_NM = $(LLVM_BINDIR ) /llvm-nm
7079# Note, removing -D_GLIBCXX_ASSERTIONS is a workaround for https://reviews.llvm.org/D142279
@@ -362,9 +371,24 @@ TEST_CXX_FLAGS += -DTEST_CUDA
362371TEST_CXX_FLAGS += -I/usr/local/cuda/include
363372endif
364373
365- # Compiling the tutorials requires libpng
366- LIBPNG_LIBS_DEFAULT = $(shell libpng-config --ldflags)
367- LIBPNG_CXX_FLAGS ?= $(shell libpng-config --cflags)
374+ # Find libjpeg and libpng. The code to set IMAGE_IO_LIBS is duplicated
375+ # in apps/support/Makefile.inc and any changes here should be repeated
376+ # there.
377+
378+ ifneq (,$(shell command -v brew) )
379+ # Get png and jpeg paths from brew
380+ LIBPNG_LIBS_DEFAULT = -L $(shell brew --prefix libpng) /lib -lpng
381+ LIBPNG_CXX_FLAGS ?= -I $(shell brew --prefix libpng) /include
382+ LIBJPEG_LIBS ?= -L $(shell brew --prefix libjpeg) /lib -ljpeg
383+ LIBJPEG_CXX_FLAGS ?= -I $(shell brew --prefix libjpeg) /include
384+ else
385+ # Get png and jpeg paths from pkg-config
386+ LIBPNG_LIBS_DEFAULT = $(shell pkg-config libpng --libs)
387+ LIBPNG_CXX_FLAGS ?= $(shell pkg-config libpng --cflags)
388+ LIBJPEG_LIBS ?= $(shell pkg-config libjpeg --libs)
389+ LIBJPEG_CXX_FLAGS ?= $(shell pkg-config libjpeg --cflags)
390+ endif
391+
368392# Workaround for libpng-config pointing to 64-bit versions on linux even when we're building for 32-bit
369393ifneq (,$(findstring -m32,$(CXX ) ) )
370394ifneq (,$(findstring x86_64,$(LIBPNG_LIBS_DEFAULT ) ) )
@@ -373,17 +397,6 @@ endif
373397endif
374398LIBPNG_LIBS ?= $(LIBPNG_LIBS_DEFAULT )
375399
376- # Workaround brew Cellar path for libpng-config output.
377- LIBJPEG_LINKER_PATH ?= $(shell echo $(LIBPNG_LIBS_DEFAULT ) | sed -e'/-L.* [/][Cc]ellar[/]libpng/!d;s=\(.* \) /[Cc]ellar/libpng/.*=\1/lib=')
378- LIBJPEG_LIBS ?= $(LIBJPEG_LINKER_PATH ) -ljpeg
379-
380- # There's no libjpeg-config, unfortunately. We should look for
381- # jpeglib.h one directory level up from png.h . Also handle
382- # Mac OS brew installs where libpng-config returns paths
383- # into the PNG cellar.
384- LIBPNG_INCLUDE_DIRS = $(filter -I% ,$(LIBPNG_CXX_FLAGS ) )
385- LIBJPEG_CXX_FLAGS ?= $(shell echo $(LIBPNG_INCLUDE_DIRS ) | sed -e'/[Cc]ellar[/]libpng/!s=\(.* \) =\1/..=;s=\(.*\)/[Cc]ellar/libpng/.*=\1/include=')
386-
387400IMAGE_IO_LIBS = $(LIBPNG_LIBS ) $(LIBJPEG_LIBS )
388401IMAGE_IO_CXX_FLAGS = $(LIBPNG_CXX_FLAGS ) $(LIBJPEG_CXX_FLAGS )
389402
0 commit comments