Skip to content

Instantly share code, notes, and snippets.

@good5dog5
Last active August 29, 2015 14:16
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save good5dog5/cba057d2b1476424af7f to your computer and use it in GitHub Desktop.
Save good5dog5/cba057d2b1476424af7f to your computer and use it in GitHub Desktop.
# Some pre-defined variables of make
#
# $? - updated dependencies
# $@ - target value
# $< - first dependencie
# $^ - all dependencies, seperated with space
# $* - target name without extension
#
CC = arm-linux-gnueabihf-gcc
AS = arm-linux-gnueabihf-as
CFLAGS = -O2 -ggdb -Wall
LDFLAGS = -fno-stack-protector
objects = example2.o multiply.o
# 1. The final target, and let make search for example2
default: example2
.PHONY: default clean clobber
# 2. Find example2, and it depends on example2.o and multiply.o.
# 6. All dependencies make, compile - assemble - link -> executable.
# - Until the link moment, extern function multiply(), multiplyadd(), multiplysub() 's address
# be bound.
example2: $(objects)
$(CC) -o $@ $^
# 3. Find the dependency to make example2.o, but does't know the rule.
example2.o: example2.c
# 4. Find the rules to make all .o file, example2.o, so
# - example2.o compiled
%.o: %.c
$(CC) -c $(CFLAGS) $(LDFLAGS) -o $@ $<
# 5. Find the rule to make multiply.o
%.o: %.s
$(AS) -o $@ $<
clean:
rm -f $(objects) example2
qemu: example2
qemu-arm -L /usr/arm-linux-gnueabihf ./example2
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment