Skip to content

Commit 8b269a0

Browse files
authored
Merge pull request #3615 from ninjaguardian/homebrew-anywhere
[Fix] Detect homebrew directory
2 parents a73c345 + d9ea8bb commit 8b269a0

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

buildconfig/config_darwin.py

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import os
44
from distutils.sysconfig import get_python_inc
5+
from subprocess import check_output, CalledProcessError, DEVNULL
56

67

78
try:
@@ -136,16 +137,23 @@ def main(auto_config=False):
136137
])
137138

138139
print('Hunting dependencies...')
139-
incdirs = ['/usr/local/include', '/opt/homebrew/include']
140-
incdirs.extend(['/usr/local/include/SDL2', '/opt/homebrew/include/SDL2', '/opt/local/include/SDL2'])
140+
141+
homebrew_prefix = '/opt/homebrew'
142+
try:
143+
homebrew_prefix = check_output(['brew', '--prefix'], text=True, stderr=DEVNULL).strip()
144+
except (FileNotFoundError, CalledProcessError):
145+
pass
146+
147+
incdirs = ['/usr/local/include', f'{homebrew_prefix}/include']
148+
incdirs.extend(['/usr/local/include/SDL2', f'{homebrew_prefix}/include/SDL2', '/opt/local/include/SDL2'])
141149

142150
incdirs.extend([
143151
#'/usr/X11/include',
144152
'/opt/local/include',
145153
'/opt/local/include/freetype2/freetype']
146154
)
147155
#libdirs = ['/usr/local/lib', '/usr/X11/lib', '/opt/local/lib']
148-
libdirs = ['/usr/local/lib', '/opt/local/lib', '/opt/homebrew/lib']
156+
libdirs = ['/usr/local/lib', '/opt/local/lib', f'{homebrew_prefix}/lib']
149157

150158
for d in DEPS:
151159
if isinstance(d, (list, tuple)):

meson.build

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,21 @@ if plat == 'win' and host_machine.cpu_family().startswith('x86')
282282
install_data(dlls, install_dir: pg_dir, install_tag: 'pg-tag')
283283

284284
else
285-
bases = ['/usr/local', '/usr', '/opt/homebrew', '/opt/local']
285+
homebrew_prefix = '/opt/homebrew'
286+
287+
brew_cmd = find_program('brew', required: false)
288+
289+
if brew_cmd.found()
290+
result = run_command(brew_cmd, '--prefix', check: false)
291+
if result.returncode() == 0
292+
detected_prefix = result.stdout().strip()
293+
if detected_prefix != '' and fs.is_dir(detected_prefix)
294+
homebrew_prefix = detected_prefix
295+
endif
296+
endif
297+
endif
298+
299+
bases = ['/usr/local', '/usr', homebrew_prefix, '/opt/local']
286300
foreach inc_dir : bases
287301
foreach sub_inc : [
288302
'',

0 commit comments

Comments
 (0)