Skip to content

Instantly share code, notes, and snippets.

@koturn
Last active January 8, 2017 01:49
Show Gist options
  • Save koturn/8f6880acdfb769fa518cc69d5e2a408b to your computer and use it in GitHub Desktop.
Save koturn/8f6880acdfb769fa518cc69d5e2a408b to your computer and use it in GitHub Desktop.
簡易的なプログラムのためのMakefile
CXX := g++ -std=gnu++14
CXXFLAGS := -Wall -Wextra -O3 -march=native -DNDEBUG
LDFLAGS := -s
TARGET := hoge
SRCS := $(wildcard *.cpp *.cxx *.cc)
OBJS := $(foreach PAT,%.cpp %.cxx %.cc,$(patsubst $(PAT),%.o,$(filter $(PAT),$(SRCS))))
ifeq ($(OS),Windows_NT)
TARGET := $(addsuffix .exe, $(TARGET))
else
TARGET := $(addsuffix .out, $(TARGET))
endif
%.exe:
$(CXX) $(LDFLAGS) $(filter %.c %.cpp %.cxx %.cc %.o, $^) $(LDLIBS) -o $@
%.out:
$(CXX) $(LDFLAGS) $(filter %.c %.cpp %.cxx %.cc %.o, $^) $(LDLIBS) -o $@
.PHONY: all clean
all: $(TARGET)
$(TARGET): $(OBJS)
$(foreach SRC,$(SRCS),$(eval $(filter-out \,$(shell $(CXX) -MM $(SRC)))))
clean:
$(RM) $(TARGET) $(OBJS)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment