Guide To Make For ARM Cross-Development
Guide To Make For ARM Cross-Development
Guide To Make For ARM Cross-Development
Make is a tool that automates building executable programs; a make le is a le that tells make what to do in order
to build the programs you want. As you will see soon enough, they make life as a computer science student a
whole lot smoother!
In this guide, we’ll learn about using make les for cross-development on the ARM architecture. We will brie y
review make le syntax and usage. For more information about make les, check out the CS107 Guide to Make les
(http://cs107.stanford.edu/guide/make.html) and other resources on the bottom of the page.
Below is a simple make le used to build a binary for the ARM processor.
NAME = blink
all: $(NAME).bin
%.bin: %.o
$(ARM)-objcopy $< -O binary $@
%.o: %.c
$(ARM)-gcc $(CFLAGS) -c $< -o $@
%.o: %.s
$(ARM)-as $(CFLAGS) -o $< $@
%.list: %.o
$(ARM)-objdump -d $< > $@
install: $(NAME).bin
rpi-install.py $<
clean:
rm -f *.o *.bin *.list
Now, this Make le may look a bit cryptic at rst! Let’s try breaking it down and see if this makes sense.
all: button.bin
button.bin: button.c
arm-none-eabi-gcc -Og -g -Wall -std=c99 -ffreestanding -c button.c -o button.o
arm-none-eabi-objcopy button.o -O binary button.bin
arm-none-eabi-objdump button.o -d > button.list
clean:
rm -f *.list *.bin *.o
Rules are written in terms of “you require dependencies on the right-hand-side to satisfy the need for our target
on the left-hand-side.” Here, we indicate: by default, make all; to do that, make button.bin .
http://cs107e.github.io/guides/make/ 1/3
16/1/2018 CS107E Guide to Make for ARM cross-development
all: button.bin
This brings us to the next rule, which tells us how to make button.bin . You may interpret this as requiring certain
ingredients (dependencies on the right-hand-side) to create the thing you want (target on the left-hand-side).
button.bin: button.c
The text which immediately follow the rule, or recipe for the rule, are commands necessary to turn the ingredients
( button.c in this case) into the nal product ( button.bin in this case). We also throw in a comment to explain the
additional ags included with our call to arm-none-eabi-gcc .
button.bin: button.c
arm-none-eabi-gcc -Og -g -Wall -std=c99 -ffreestanding -c button.c -o button.o
arm-none-eabi-objcopy button.o -O binary button.bin
arm-none-eabi-objdump button.o -d > button.list
The line below indicates what should happen when we make clean ; the keyword clean tells Make to run the
command below.
clean:
rm -f *.list *.bin *.o
NAME = blink
ARM = arm-none-eabi
all: $(NAME).bin
$(NAME).bin: $(NAME).c
$(ARM)-gcc $(CFLAGS) -c $(NAME).c -o $(NAME).o
$(ARM)-objcopy $(NAME).o -O binary $(NAME).bin
$(ARM)-objdump $(NAME).o -d > $(NAME).list
clean:
rm -f *.list *.bin *.o
So we’ve just added three macros up top. They’re similar to variables in that they put text in where you expect
them to go. Be sure to use the $(<macro_name>) syntax to access the value of the macro and allow string
concatenation. (Did you see what we did there with the ARM macro?) Phew, this saves us a lot of visual space!
Now, let’s introduce a few special rules here to replace our one rule for blink.bin .
http://cs107e.github.io/guides/make/ 2/3
16/1/2018 CS107E Guide to Make for ARM cross-development
% is a wildcard symbol when used in a rule; %.o for example matches any le that ends with .o
$@ refers to the left part of the rule, before the :
$< refers to the rst element in the right part of the rule, after the :
So, really, you can think of the make le as a big cookbook that culminates in the program you ultimately wish to
create.
For convenience, we can also throw in another rule so we don’t have to type in rpi-install.py blink.bin every time
we want to run our program on the Pi.
# The install target uploads freshly made binary image to rpi bootloader
install: $(NAME).bin
rpi-install.py $<
If you’d like to learn more, check out a Make le tutorial (http://www.opussoftware.com/tutorial/TutMake le.htm),
another Make le tutorial (http://www.delorie.com/djgpp/doc/ug/larger/make les.html), the CS107 Guide to
Make les (http://cs107.stanford.edu/guide/make.html), and the GNU Documentation about Compiler Options
(https://gcc.gnu.org/onlinedocs/gcc-4.2.2/gcc/C-Dialect-Options.html).
http://cs107e.github.io/guides/make/ 3/3