0

I am writing a simple device driver in Linux. In the makefile we normally write first line as

obj-m += hello.o 

where hello is the module written. I have seen in other makefiles the symbol += being replaced by := and some others. What is significant difference between the two and also what are the possible options?

Eldar Abusalimov
  • 24,387
  • 4
  • 67
  • 71
elyon
  • 9
  • 2
  • 2
    If you read the documentation for the `make` program, it will tell you exactly what the meaning of `:=` or `+=` means in the makefile. See for example the [GNU Make manual](http://www.gnu.org/software/make/manual/). – Some programmer dude Feb 08 '12 at 11:15
  • Ya sure will go through it. Thank you. – elyon Feb 08 '12 at 11:53

1 Answers1

2

Actually, Kbuild resets obj-m along with some other variables (see scripts/Makefile.build) before including user Makefile, so there is no difference between += and := assignments (assuming that there is the only hello.o line).

Personally I would prefer appending assignment (+=). This prevents some stupid errors like the following:

obj-m := hello.o
obj-m := world.o

If the last line is a copy-paste of the first one and you forget to change the assignment type to +=, then you'll get only world.o compiled (without hello.o).

I would also suggest you to read Kbuild documentation about how to write module makefiles.

Eldar Abusalimov
  • 24,387
  • 4
  • 67
  • 71