Skip to content

Instantly share code, notes, and snippets.

@satishgoda
Last active December 10, 2015 11:19
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save satishgoda/4427215 to your computer and use it in GitHub Desktop.
Save satishgoda/4427215 to your computer and use it in GitHub Desktop.
A simple Makefile that I have written and use for my toy projects. http://www.gnu.org/software/make/ http://www.gnu.org/software/make/manual/make.html
# Name of the project
# The binary file will use the name of the project!
PROJECT := $(shell basename $(shell pwd))
# Header files
HEADERS = -I../../util/
# C++ source files
SOURCES := $(shell find ./ -name "*.cpp")
# Object files corresponsing to the source files
OBJECTS := $(SOURCES:.cpp=.o)
# Compiler to use
CC = g++
# Flags to use while compiling
CFLAGS = -Wno-deprecated -c
# Compile, Link and Run the Project
all: $(PROJECT)
./$(<).exe
# Create the binary ($@) by linking the object files ($<) after compilation is done.
$(PROJECT): $(OBJECTS)
$(CC) $< -o $@
# Compile the source files ($<) into object files ($@)
.cpp.o:
$(CC) $(HEADERS) $(CFLAGS) $< -o $@
# Cleanup object and binary files.
clean:
@rm -fv *.o
@rm -fv *.exe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment