PDA

View Full Version : Makefile



serthy
31st July 2014, 12:30
Hey,
I'm currently learning how to build my apps without an IDE and I am currently at the point where typing all my source files into a makefile becomes annoying.
As I'm a novice at writing makefiles (and only read a few tuts about them and yet im tired of it) is there a way to have only one single toplevel makefile in my directory root and no others in my source-directories?
Or do I have to write a batch file that lists all my source files and auto-create the makefile from it then?

serthy
31st July 2014, 21:02
This is my current Makefile that only searches the top level directory in the src folder.
I want it to automatically search all subdirs in the src folder and link to one single exe.


APP_NAME = CoDstructor

SRC_DIR = src/cod
OBJ_DIR = obj
BIN_DIR = bin

INC_DIR = -Isrc

CXXFLAGS += -g
CXXFLAGS += -Wall
CXXFLAGS += -Werror
CXXFLAGS += -Wextra
CXXFLAGS += -pedantic
CXXFLAGS += -std=c++11

CXXFLAGS += $(INC_DIR)

LDFLAGS += -g
LDFLAGS += -static
LDFLAGS += -static-libstdc++
LDFLAGS += -static-libgcc

SOURCES = $(wildcard $(SRC_DIR)/*.cpp)
OBJS = $(addprefix $(OBJ_DIR)/,$(notdir $(SOURCES:.cpp=.o)))

$(OBJ_DIR)/%.o: $(SRC_DIR)/%.cpp
$(CXX) $(CXXFLAGS) -c $< -o $@

$(BIN_DIR)/$(APP_NAME): $(OBJS)
$(CXX) $(LDFLAGS) $(OBJS) -o $@