Skip to content

Instantly share code, notes, and snippets.

@denkiwakame
Created January 23, 2014 13:28
Show Gist options
  • Save denkiwakame/8578413 to your computer and use it in GitHub Desktop.
Save denkiwakame/8578413 to your computer and use it in GitHub Desktop.
ヘッダ依存関係をなんtか
GCC = g++
CFLAGS = -O2 -MMD -Wall -Wextra
SRCS = main.cpp sample.cpp
TARGET = main
OBJS = $(SRCS:.cpp=.o)
DEPS = $(SRCS:.cpp=.d)
.cpp.o:
$(GCC) $(CFLAGS) -c $< -o $@
$(TARGET): $(OBJS)
$(GCC) $(CFLAGS) -o $@ $+
default: $(OBJS) $(TARGET)
clean:
$(RM) $(OBJS) $(TARGET)
-include $(DEPS)
---------------------------------------------------------------------
CXX=g++
INCDIR=`pkg-config --libs opencv`
LIBDIR=`pkg-config --cflags opencv`
CFLAGS=-Wall
TARGETS=endecoder
SRCS=main.cpp
OBJS=$(SRCS:.cpp=.o)
DEPS=$(SRCS:.cpp=.d)
all: $(TARGETS) $(OBJS)
$(TARGETS): $(OBJS)
$(CXX) -o $@ $(OBJS) $(INCDIR) $(LIBDIR)
.cpp.o:
$(CXX) $(CFLAGS) -c -O2 -MMD $< $(INCDIR) $(LIBDIR)
clean:
rm -rf $(TARGETS) $(OBJS) *.gch *.d
-include $(DEPS)
@denkiwakame
Copy link
Author

suffix
.cpp.o
cppからoつくるー

$< 依存ファイルで変更があったやつ
$(GCC) $(CFLAGS) -c $&lt; -o $@
$@いまのターゲットのフルネーム(作ろうとしてるやつ)

-c リンクしない
-O2 optimization lv2 -O4:デバッグではちょっとやりすぎ

-c -o 以外はCFLAGS

@denkiwakame
Copy link
Author

.d 作って 最後に-include $(DEPS)しないとヘッダの更新に反応しなくてかなしみ

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