Makefile 3.01 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements.  See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership.  The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License.  You may obtain a copy of the License at
#
#   http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied.  See the License for the
# specific language governing permissions and limitations
# under the License.

18 19 20 21 22 23 24 25 26 27 28
ROOTDIR = $(CURDIR)

ifndef config
ifneq ("$(wildcard ./config.mk)", "")
	config = config.mk
else
	config = make/config.mk
endif
endif
include $(config)

tqchen committed
29 30
TVMPATH = ..

tqchen committed
31
export LDFLAGS = -pthread -lm
Tianqi Chen committed
32
export CFLAGS = -std=c++11 -Wall -O2 -Iinclude -fPIC
33

34 35 36
ifdef DMLC_CORE_PATH
  CFLAGS += -I$(DMLC_CORE_PATH)/include
else
37
  CFLAGS += -I$(TVMPATH)/3rdparty/dmlc-core/include
38 39
endif

40 41 42 43 44
ifneq ($(ADD_CFLAGS), NONE)
	CFLAGS += $(ADD_CFLAGS)
endif

ifneq ($(ADD_LDFLAGS), NONE)
45
	LDFLAGS += $(ADD_LDFLAGS)
46 47 48 49 50 51
endif

# plugin
PLUGIN_OBJ =
include $(NNVM_PLUGINS)

52
# specify tensor path
53
.PHONY: clean all test lint cpplint pylint doc cython cython3 cyclean
54

Tianqi Chen committed
55 56 57
UNAME_S := $(shell uname -s)

ifeq ($(UNAME_S), Darwin)
58
	SHARED_LIBRARY_SUFFIX := dylib
Tianqi Chen committed
59 60
	WHOLE_ARCH= -all_load
	NO_WHOLE_ARCH= -noall_load
61
	LDFLAGS += -undefined dynamic_lookup
Tianqi Chen committed
62
else
63
	SHARED_LIBRARY_SUFFIX := so
Tianqi Chen committed
64 65 66 67
	WHOLE_ARCH= --whole-archive
	NO_WHOLE_ARCH= --no-whole-archive
endif

68
all: lib/libnnvm.a lib/libnnvm.$(SHARED_LIBRARY_SUFFIX)
69

tqchen committed
70
SRC = $(wildcard src/*.cc src/c_api/*.cc src/core/*.cc src/pass/*.cc)
71
SRC_COMPILER = $(wildcard src/top/*/*.cc wildcard src/top/vision/*/*.cc src/compiler/*.cc src/compiler/*/*.cc)
72
ALL_OBJ = $(patsubst %.cc, build/%.o, $(SRC))
73
TOP_OBJ = $(patsubst %.cc, build/%.o, $(SRC_COMPILER))
tqchen committed
74
ALL_DEP = $(ALL_OBJ)
Tianqi Chen committed
75

tqchen committed
76 77 78
include tests/cpp/unittest.mk

test: $(TEST)
79

80
build/src/%.o: src/%.cc
81
	@mkdir -p $(@D)
82
	$(CXX) $(CFLAGS) -MM -MT build/src/$*.o $< >build/src/$*.d
83 84
	$(CXX) -c $(CFLAGS) -c $< -o $@

85
lib/libnnvm.a: $(ALL_DEP)
tqchen committed
86
	@mkdir -p $(@D)
87
	$(AR) crv $@ $(filter %.o, $?)
tqchen committed
88

89
lib/libnnvm.$(SHARED_LIBRARY_SUFFIX): lib/libnnvm.a ${TOP_OBJ}
90
	@mkdir -p $(@D)
tqchen committed
91
	$(CXX) $(CFLAGS) -shared -o $@ $(filter %.o, $^) $(LDFLAGS) -Wl,${WHOLE_ARCH} lib/libnnvm.a -Wl,${NO_WHOLE_ARCH}
92

93
cython:
94 95
	cd python; python setup.py build_ext --inplace

96 97 98
cython3:
	cd python; python3 setup.py build_ext --inplace

99
cyclean:
100
	rm -rf python/nnvm/*/*.so python/nnvm/*/*.dylib python/nnvm/*/*.cpp
101

102 103
lint: pylint cpplint

tqchen committed
104 105 106
doc:
	doxygen docs/Doxyfile

107
cpplint:
tqchen committed
108
	python ../dmlc-core/scripts/lint.py nnvm cpp include src
tqchen committed
109

110 111 112
pylint:
	pylint python/nnvm --rcfile=$(ROOTDIR)/tests/lint/pylintrc

113
clean:
tqchen committed
114
	$(RM) -rf build lib bin *~ */*~ */*/*~ */*/*/*~ */*.o */*/*.o */*/*/*.o cli_test
115 116 117

-include build/*.d
-include build/*/*.d
ziheng committed
118
-include build/*/*/*.d
119
-include build/*/*/*/*.d