Skip to content

Commit a3532fb

Browse files
authored
Check if AVR Toolchain exits in macOS
AVR Toolchain for macOS can also be installed from Microchip binaries in https://www.microchip.com/mplab/avr-support/avr-and-arm-toolchains-c-compilers
1 parent 4cd9f83 commit a3532fb

File tree

1 file changed

+36
-29
lines changed

1 file changed

+36
-29
lines changed

Makefile.common

Lines changed: 36 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -46,38 +46,45 @@ CFLAGS += -g
4646
CORE_CFLAGS = -DAVR_CORE=1
4747

4848
ifeq (${shell uname}, Darwin)
49-
# gcc 4.2 from MacOS is really not up to scratch anymore
50-
CC = clang
51-
AVR_ROOT := "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/"
52-
AVR := ${AVR_ROOT}/bin/avr-
53-
# Thats for MacPorts libelf
54-
ifeq (${shell test -d /opt/local && echo Exists}, Exists)
55-
ifneq (${shell test -d /opt/local/avr && echo Exists}, Exists)
56-
$(error Please install avr-gcc: port install avr-gcc avr-libc)
57-
endif
58-
ifneq (${shell test -d /opt/local/include/libelf && echo Exists}, Exists)
59-
$(error Please install libelf: port install libelf)
60-
endif
61-
CC = clang
62-
IPATH += /opt/local/include /opt/local/include/libelf
63-
LFLAGS = -L/opt/local/lib/
64-
AVR := /opt/local/bin/avr-
49+
# If AVR Toolchain was installed from Microchip binaries
50+
ifneq (, $(shell which avr-gcc))
51+
CC = clang
52+
AVR_ROOT := $(shell which avr-gcc | awk -F'bin/' '{ print $1 }')
53+
AVR := ${AVR_ROOT}/bin/avr-
6554
else
66-
# That's for Homebrew libelf and avr-gcc support
67-
HOMEBREW_PREFIX ?= /usr/local
68-
ifeq (${shell test -d $(HOMEBREW_PREFIX)/Cellar && echo Exists}, Exists)
69-
ifneq (${shell test -d $(HOMEBREW_PREFIX)/Cellar/avr-gcc/ && echo Exists}, Exists)
70-
$(error Please install avr-gcc: brew tap osx-cross/homebrew-avr ; brew install avr-libc)
55+
# gcc 4.2 from MacOS is really not up to scratch anymore
56+
CC = clang
57+
AVR_ROOT := "/Applications/Arduino.app/Contents/Java/hardware/tools/avr/"
58+
AVR := ${AVR_ROOT}/bin/avr-
59+
# Thats for MacPorts libelf
60+
ifeq (${shell test -d /opt/local && echo Exists}, Exists)
61+
ifneq (${shell test -d /opt/local/avr && echo Exists}, Exists)
62+
$(error Please install avr-gcc: port install avr-gcc avr-libc)
63+
endif
64+
ifneq (${shell test -d /opt/local/include/libelf && echo Exists}, Exists)
65+
$(error Please install libelf: port install libelf)
7166
endif
72-
ifneq (${shell test -d $(HOMEBREW_PREFIX)/Cellar/libelf/ && echo Exists}, Exists)
73-
$(error Please install libelf: brew install libelf)
67+
CC = clang
68+
IPATH += /opt/local/include /opt/local/include/libelf
69+
LFLAGS = -L/opt/local/lib/
70+
AVR := /opt/local/bin/avr-
71+
else
72+
# That's for Homebrew libelf and avr-gcc support
73+
HOMEBREW_PREFIX ?= /usr/local
74+
ifeq (${shell test -d $(HOMEBREW_PREFIX)/Cellar && echo Exists}, Exists)
75+
ifneq (${shell test -d $(HOMEBREW_PREFIX)/Cellar/avr-gcc/ && echo Exists}, Exists)
76+
$(error Please install avr-gcc: brew tap osx-cross/homebrew-avr ; brew install avr-libc)
77+
endif
78+
ifneq (${shell test -d $(HOMEBREW_PREFIX)/Cellar/libelf/ && echo Exists}, Exists)
79+
$(error Please install libelf: brew install libelf)
80+
endif
81+
CC = clang
82+
IPATH += $(HOMEBREW_PREFIX)/include
83+
LFLAGS = -L$(HOMEBREW_PREFIX)/lib/
84+
CFLAGS += -I/$(HOMEBREW_PREFIX)/include/libelf
85+
AVR_ROOT := $(firstword $(wildcard $(HOMEBREW_PREFIX)/Cellar/avr-libc/*/))
86+
AVR := $(HOMEBREW_PREFIX)/bin/avr-
7487
endif
75-
CC = clang
76-
IPATH += $(HOMEBREW_PREFIX)/include
77-
LFLAGS = -L$(HOMEBREW_PREFIX)/lib/
78-
CFLAGS += -I/$(HOMEBREW_PREFIX)/include/libelf
79-
AVR_ROOT := $(firstword $(wildcard $(HOMEBREW_PREFIX)/Cellar/avr-libc/*/))
80-
AVR := $(HOMEBREW_PREFIX)/bin/avr-
8188
endif
8289
endif
8390
else

0 commit comments

Comments
 (0)