From 3ddb370718a080d763e8895b76e57c645a8dbdb1 Mon Sep 17 00:00:00 2001
From: Anatolii Cherednichenko <greatestcombinator@gmail.com>
Date: Tue, 30 Aug 2022 00:57:46 +0300
Subject: [PATCH] Add support mac m1 and fix homebrew paths

In new Macbooks, homebrew has the /opt/homebrew patch, not /usr/local/
---
 Makefile.homebrew | 18 +++++++++++++++---
 1 file changed, 15 insertions(+), 3 deletions(-)

diff --git a/Makefile.homebrew b/Makefile.homebrew
index 88b2a9e2..c3f0c36a 100644
--- a/Makefile.homebrew
+++ b/Makefile.homebrew
@@ -1,5 +1,13 @@
+ARCH_TARGET ?= $(shell uname -m)
+
 # root directory holding homebrew
-BREWROOT = /usr/local
+ifeq ($(ARCH_TARGET),arm64)
+    BREWROOT = /opt/homebrew
+endif
+ifeq ($(ARCH_TARGET),amd64)
+    BREWROOT = /usr/local
+endif
+
 BOOSTROOT = ${BREWROOT}/opt/boost
 SSLROOT = ${BREWROOT}/opt/openssl@1.1
 UPNPROOT = ${BREWROOT}/opt/miniupnpc
@@ -34,8 +42,12 @@ endif
 # http://www.hutsby.net/2011/08/macs-with-aes-ni.html
 # Seems like all recent Mac's have AES-NI, after firmware upgrade 2.2
 # Found no good way to detect it from command line. TODO: Might be some osx sysinfo magic
-ifeq ($(USE_AESNI),yes)
-	CXXFLAGS += -D__AES__ -maes
+ifeq ($(ARCH_TARGET),amd64)
+    ifeq ($(USE_AESNI),yes)
+        CXXFLAGS += -D__AES__ -maes
+    else
+        CXXFLAGS += -msse
+    endif
 endif
 
 install: all