Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the Makefile Target `.c.o` for?

Someone recently mentioned the target .c.o in Makefiles for cross compatability, but I fail to understand its purpose. Can anyone clarify?

like image 526
chacham15 Avatar asked Feb 10 '12 19:02

chacham15


2 Answers

It's an old-fashioned suffix rule. The more up-to-date way to do it is to use a pattern rule:

%.o : %.c 
like image 148
Carl Norum Avatar answered Sep 21 '22 19:09

Carl Norum


It's a canned rule for translating .c files, i.e. C modules, to .o object files. It exists so you don't have to write this rule yourself and is parameterized by Make variables such as CC (the C compiler to use), CFLAGS (compiler flags), etc.

So, if you use this implicit rule to compile C modules and don't tinker with any Make variables, then the person building your code can specify a compiler and flags on the command line without editing the Makefile.

like image 26
Fred Foo Avatar answered Sep 21 '22 19:09

Fred Foo