Skip to content

Instantly share code, notes, and snippets.

@YuukiTsuchida
Created September 15, 2016 04:29
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YuukiTsuchida/a6a0a93c66ec98735162f88df3eda6f8 to your computer and use it in GitHub Desktop.
Save YuukiTsuchida/a6a0a93c66ec98735162f88df3eda6f8 to your computer and use it in GitHub Desktop.
.PHONY ターゲット
ターゲット: 依存ファイル
[実行コマンド]
% make ターゲット
.cpp.o:
コマンド
.PHONY: debug
debug: main.o sub1.o
clang++ main.o sub1.o
.cpp.o:
clang++ -c -std=c++14 -O3 -g $<
CC=clang++
SRCS=main.cpp sub1.cpp
EXE_FILE=exe_
CXXFLAGS=-c -std=c++14
OBJS=$(SRCS:.cpp=.o)
DEFINE=NDEBUG
.PHONY: debug
debug: EXE_FILE=exe_debug
debug:CXXFLAGS+=-g -O3 -Wall -W
debug: build
.PHONY: release
release: EXE_FILE=exe_release
release: CXXFLAGS+=-O0 -DNDEBUG
release: build
.PHONY: build
build: $(OBJS)
$(CC) -o $(EXE_FILE) $(OBJS)
.cpp.o:
$(CC) -c -std=c++14 $(CXXFLAGS) $<
.PHONY: clean
clean:
rm -f $(EXE_FILE)* $(OBJS)
clang++ -MMD -std=c++11 -c main.cpp
CC=clang++
SRCS=main.cpp sub1.cpp
DEPS=$(SRCS:.cpp=.d)
EXE_FILE=exe_
CXXFLAGS=-c -std=c++14
OBJS=$(SRCS:.cpp=.o)
DEFINE=NDEBUG
-include $(DEPS)
.PHONY: debug
debug: EXE_FILE=exe_debug
debug:CXXFLAGS+=-g -O3 -Wall -W
debug: build
.PHONY: release
release: EXE_FILE=exe_release
release: CXXFLAGS+=-O0 -DNDEBUG
release: build
.PHONY: build
build: $(OBJS)
$(CC) -o $(EXE_FILE) $(OBJS)
.cpp.o:
$(CC) -c -MMD -MP -std=c++14 $(CXXFLAGS) $<
.PHONY: clean
clean:
rm -f $(EXE_FILE)* $(OBJS)
.PHONY output
output:
echo "test"
echo "test" # makeの出力
test  # echoの出力
.PHONY: debug
debug: main.cpp
clang++ -std=c++14 -O3 -g main.cpp
.PHONY: release
release: main.cpp
clang++ -std=c++14 -O0 -DNDEBUG main.cpp
.PHONY: debug
debug: main.cpp sub1.cpp
clang++ -std=c++14 -O3 -g main.cpp
clang++ -std=c++14 -O3 -g sub1.cpp
clang++ -o main main.o sub1.o
#include <iostream>
#include "sub1.hpp"
int main(int argc, char const* argv[])
{
std::cout << "make test" << std::endl;
sub1();
#ifdef NDEBUG
std::cout << "NO DEBUG" << std::endl;
#else
std::cout << "DEBUG" << std::endl;
#endif
return 0;
}
main.o: main.cpp sub1.hpp
sub1.hpp:
#include <iostream>
#include "sub1.hpp"
void sub1()
{
std::cout << "sub1" << std::endl;
}
#pragma once
void sub1();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment