I have a problem with a makefile that I was not able to resolve. I have this structure of files and folders.
├───bin
├───include
│ des.hh
│ des_CR.hh
│ des_CX.hh
│ des_JAK.hh
│ des_JK.hh
│ des_testbench.hh
│ des_VA1.hh
│
├───obj
└───src
des.cc
des_CR.cc
des_CX.cc
des_JAK.cc
des_JK.cc
des_testbench.cc
des_VA1.cc
main_des.cc
I write the makefile in this way (here I put a small part):
DESIGN_NAME=des
FULL_NAME=$(basename $(shell find ./src -name $(DESIGN_NAME)'_[A-Z]*.cc' -type f -printf "%f\t"))
EXECUTABLE=bin/$(DESIGN_NAME).x
SYSTEMC=$$SYSTEMC_HOME
LIBDIR = $(SYSC_LIBDIR)
LIBS = $(SYSC_LIBDIR)/libsystemc.a -lpthread
INCDIR = -I./include/ -I. -I$(SYSTEMC)/include/
CXX=g++
CFLAGS= -c
$(EXECUTABLE): obj/main_$(DESIGN_NAME).o obj/$(DESIGN_NAME)_testbench.o obj/$(FULL_NAME).o obj/$(DESIGN_NAME).o
@echo Building $@
$(CXX) -g $(INCDIR) -o $@ $^ $(LIBDIR)/libsystemc.a -lpthread
obj/main_$(DESIGN_NAME).o: src/main_$(DESIGN_NAME).cc
@echo Building $@
$(CXX) -g $(CFLAGS) $(INCDIR) -o $@ $<
obj/$(DESIGN_NAME)_testbench.o: src/$(DESIGN_NAME)_testbench.cc include/$(DESIGN_NAME)_testbench.hh
@echo Building $@
$(CXX) -g $(CFLAGS) $(INCDIR) -o $@ $<
obj/$(FULL_NAME).o: src/$(FULL_NAME).cc include/$(FULL_NAME).hh
@echo Building $@
$(CXX) -g $(CFLAGS) $(INCDIR) -o $@ $<
obj/$(DESIGN_NAME).o: src/$(DESIGN_NAME).cc include/$(DESIGN_NAME).hh
@echo Building $@
$(CXX) -g $(CFLAGS) $(INCDIR) -o $@ $<
The variable FULL_NAME is used to get a list of all files that starts with "des_" and compile them. All works, except for the fact that when FULL_NAME contains more file names, as it will be, it says this:
g++ src/des_CX.cc -o src/des_CX
src/des_CX.cc:1:29: fatal error: des_CX.hh: No such file or directory
compilation terminated.
<builtin>: recipe for target 'src/des_CX' failed
make: *** [src/des_CX] Error 1
Every cc file has an include directive like this (obviously with the corresponding correct name):
#include "des_CX.hh"
I repeat, it works if FULL_NAME has only one name, as the other variable, if it has more than one it returns the error.
Any suggestions? Maybe someone knows a better way to get file names, this is an attempt that i made but I'm not sure that it is correct, probably the error is here. Thank you in advance and sorry for the long message.