Results 1 to 2 of 2

Thread: Makefile

  1. #1
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts

    Makefile

    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?
    Last edited by serthy; 31st July 2014 at 12:32.

  2. #2
    Sergeant serthy's Avatar
    Join Date
    Nov 2012
    Posts
    450
    Thanks
    96
    Thanked 296 Times in 188 Posts
    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.

    Code:
    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 $@

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •