Flags in Makefile

Hello everyone! I have a problem about Makefile flags. It begins with that I cannot get the exact meaning of my task:
"The compiler flags -o0(letter o and digit 0), -o1, -o2, and -o3 set the level of optimization from none to highest. Write a makefile that automatically generates four different programs matmul-o0, matmul-o1, matmul-o2, and matmul-o3 which are compiled using the respectively options. Make sure you also use -Wall." And where matmul.cc is given, but it is a file that with some mistakes. Firstly, I used submakefiles to generate programs with different flags, but the -o0 to -o3 didn't work. Then I tried to generates the programs in one makefile as:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
#makefile

CXX=g++
CXXFLAGS=-Wall
FLAGS=-o
TARGETS=matmul-o0 matmul-o1 matmul-o2 matmul-o3

all:$(TARGETS)

$(TARGETS):matmul.cc
	$(CXX) $(CXXFLAGS) $< $(FLAGS) $@

clean:
	rm -f $(TARGETS)


It works but with the same flag -o.

Then I tried:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#makefile

CXX=g++
CXXFLAGS=-Wall
TARGETS=matmul-o0 matmul-o1 matmul-o2 matmul-o3

all : $(TARGETS)

matmul-o0 : matmul.o
        $(CXX) $< -o0 $@

matmul-o1 : matmul.o
        $(CXX) $< -o1 $@

matmul-o2 : matmul.o
	$(CXX) $< -o2 $@

matmul-o3 : matmul.o
	$(CXX) $< -o3 $@

matmul.o : matmul.cc
	$(CXX) $(CXXFLAGS) -c $^

clean : 
	rm -f $(TARGETS)


Then it does not work as the flags are invalid. I also tried to use for-loop but did not work either.

I am confused about the requirements of the task now. Could you please give me some hints?

Thank you so much!
I think the o should be capitalized?
(So -O1, -O2, -O3, etc.)
It still does not work...
I wonder if it is a problem of the system? I use Ubuntu, but maybe it will work with SUSE?
What about
$(CXX) $< -O0 -o $@
instead of
$(CXX) $< -o0 $@
and so forth?
Oh! It works!!! Thank you soooo much!!!!!!!!!!!! @long double main
I should read my material carefully and make sure about the meaning of "FLAGS"...
Thank you again! And happy New Year!
I think that you need to put the -O flags at compilation time
Yes, I wrote linking and compilation in the same line then. And I think my mistake was using the small letter o. And would you please tell me the details of "echo" in makefile?
Topic archived. No new replies allowed.