Last active
August 29, 2015 14:01
-
-
Save chefe/8222ac1772f6a9ba61b2 to your computer and use it in GitHub Desktop.
Sample make file for cpp
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Setup make variables | |
CC=g++ | |
CFLAGS=-c -Wall -g -Iinc | |
LDFLAGS= | |
SOURCEDIR=src/ | |
OBJECTDIR=obj/ | |
BINDIR=bin/ | |
SOURCES=main.cpp | |
OBJECTS=$(SOURCES:.cpp=.o) | |
EXECUTABLE=main | |
CSOURCES=$(addprefix $(SOURCEDIR),$(SOURCES)) | |
COBJECTS=$(addprefix $(OBJECTDIR),$(OBJECTS)) | |
CEXECUTABLE=$(addprefix $(BINDIR),$(EXECUTABLE)) | |
# Build the whole executable | |
all : dir $(CEXECUTABLE) | |
# Link the object files to a executable together | |
$(CEXECUTABLE) : $(COBJECTS) | |
@$(CC) $(LDFLAGS) $^ -o $@ | |
# Compile the cpp files to obejct files | |
$(OBJECTDIR)%.o : $(SOURCEDIR)%.cpp | |
@$(CC) $(CFLAGS) $< -o $@ | |
# Create the needed directories | |
dir: | |
@mkdir -p $(OBJECTDIR) | |
@mkdir -p $(BINDIR) | |
# Clean the current build | |
clean: | |
@rm -rf $(OBJECTDIR) $(BINDIR) | |
# Run the created executable | |
run: all | |
@$(CEXECUTABLE) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment