Skip to content

Instantly share code, notes, and snippets.

@hschlichter
Last active August 23, 2016 09:03
Show Gist options
  • Save hschlichter/31284857882cedcd0c95df45b917f3b4 to your computer and use it in GitHub Desktop.
Save hschlichter/31284857882cedcd0c95df45b917f3b4 to your computer and use it in GitHub Desktop.
Simple makefile for building C/C++ programs.
CC = clang++
CFLAGS = -std=c++14 -O0 -g -Wall -MMD
LDFLAGS =
INCLUDE = -I.
LDINCLUDE =
SRCS = main.cpp\
helper.cpp
OUTDIR = ./out
OBJS = $(foreach obj, $(SRCS:.cpp=.o), $(OUTDIR)/$(obj))
# Main build rules.
.PHONY: all
all: $(OBJS)
$(CC) $^ -o $(OUTDIR)/main $(CFLAGS) $(INCLUDE) $(LDINCLUDE) $(LDFLAGS)
$(OBJS): $(OUTDIR)/%.o: %.cpp
$(CC) -c $(CFLAGS) -o $@ $< $(INCLUDE)
-include $(OBJS:%.o=%.d)
# Clean rules
.PHONY: clean
clean:
@rm -rf $(OUTDIR)
@mkdir $(OUTDIR)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment