Creating a makefile

Go To Last Post
8 posts / 0 new
Author
Message
#1
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Hello,

I wanted to ask if you can recommend me any tutorial or a guide how to build a makefile for my (semi-awesome ;-) ) project so that I am able to share it with you in projects section of this web.

So far I used Code::Blocks as a programming IDE with its default compilation options (I only added external library and some compile flags but it was all in the C::B interface).

 

I have found multiple templates for AVR makefiles but with no explanation and the sintax was not always clear to me. Therefore I am not sure if the templates are actually usable by me.

Also is there some major difference between windows (mingw avr-gcc) and ubuntu (avr-gcc libc)  regarding the makefile?

 

 

P.S. Should I even bother to share it? :-) It is some sort of macro-HID-keyboard based on v-usb library with attiny85 mcu + a poorly programmed data uploader for this device designed for linux libusb-1.0.

This topic has a solution.
Last Edited: Fri. Nov 24, 2017 - 06:05 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 1

Surely the way Code::Blocks works (like most IDEs) is that from the project options you set it then auto-creates "makefile" then hands this on the "make" to be built?

 

But if that isn't how C::B does it then on the subject of writing Makefiles from scratch "Just Say No!". There are too many subtle details you won't think of if you start from scratch. If you want a makefile for AVR then get Mfile and let that create the Makefile for you. The template it uses has the combined knowledge of a load of avr-gcc gurus from several years of experience so they have "got it right". So re-use their knowledge - don't try to go it alone.

 

As for the syntax in Makefiles, the fact is that the user manuals for most "open source" programming utilities are pretty atrocious but the one for GNU make is a real exception. It's well written and easy to understand. It gets technical later but read the first few chapters and it's difficult to go wrong.

 

BTW two key concepts in Makefiles:

 

1) the commands under a rule MUST be indented with tabs (not spaces)

 

2) A Makefile is a bit like a C program - you don't (usually) just read them from top to bottom. In C you find main(), then you find what it calls, then you find what they call and so on to follow a "hierarchy". Makefiles are also hierarchical like this so don't just read them as a linear list of rules from top to bottom. Find the entry rule - then the rules that invokes, then the rules those invoke and so on.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thank you. I think this will help me.

Since I know very little about makefiles I didn't really know where to start. I can sometimes see which build options are available but not to a degree to modify or even create one.

 

This reply has been marked as the solution. 
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Start with mfile https://spaces.microchip.com/gf/...

(I honestly have no idea how to download except having svn)

originally at http://www.sax.de/~joerg/mfile/ and available also as part of WinAVR (which is still worth having as a package, even if somewhat dated -  at least for its decent set of *nix tools and - and unless using any supermodern AVRs or wish to use the named address spaces which weren't mature back then - it's still a decent compiler there).

 

If you don't manage to run it, you can simply take the sample makefile as a template and modify it manually for your purposes. Use an editor preserving tabs.

 

If you happen to understand Slovak (fat chance ;-) ) here http://www.efton.sk/tmp/makefile... is some random makefile explained.

 

JW

 

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

http://www.efton.sk/tmp/makefile... perhaps slightly better translation than using guggle's... ;-)

 

Comments welcome.

 

JW

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

wek3 wrote:
If you happen to understand Slovak (fat chance ;-) )

Tak pravda, není to úplně moje mateřština. ;-)

 

I will dig into it. Thanks.

  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Whata.... I didn't see this coming! :-)

 

So you might also read this https://www.bastl.sk/make-tajoms... ,  certainly this http://mcu.cz/news.php?extend.1288 , and I hope you'll enjoy this http://mcu.cz/news.php?extend.1292 even if it is more on the literary side than factual ;-)

 

And, in case of doubts, you can always drop in to the mikrozone.sk chatroom and ask there. We are always ready to provide useless advice and ironic comments :-D

 

Jano Waclawek

 

Last Edited: Fri. Nov 24, 2017 - 09:33 PM
  • 1
  • 2
  • 3
  • 4
  • 5
Total votes: 0

Thanks to your help I was able to use mfile to add a makefile to my project. And it compiled without error.

 

If you want to look at it I uploared it to Projects section of this web:

https://community.atmel.com/projects/v-usb-hid-macro-keyboard