-
Notifications
You must be signed in to change notification settings - Fork 78
197 lines (153 loc) · 6.06 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
class AvrGccAT12 < Formula
desc "GNU compiler collection for AVR 8-bit and 32-bit Microcontrollers"
homepage "https://gcc.gnu.org/"
url "https://ftp.gnu.org/gnu/gcc/gcc-12.2.0/gcc-12.2.0.tar.xz"
mirror "https://ftpmirror.gnu.org/gcc/gcc-12.2.0/gcc-12.2.0.tar.xz"
sha256 "e549cf9cf3594a00e27b6589d4322d70e0720cdd213f39beb4181e06926230ff"
license "GPL-3.0-or-later" => { with: "GCC-exception-3.1" }
revision 3
head "https://gcc.gnu.org/git/gcc.git", branch: "master"
bottle do
root_url "https://github.com/osx-cross/homebrew-avr/releases/download/[email protected]_3"
sha256 arm64_sonoma: "ba0c8596203f126e5acb5795fe14180799b192920abd77c3c4f3962296e380dd"
sha256 ventura: "b87620c6e9d5fc0dc5b39e0ed0342e012b3a88a44c801c3be4ae11d918c4382f"
sha256 monterey: "484339713793087bd20767adb522fba3848423b3c407fd6ae8ae67e1afe63653"
end
# The bottles are built on systems with the CLT installed, and do not work
# out of the box on Xcode-only systems due to an incorrect sysroot.
pour_bottle? only_if: :clt_installed
keg_only "it might interfere with other version of avr-gcc.\n" \
"This is useful if you want to have multiple version of avr-gcc\n" \
"installed on the same machine"
option "with-ATMega168pbSupport", "Add ATMega168pb Support to avr-gcc"
# automake & autoconf are needed to build from source
# with the ATMega168pbSupport option.
depends_on "autoconf" => :build
depends_on "automake" => :build
depends_on "gmp"
depends_on "isl"
depends_on "libmpc"
depends_on "mpfr"
depends_on "osx-cross/avr/avr-binutils"
uses_from_macos "zlib"
# Branch from the Darwin maintainer of GCC, with a few generic fixes and
# Apple Silicon support, located at https://github.com/iains/gcc-12-branch
# macOS 13 with CLT 14.2 installed will fail due to missing support for
# -nodefaultrpath in clang. The patch seems to not be needed however.
on_macos do
if Hardware::CPU.arm? && (MacOS.version < :ventura)
patch do
url "https://raw.githubusercontent.com/Homebrew/formula-patches/1d184289/gcc/gcc-12.2.0-arm.diff"
sha256 "a7843b5c6bf1401e40c20c72af69c8f6fc9754ae980bb4a5f0540220b3dcb62d"
end
end
end
# GCC bootstraps itself, so it is OK to have an incompatible C++ stdlib
cxxstdlib_check :skip
current_build = build
resource "avr-libc" do
url "https://download.savannah.gnu.org/releases/avr-libc/avr-libc-2.1.0.tar.bz2"
mirror "https://download-mirror.savannah.gnu.org/releases/avr-libc/avr-libc-2.1.0.tar.bz2"
sha256 "0b84cee5c08b5d5cba67c36125e5aaa85251bc9accfba5773bfa87bc34b654e8"
if current_build.with? "ATMega168pbSupport"
patch do
url "https://raw.githubusercontent.com/osx-cross/homebrew-avr/d2e2566b06b90355952ed996707a0a1a24673cd3/Patch/avr-libc-add-mcu-atmega168pb.patch"
sha256 "7a2bf2e11cfd9335e8e143eecb94480b4871e8e1ac54392c2ee2d89010b43711"
end
end
end
def version_suffix
if build.head?
"HEAD"
else
version.major.to_s
end
end
def install
# GCC will suffer build errors if forced to use a particular linker.
ENV.delete "LD"
# Even when suffixes are appended, the info pages conflict when
# install-info is run so pretend we have an outdated makeinfo
# to prevent their build.
ENV["gcc_cv_prog_makeinfo_modern"] = "no"
languages = ["c", "c++"]
pkgversion = "Homebrew AVR GCC #{pkg_version} #{build.used_options*" "}".strip
args = %W[
--target=avr
--prefix=#{prefix}
--libdir=#{lib}/avr-gcc/#{version_suffix}
--enable-languages=#{languages.join(",")}
--with-ld=#{Formula["avr-binutils"].opt_bin/"avr-ld"}
--with-as=#{Formula["avr-binutils"].opt_bin/"avr-as"}
--disable-nls
--disable-libssp
--disable-shared
--disable-threads
--disable-libgomp
--with-dwarf2
--with-avrlibc
--with-system-zlib
--with-pkgversion=#{pkgversion}
--with-bugurl=https://github.com/osx-cross/homebrew-avr/issues
]
# Avoid reference to sed shim
args << "SED=/usr/bin/sed"
mkdir "build" do
system "../configure", *args
# Use -headerpad_max_install_names in the build,
# otherwise updated load commands won't fit in the Mach-O header.
# This is needed because `gcc` avoids the superenv shim.
system "make", "BOOT_LDFLAGS=-Wl,-headerpad_max_install_names"
system "make", "install"
end
# info and man7 files conflict with native gcc
rm_r(info)
rm_r(man7)
current_build = build
resource("avr-libc").stage do
ENV.prepend_path "PATH", bin
ENV.delete "CFLAGS"
ENV.delete "CXXFLAGS"
ENV.delete "LD"
ENV.delete "CC"
ENV.delete "CXX"
# avr-libc ships with outdated config.guess and config.sub scripts that
# do not support Apple ARM systems, causing the configure script to fail.
if OS.mac? && Hardware::CPU.arm?
ENV["ac_cv_build"] = "aarch64-apple-darwin"
puts "Forcing build system to aarch64-apple-darwin."
end
system "./bootstrap" if current_build.with? "ATMega168pbSupport"
system "./configure", "--prefix=#{prefix}", "--host=avr"
system "make", "install"
end
end
test do
ENV.delete "CPATH"
hello_c = <<~EOS
#define F_CPU 8000000UL
#include <avr/io.h>
#include <util/delay.h>
int main (void) {
DDRB |= (1 << PB0);
while(1) {
PORTB ^= (1 << PB0);
_delay_ms(500);
}
return 0;
}
EOS
hello_c_hex = <<~EOS
:10000000209A91E085B1892785B92FEF34E38CE000
:0E001000215030408040E1F700C00000F3CFE7
:00000001FF
EOS
hello_c_hex.gsub!("\n", "\r\n")
(testpath/"hello.c").write(hello_c)
system "#{bin}/avr-gcc", "-mmcu=atmega328p", "-Os", "-c", "hello.c", "-o", "hello.c.o", "--verbose"
system "#{bin}/avr-gcc", "hello.c.o", "-o", "hello.c.elf"
system "#{Formula["avr-binutils"].opt_bin}/avr-objcopy", "-O", "ihex", "-j", ".text", "-j", ".data", \
"hello.c.elf", "hello.c.hex"
assert_equal `cat hello.c.hex`, hello_c_hex
end
end