Some notes about makefiles

If you aren't familiar with linux programming or compilation chances are this might be the first time you have encountered makefiles. Makefiles and a necesary component of every project. They are a form of batch file or script, they contain all a list of all the steps needed to take your code and turn it into a .hex file to be sent to the AT90s2313. In this way they are a form of program themselves.

To compile the average project with WINAVR you run a program called "make.exe". This proram by default looks for a file called "makefile" (note: no extension as it originated in the Unix environment) and reads the contents of that file to know which actions to perform to compile your source code. The "make.exe" program performs the steps listed in the file "makefile" to run other programs (compilers, linkers, etc). The file "makefile" will also store the necessary command-line options that need to be specified when invoking other programs (compilers, linkers, etc). Thus it is entirely possible to not use a makefile and go through the process of manually running each program that needs to act upon your source code to generate the final .hex file to program into the AT90s2313. The advantage of the makefile is that you can store these repetative processes in a list called the makefile and have a program called "make.exe" do all the steps you've listed in the makefile.

If the thought of spending the time working out each step required to compile your program and the options that need to be specified at each step doesn't appeal to you then you are in luck. Most of the time, at least for simple programs, you can copy a makefile from somewhere else, modify the few lines that need changing and compile your source code. The AVRFreaks distribution of WINAVR has several makefiles already included in it. The one I will be using is located in the "sample" directory, for example "C:\WINAVR\sample\makefile". I have also included a copy here (right-click and "save as" if you want to download it)

For each project you need a separate copy the makefile with it. So when starting a new project for the examples here, do not forget to copy the above makefile into the same directory as your source files (mysource.c and  mysource.h for example). When you have you will need to edit just two lines to get simple programs to compile.

Firstly scroll down until you find these lines;

 # MCU name

 MCU = atmega128

and change them so that instead of the atmega128 being the target AVR the AT90s2313 is. For example

 # MCU name

 MCU = at90s2313

That was the first alteration. The other is just below this one where you see: 

 # Target file name (without extension).

 TARGET = main

This needs to be changed to reflect the name you have chosen for your main source file. For example if you were writing a program to control an LCD and called the .c source file "lcd.c" then you need to replace "main" with "lcd". For example: 

 # Target file name (without extension).

 TARGET = lcd

These two changes means you have directed the makefile to (1) compile for the AT90s2313 and (2) use your .c file to create the code. Now if you invoke "make.exe" program in the directory of you source code and your new makefile you (hopefully) will get no errors and have a .hex file ready for programming into the physical AT90s2313. If it does not work for you, double check you have set up the "path" variable correctly in windows so that it includes the make.exe file and that also the directory where you installed WinAVR is also on the "path" variable. These topics are covered in the installation guide that comes with the AVRFreaks WinAVR distribution (found here).

I also highly recommend reading through the beginning of the official 'GNU make' manual, http://www.gnu.org/software/make/manual/html_mono/make.html.gz