I am trying to use vpath in my Makefile to avoid prefixing every source file with directory name. But I can't get it to work properly.
Here's the Makefile:
CC=gcc -Wall
vpath %.h include
vpath %.c src
all: main.c Event.o Macros.h
$(CC) $< Event.o -o test/a.out
Event.o: Event.c Event.h Macros.h
$(CC) -c $< -o $@
The src directory is being included correctly. i.e Event.c file is found by gcc. But both Event.h and Macros .h are not. I get an errors in gcc saying that both files were not found when compiling Event.c.
I tried changing the #include directive in my C file to each of these at a time.
#include "Event.h" /* doesnt work */
#include <Event.h> /* doesnt work */
#include "../include/Event.h" /* works */
Can you please help me with this problem ? I really want to avoid using directory names before every source file as my actual Makefile is bigger than this.