2.5. Letting Make Build the Project

Rather than type these commands over and over, they can all be placed in a make file. To build the demo project using make, save Example 2-4 in a file called Makefile.

Example 2-4. Makefile for Demo Project

    CC=avr-gcc
    OBJCOPY=avr-objcopy
    
    CFLAGS=-g -mmcu=at90s2313
    
    rom.hex : demo.out
    	$(OBJCOPY) -j .text -O ihex demo.out rom.hex
    
    demo.out : demo.o
    	$(CC) $(CFLAGS) -o demo.out -Wl,-Map,demo.map demo.o
    
    demo.o : demo.c
    	$(CC) $(CFLAGS) -Os -c demo.c