0

I have seen some examples of using makefile with multiple source directories but still could not implement it to my makefile.

Currently I have all source files at /src/ folder and I would like to be able compile subfolders in /src/ such as /src/modules.

I am using:

NAME = 'AI'
SRC = src
TGT = obj
PRG = application
INCLUDES = -Iinclude ...
LIBRARIES = -L ...
CXXFLAGS = -O2 -std=c++0x $(INCLUDES) $(LIBRARIES)
SOURCES = $(wildcard $(SRC)/*.cpp)
ENDFLAGS = -ljvm -lcurl
NOWARNINGS = -Wno-unused-variable -Wno-unused-result
OBJS = $(addprefix $(TGT)/, $(notdir $(SOURCES:.cpp=.o)))

$(TGT)/%.o: $(SRC)/%.cpp
    $(CXX) $(CXXFLAGS) -c $< -o $@ $(NOWARNINGS)

$(PRG)/$(NAME): $(OBJS)
    $(CXX) $(LIBRARIES) $(OBJS) -o $@ $(ENDFLAGS) $(NOWARNINGS)
Wagm
  • 309
  • 5
  • 12
  • What's the question here exactly? How to get those sub-directory source files into the `SOURCES` variable in your makefile? – Etan Reisner Dec 25 '15 at 14:58
  • I would like sub directories of SRC to be compiled too. – Wagm Dec 25 '15 at 15:56
  • Compiled into `$(TGT)` directly? Compiled into a mirrored sub-directory? Compiled into the current (Makefile) directory? Compiled next to the source file? – Etan Reisner Dec 25 '15 at 20:23
  • To compile them into `$(TGT)` directly you can just add `$(wildcard $(SRC)/sub-dir/*.cpp)` to the `SOURCES` assignment line and that should work. If you want something more automatic then look at [this answer](http://stackoverflow.com/a/18258352/258523). – Etan Reisner Dec 25 '15 at 20:26

0 Answers0