avr-gcc-list
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [avr-gcc-list] makefile for ubuntu


From: David Kelly
Subject: Re: [avr-gcc-list] makefile for ubuntu
Date: Thu, 13 Oct 2005 22:04:31 -0500


On Oct 13, 2005, at 9:02 PM, Patrick Blanchard wrote:

On Thu, 2005-10-13 at 20:10 -0500, David Kelly wrote:

You lost me in "linux tooling process".

I have yet to find 2 linux boxes 'tooled' the same way.

Agreed. Thats no small part of the reason I Don't Do Linux. No point in putting up with that headache when there are solutions which are cheaper and better.

The Makefile I sent to Vincent
which was reposted here yesterday works unchanged on WinAVR, FreeBSD,
and undoubtedly on Vincent's Linux.

It will probably work, but only until Vincent tries it on his own linux
box (which is different from my linux box(es)) will he be undoubtedly
certain that it works or not. And if it doesn't work, it might get him
so frustrated that he gives up linux for good.

No, Vincent posted his own slightly revised version. It did exactly the opposite of what you suggest. Where originally he was searching for an IDE to magically "handle it", else write a script to handle the repetitive build steps, a simple yet full featured Makefile made a convert of him.

I couldn't write an advanced makefile like you did.

Sure you could. Read the Makefile Vincent posted, its very top-to- bottom and straightforward. Its nothing compared to those used to build FreeBSD and/or FreeBSD ports.

Some comments:

This line mostly came from one of Joerg's Makefiles. The big change is that eeprom skips the first address and starts at 0x0001.

LDFLAGS= -Wl,-Map,address@hidden -Wl,--section-start=.eeprom=00810001

This is something that aids when cross compiling. A blank .SUFFIXES: line erases Make's default suffixes list. Listing suffixes appends to the existing list:

.SUFFIXES:
.SUFFIXES: .c .o .bin .elf .hex .srec .cof .list

Use the macros $(CC) and $(CFLAGS) to turn .c's into .o's:

.c.o:
        $(CC) $(CFLAGS) -c $<

Pretty much the same as above but in GNU Make syntax. Turns .elf's into _flash.hex's:

%_flash.hex: %.elf
        avr-objcopy -j .text -j .data -O ihex $< $@

We previously defined a list of source files in $(SRCS). This substitutes .o for .c and makes a list of $(OBJS):

OBJS = $(SRCS:.c=.o)

This is the first target for Make. Says that "all" needs the listed files. Just make sure a file named "all" doesn't exist because if it does then nothing will happen if all is newer than the listed files and the files the listed files depend on:

all:    object.elf object.list object_flash.hex object_eeprom.hex

Above "all:" needs object.elf. So here is an object.elf target saying it depends on $(OBJS). And if something in $(OBJS) is newer then do the following 2 lines:

object.elf: $(OBJS)
        $(CC) -o $@ $(CFLAGS) $(LDFLAGS) $(OBJS) $(LDLIBS)
        avr-size $@

This is the part I had the most trouble with. The target "depend:" will invoke gcc in a special way that gcc writes to stdout in Makefile format the target files and all included files used to compile the target.

You could manually tell make that main.o depends on myintdefs.h, myglobals.h, ... or you can let gcc figure that out for you:

# BSD make automatically reads .depend if it exists
depend: clean $(SRCS)
        $(CC) -E -M $(SRCS) > .depend

In BSD make the following include is implied. BSD make will silently include a .depend file if one is found. GNU make will not. But the problem is that if .depend does not exist then "include .depend" will cause a fatal abort preventing one from doing "make depend" to create .depend. Catch-22. Then I learned of "-include" which will fail silently and non-fatally if the specified file does not exist. The irony of the situation is that this breaks BSD Make. "-include" is not accepted in BSD. So having broke BSD make I later added the "% _flash.hex: %.elf" stuff above which is also totally non-BSD. I have GNU Make installed as gmake on my BSD system.

A .depend file isn't really necessary. Its just a Very Nice Thing To Have. Makes it easy to edit a .h file and have the correct files rebuilt rather than "make clean" && "make all" to brute force build. But the above goes even deeper, it lists all of the required *system* includes, recursively, down the the last one. Update avr-libc and Make will notice.

# -include fails silently in GNU Make if .depend does not exist
# OTOH -include is not BSD Make compatible.
-include .depend

Other than the lack of GNU Make on default BSD machines there isn't one thing above preventing the Makefile from working perfectly on Linux, WinAVR, FreeBSD, or MacOS.

--
David Kelly N4HHE, address@hidden
========================================================================
Whom computers would destroy, they must first drive mad.





reply via email to

[Prev in Thread] Current Thread [Next in Thread]