Skip to content

Instantly share code, notes, and snippets.

@eigenfoo
Last active November 9, 2017 03:01
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save eigenfoo/640a3633ccbcdc4636878adb8557a00d to your computer and use it in GitHub Desktop.
Save eigenfoo/640a3633ccbcdc4636878adb8557a00d to your computer and use it in GitHub Desktop.
C++ simple general-purpose Makefile
.PHONY: clean debug run
CXX = g++
CXXFLAGS = -std=c++11 -Wall -Wextra
LDFLAGS =
SOURCES = hash.cpp spellcheck.cpp
OBJECTS = $(SOURCES:.cpp=.o)
EXECUTABLE = spell.exe
all: $(SOURCES) $(EXECUTABLE)
$(EXECUTABLE): $(OBJECTS)
$(CXX) $(CXXFLAGS) -o $@ $(OBJECTS) $(LDFLAGS)
.cpp.o:
$(CXX) $(CXXFLAGS) -c $<
clean:
rm -rf $(EXECUTABLE) $(OBJECTS) debug.exe *.stackdump *~ *.dSYM/
debug:
$(CXX) $(CXXFLAGS) -g -o debug.exe $(SOURCES)
run:
./$(EXECUTABLE)
@eigenfoo
Copy link
Author

eigenfoo commented Sep 16, 2017

This Makefile should be adequate for most non-enterprise projects: only lines 3 through 9 need be edited for project-specific details.

See here and here for great crash courses on Makefiles.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment