-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile.impl
51 lines (37 loc) · 1.15 KB
/
Makefile.impl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# -*- coding: utf-8 -*-
# MegEngine is Licensed under the Apache License, Version 2.0 (the "License")
#
# Copyright (c) 2014-2020 Megvii Inc. All rights reserved.
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT ARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
TARGET ?= main
CXX := g++
SRC_EXT := cpp
OPTFLAG ?= -O2
BUILD_DIR ?= build
override CXXFLAGS += \
-Isrc -std=c++11 -ggdb -flto \
-Wall -Wextra -Wnon-virtual-dtor -Wno-unused-parameter -Winvalid-pch \
-Wno-unused-local-typedefs \
$(OPTFLAG)
override LDFLAGS += -flto
override V ?= @
CXXSOURCES := $(shell find src example -name "*.$(SRC_EXT)")
OBJS := $(addprefix $(BUILD_DIR)/,$(CXXSOURCES:.$(SRC_EXT)=.o))
DEPFILES := $(OBJS:.o=.d)
all: $(TARGET)
-include $(DEPFILES)
$(BUILD_DIR)/%.o: %.$(SRC_EXT)
@echo "[cxx] $< ..."
@mkdir -pv $(dir $@)
$(V)$(CXX) $(CXXFLAGS) -MM -MT "$@" "$<" > "$(@:.o=.d)"
$(V)$(CXX) -c $< -o $@ $(CXXFLAGS)
$(TARGET): $(OBJS)
@echo "Linking ..."
$(V)$(CXX) $(OBJS) -o $@ $(LDFLAGS)
clean:
rm -rf $(BUILD_DIR) $(TARGET)
.PHONY: all clean
# vim: ft=make