2

I have created a simple makefile i.e.

COMMON=hello
all:
  gcc $(COMMON).c -o $(COMMON).o

The directory in which I am running the makefile contains three files: hello.c add.c multiply.c factorial.c and subtraction.c.

When I am compiling this in the terminal using the make command, the hello gets printed. Now I want to make changes in the program such that when I write "make add" or "make multiply" or "make factorial", the corresponding program will compile.

user1511590
  • 71
  • 2
  • 5

1 Answers1

2

Just supply it on the command line.

make COMMON=bye

If the target is predictable from file names in the current directory, you don't really need a Makefile at all, because Make already knows how to make multiply from multiply.c.

.PHONY: all
all: hello add multiply factorial

If you really want an explicit recipe, try something like this.

%: %.c
        gcc -o $@ $^
tripleee
  • 175,061
  • 34
  • 275
  • 318
  • this thing i already know.......but if the user dont know "COMMON" is there in the file.............the user just want to use "make " to compile the program.... – user1511590 Jul 09 '12 at 11:57