title: Writing a makefile for ARM project
body: <p>My project structure looks like:</p>
  
  <pre><code>.
  ├── build
  ├── src
  |   ├── rbpi
  |   |   └── gpio.h
  |   ├── boot.c
  |   ├── boot.s
  |   └── kernel.c
  └── linker.ld
  </code></pre>
  
  <p>This is a simple raspberry pi kernel that makes a LED blink!
  I currently use a simple bat file with the following content to build it:</p>
  
  <pre><code>arm-none-eabi-gcc -g -O0 -mfpu=neon-vfpv4 -mfloat-abi=hard -march=armv7-a -mtune=cortex-a7 -nostartfiles -Wl,-T,linker.ld src/kernel.c src/boot.c src/boot.s -o build/kernel.elf
  arm-none-eabi-objcopy build/kernel.elf -O binary build/kernel7.img
  </code></pre>
  
  <p>Since I will add more files to this project, I would have to append every file to my "buildscript".<br>
  If possible, I'd like to use a <code>makefile</code>.</p>
  
  <p><strong>How should my makefile look like if I want the following "rules"?</strong></p>
  
  <ul>
  <li>Before compilation, clean all <code>*.elf</code> and <code>*.img</code> files from the <code>build</code> directory.</li>
  <li>Compile all <code>*.c</code> and <code>*.s</code> files from the <code>src</code> directory.</li>
  <li>Output the <code>kernel.elf</code> file into the <code>build</code> directory.</li>
  <li>Use the linker script <code>linker.ld</code>.</li>
  <li>After compilation, run <code>objcopy</code> to generate a binary file.</li>
  </ul>