Navneeth
Navneeth

Reputation: 423

GNU Make pattern rule issues

I'm trying to use GNU Make's pattern rules to automatically generate precompiled headers from a directory full of headers. However, despite the simplicity of this usage case, I'm getting errors.

HEADERS=$(patsubst %.h,%.h.gch,$(wildcard *.h))
CXX=g++
WARNINGS=-Wno-unused-result -Wall
WARNINGSH=-w
CFLAGS=-c -g -flto=8 -fuse-linker-plugin -Ofast -std=c++11 -pthread $(WARNINGS)
HFLAGS= $(CFLAGS) $(WARNINGSH)

all: $(HEADERS)

debug: CFLAGS=-c -g3 -ggdb -O0 -std=c++11 -pthread -DSTACK_TRACE $(WARNINGS) \
                -D_GNU_SOURCE
debug: HFLAGS=$(CFLAGS) $(WARNINGSH)
debug: clean all

%.h.ghc : %.h
    $(CXX) $(HFLAGS) $<

clean:
    rm -f *.gch

Running $ make results in the error

make: *** No rule to make target 'my_header.h.gch', needed by 'all'.  Stop.

What am I missing here?

Upvotes: 1

Views: 105

Answers (1)

iBug
iBug

Reputation: 37307

Here's the problem:

%.h.gch : %.h
     ^^
    $(CXX) $(HFLAGS) $<

Upvotes: 2

Related Questions