SRC = $(TARGET).c buffer.c uart.c
But as it is easy to predict, it again added all code from buffer.c and uart.c to my hex, and it became 2400 bytes instead of 400.
Yes - if you add the c files to your project then they will always get linked.
What you need to do is create a library of the files you download - ie it ends with
I'm not sure if your download already includes one - as the original link you gave seems to be broken. If the library file is there then fine. If not then you need to create a makefile in the library folder (or modify any existing one). The key part to change is:
Which says the final thing to create is the library file
Later in the makefile you need something like:
# make the library file from all of the object files
avr-ar -v -ru $(PRG).a $(OBJ)
Which creates the library file and adds all the compiled object files into it.
Now in your main project - you should really change the #include command to point to the files in their original location so that you dont copy the files around. Or you can pass additional source file paths for the compiler to search via. Cant remember how off the top of my head - worry about that later - so keep the copied header files in your project for now but delete the copied C files.
Now change the makefile for your project as follows:
1. Define a variable that points at the exact location where the library file got created - ie you will need to change this line to match what came out of the earlier makefile.
LIBS = ..\avrlib\lib.a
2. When creating the elf file you need to add the above library to the list of libraries that the linker will use
avr-gcc -o $@ $^ $(LIBS)
The linker will then only pull in the required code from your library file.
If this doesn't help then perhaps you could post the current makefile(s) for the library and for your project.
NB There is one thing to note with this approach:- If the library code compiles differently for different processors and CPU speeds then the compiler library file will be specific to the values at the time it was compiled. So if you then 'blow a fuse' and change your processor speed you may well need to recompile the libraries as well as your own code.