Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What does wildcard mean in makefile?

Tags:

makefile

I found the following lines in a makefile tutorial, but I have some problem with the bold lines.

In 1 line, if I write

program_C_SRCS:=$(*.c)

it does not work. So please tell me what is wildcard word in doing here. Is this word is specific to the makefile only?

In tutorial it is written that second line will perform the test substitution. Can anyone tell me something about this text substitution?

Please excuse me if my questions are very basic because I am new to make filestuff.

link of tutorial

CC:=g++
program_NAME:=myprogram
**program_C_SRCS:=$(wildcard *.c)**  # 1 line 
program_CXX_SRCS:=$(wildcard *.cc)
**program_C_OBJ:=$(program_C_SRCS:.c=.o)** # 2 line
program_CXX_OBJ:=$(program_CXX_SRCS:.c=.o)
program_OBJ:= $(program_C_OBJ) $(program_CXX_OBJ)
like image 539
Abhishek Gupta Avatar asked Jun 25 '12 06:06

Abhishek Gupta


People also ask

What does $() mean in makefile?

The $@ and $< are called automatic variables. The variable $@ represents the name of the target and $< represents the first prerequisite required to create the output file.

What is include in makefile?

The include directive tells make to suspend reading the current makefile and read one or more other makefiles before continuing. The directive is a line in the makefile that looks like this: include filenames … filenames can contain shell file name patterns.

What is makefile target?

A simple makefile consists of “rules” with the following shape: target … : prerequisites … recipe … … A target is usually the name of a file that is generated by a program; examples of targets are executable or object files. A target can also be the name of an action to carry out, such as ' clean ' (see Phony Targets).


2 Answers

Suppose you have two source files. foo.c and bar.c.

program_C_SRCS:=$(wildcard *.c) # 1 line

The wildcard function is Make syntax. The variable program_C_SRCS will now have the value foo.c bar.c (maybe not in that order).

program_C_OBJ:=$(program_C_SRCS:.c=.o) # 2 line

This is a substitution reference. It transforms text, replacing one substring with another. The variable program_C_OBJ now has the value foo.o bar.o.

like image 179
Beta Avatar answered Oct 12 '22 03:10

Beta


The use of wildcard card function in make file is to list all the source files with a particular extension. For example:

program_C_SRCS:=$(*.c) // In this the variable program_C_SRCS will have all the files with ".c" extension.

Suppose if you want to convert .c files to .o files then the following syntax may be useful:

program_C_OBJS:=$(patsubst %.c,%.o,$(wildcard *.c))
like image 31
user3709665 Avatar answered Oct 12 '22 05:10

user3709665