Makefile question...

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

So, when I took over the Optiboot project, I inherited a makefile structure that includes rules like:

atmega168: TARGET = atmega168
atmega168: MCU_TARGET = atmega168
atmega168: CFLAGS += $(COMMON_OPTIONS)
atmega168: AVR_FREQ ?= 16000000L
atmega168: LDSECTIONS  = -Wl,--section-start=.text=0x3c00 -Wl,--section-start=.v
atmega168: $(PROGRAM)_atmega168.hex
atmega168: $(PROGRAM)_atmega168.lst

atmega328: TARGET = atmega328
atmega328: MCU_TARGET = atmega328p
atmega328: CFLAGS += $(COMMON_OPTIONS)
atmega328: AVR_FREQ ?= 16000000L
atmega328: LDSECTIONS  = -Wl,--section-start=.text=0x7e00 -Wl,--section-start=.version=0x7ffe
atmega328: $(PROGRAM)_atmega328.hex
atmega328: $(PROGRAM)_atmega328.lst

This is not a syntax/style that I'm used to.  Aren't things on the right side of a ":" supposed to be "dependencies" of the "targets" on the left?

I don't even think I understand what's supposed to happen if the same target is mentioned multiple times, even without the above dependency vs expression issue.

 

Does anyone have an explanation for what's going on?   Is there a good reason to use a syntax like this, or is it more likely to be a case of "the person who wrote the Makefile originally didn't really understand Make very well"?

 

My general observation is that Makefiles expand in complexity until no one really understands them any more :-(  (auto-generated Makefiles are worse, since they start out incomprehensible by mortals.)

 

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

from gnu make manual:

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

Thanks!

 

If a makefile generally builds only one target at a time, why would it need target-specific variables?

 

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

I like a small Makefile;) I would remove everything... wait I did remove everything.

 

https://github.com/epccs/RPUno/blob/master/Bootloader/Makefile

 

One advantage of a simple Makefile is CI. In my Travis setup, I just run the default (bionic) toolchain.

 

https://github.com/epccs/RPUno/blob/master/.travis.yml

 

so it is fast (well for Travis anyway).

 

https://travis-ci.org/epccs/RPUno/jobs/573255218

 

In the Makefile, I should add a test for the environment values so that they have a default if not provided. Then Travis could set them for each job (each line under the matrix heading of the travis.yml).