user80641: Note: This is a reference question (but feel free to write answers of your own!)

I want to use the AVR tools directly -- no arduino-builder or arduino-cli. I would also like compilation and uploading to be as fast as reasonably possible

user80641: 
Create a new file called Makefile in your project directory. Populate it with the following contents:

TEMPDIR := $(shell mktemp -d)

all:
    avr-g++ -DF_CPU=<CLK> -mmcu=<PARTNO> -fno-threadsafe-statics -O3 -flto -std=c++23 -isystem/usr/avr/include -lm -fuse-linker-plugin -Wl,--gc-sections *.cpp -o ${TEMPDIR}/a.elf

    avr-objcopy -O ihex -R .eeprom ${TEMPDIR}/a.elf ${TEMPDIR}/a.hex
    avrdude -V -p<PARTNO> -carduino -P/dev/tty<SERIAL_PORT> -b<BAUD> -D -Uflash:w:${TEMPDIR}/a.hex

    rm ${TEMPDIR}/a.elf ${TEMPDIR}/a.hex
    rm -d ${TEMPDIR}


In the Arduino IDE, press Ctrl+, and enable verbose output during compilation and uploading.
Start uploading with Ctrl+U. Replace the groups of angled brackets in Makefile (e.g. <CLK>) with the values in the Arduino IDE's build output.
Run make.

-lm links in the AVR math library. *.cpp refers to your c++ source files. -V prevents avrdude from reading back the flash contents and verifying it, which saves time, but you may want to disable it while diagnosing problems.

80641: <p><em>Note: This is a reference question (but feel free to write answers of your own!)</em></p>
<hr />
<p>I want to use the AVR tools directly -- no arduino-builder or arduino-cli. I would also like compilation and uploading to be as fast as reasonably possible</p>
 80641: <ol>
<li>Create a new file called <code>Makefile</code> in your project directory. Populate it with the following contents:</li>
</ol>
<pre><code>TEMPDIR := $(shell mktemp -d)

all:
    avr-g++ -DF_CPU=&lt;CLK&gt; -mmcu=&lt;PARTNO&gt; -fno-threadsafe-statics -O3 -flto -std=c++23 -isystem/usr/avr/include -lm -fuse-linker-plugin -Wl,--gc-sections *.cpp -o ${TEMPDIR}/a.elf

    avr-objcopy -O ihex -R .eeprom ${TEMPDIR}/a.elf ${TEMPDIR}/a.hex
    avrdude -V -p&lt;PARTNO&gt; -carduino -P/dev/tty&lt;SERIAL_PORT&gt; -b&lt;BAUD&gt; -D -Uflash:w:${TEMPDIR}/a.hex

    rm ${TEMPDIR}/a.elf ${TEMPDIR}/a.hex
    rm -d ${TEMPDIR}
</code></pre>
<ol start="2">
<li>In the Arduino IDE, press <kbd>Ctrl</kbd>+<kbd>,</kbd> and enable verbose output during compilation and uploading.</li>
<li>Start uploading with <kbd>Ctrl</kbd>+<kbd>U</kbd>. Replace the groups of angled brackets in Makefile (e.g. <code>&lt;CLK&gt;</code>) with the values in the Arduino IDE's build output.</li>
<li>Run <code>make</code>.</li>
</ol>
<p><code>-lm</code> links in the AVR math library. <code>*.cpp</code> refers to your c++ source files. <code>-V</code> prevents avrdude from reading back the flash contents and verifying it, which saves time, but you may want to disable it while diagnosing problems.</p>
