Target pattern contains no '%'

I am new to Fortran and I am following the tutorial about build tools using make (Build tools ā€” Fortran Programming Language). While I am typing:

OBJS := tabulate.o: functions.o
PROG := my_prog

all: $(PROG)

$(PROG): $(OBJS)
	gfortran -o $@ $^

$(OBJS): %.o: %.f90
	gfortran -c -o $@ $<

(I do have the source files tabulate.f90 and functions.f90 ready, and I do use TAB for indentation rather than space) and run it with make, this error keeps showing:

makefile:6: *** target pattern contains no '%'.  Stop.

Does anyone know how I can fix it? Would this be a problem with Linux (Iā€™m using HPC provided by my institution)? Your help is really appreciated. Thanks.

1 Like

Welcome to the forum.

The second colon on the first line of the makefile should not be there.

2 Likes

Thank you for your help. I removed the colon and I found after re-reading the tutorial that I should write tabulate.o: functions.o as an individual line at the end of the code. So the correct one should look like

OBJS := tabulate.o functions.o
PROG := my_prog

all: $(PROG)

$(PROG): $(OBJS)
        gfortran -o $@ $^

$(OBJS): %.o: %.f90
        gfortran -c -o $@ $<

tabulate.o: functions.o

Thank you so much for the help!

It looks like you have it working, but in case there are other problems, here is a makefile that works with some different syntax.

OBJS=tabulate.o functions.o
PROG=my_prog

all: $(PROG)

$(PROG): $(OBJS)
        gfortran -o $@ $(OBJS)

.f90.o:  # free format default compile
        gfortran -o $@ -c $<

clean:
        rm -f *.o

.SUFFIXES: .f90 .o
.PHONY: all clean

I did not include the tabulate.o: functions.o dependency line. You would need that if functions.f90 creates modules that are required to compile tabulate.f90. Otherwise, the two files can be compiled in any order, so there would be no depenency line required.

Regarding the syntax, make has lots of quirky ways to do almost everything. Most people just find one of the ways that works for them, and then they stick with those conventions.

2 Likes