-1

Recently our project structure changed and now we have subdirectories. My old makefile assumed that and just said:

SOURCES := $(wildcard $(SRCDIR)/*.cpp)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)

Now with arbitrary deep nested directories it changed to

SOURCES := $(wildcard $(SRCDIR)/**/*.cpp)

But I still want all objects to land in the same directory, how would I have to change the OBJECTS ( or compile? ) definition so that it does not fail, because the given subdirectories don't exist in the objectdirectory.

edit: Someone flagged this as a duplicate of Getting make to create object files in a specific directory

Now I am asked as to say how this is different. Which i find insulting, since why should I provide the reason as to why this is a duplicate. Whoever flagged this as duplicate should provide the reason.

I don't even know where to begin as to why it is different. You might as well have linked me to some excel-question and ask my why it is different.

Explain to me why the linked question should answer my question and then I will tell you how it is or not is.

  • 1
    Possible duplicate of [Getting make to create object files in a specific directory](https://stackoverflow.com/questions/14639794/getting-make-to-create-object-files-in-a-specific-directory) – πάντα ῥεῖ Oct 31 '18 at 17:29
  • First, your statement `SOURCES := $(wildcard $(SRCDIR/**/*.cpp)` won't do what you might expect it to do (find all instances of `*.cpp` at all levels of directory under `$(SRCDIR)`). The `**` facility is an advanced type of globbing supported by some shells (like `zsh`) but it's not supported by the standard C `glob()` function which is what `make` uses for `wildcard`. Your globbing expression is identical in functionality to `$(SRCDIR)/*/*.cpp` (exactly one directory level). To find all files you need `$(shell find $(SRCDIR) -name \*.cpp)` – MadScientist Nov 01 '18 at 17:56
  • Second, I do agree that the linked duplicate question isn't quite the same thing, but it's not appropriate to be insulted by someone trying to answer your question when you asked for help. Perhaps you don't see how the referenced question applies, then you can ask for clarification, but there's no need to respond so aggressively. I would say that a better duplicate question would be: https://stackoverflow.com/questions/52974743/place-all-object-files-into-the-same-directory-for-a-distributed-sources-in-a-ma which actually gives the exact same answer as Beta provides below. – MadScientist Nov 01 '18 at 18:03

1 Answers1

1

No problem, just use a couple of the text manipulation functions:

OBJECTS := $(patsubst %.cpp,$(OBJDIR)/%.o,$(notdir $(SOURCES)))
Beta
  • 96,650
  • 16
  • 149
  • 150