Skip to content

Instantly share code, notes, and snippets.

@samuelsmal

samuelsmal/makefile

Last active Jun 16, 2016
Embed
What would you like to do?
Generic clang++ (or c++ for that matter) makefile with directory structure
# Requires the following project directory structure:
# /bin
# /obj
# /src
# Use 'make remove' to clean up the hole project
# Name of target file
TARGET = foooooooobar
CXX = clang++
CXXFLAGS = -std=c++11 \
-Weverything -Wall -Wextra -Werror -Wpointer-arith -Wcast-qual \
-Wno-missing-braces -Wempty-body -Wno-error=uninitialized \
-Wno-error=deprecated-declarations \
-pedantic-errors -pedantic \
-Os
LD = clang++ -o
LDFLAGS = -Wall -pedantic
SRCDIR = src
OBJDIR = obj
BINDIR = bin
SOURCES := $(wildcard $(SRCDIR)/*.cpp)
INCLUDES := $(wildcard $(SRCDIR)/*.h)
OBJECTS := $(SOURCES:$(SRCDIR)/%.cpp=$(OBJDIR)/%.o)
RM = rm -f
$(BINDIR)/$(TARGET): $(OBJECTS)
@$(LD) $@ $(LDFLAGS) $(OBJECTS)
@echo "Linking complete!"
$(OBJECTS): $(OBJDIR)/%.o : $(SRCDIR)/%.cpp
@$(CXX) $(CXXFLAGS) -c $< -o $@
@echo "Compiled "$<" successfully!"
.PHONY: clean
clean:
@$(RM) $(OBJECTS)
@echo "Cleanup complete!"
.PHONY: remove
remove: clean
@$(RM) $(BINDIR)/$(TARGET)
@echo "Executable removed!"
@samuelsmal

This comment has been minimized.

Copy link
Owner Author

@samuelsmal samuelsmal commented Jun 10, 2016

Thanks /u/Leandros99, /u/skoink and /u/dangerbird2.

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