1# Copyright 2015 The TensorFlow Authors. All Rights Reserved. 2# 3# Licensed under the Apache License, Version 2.0 (the "License"); 4# you may not use this file except in compliance with the License. 5# You may obtain a copy of the License at 6# 7# http://www.apache.org/licenses/LICENSE-2.0 8# 9# Unless required by applicable law or agreed to in writing, software 10# distributed under the License is distributed on an "AS IS" BASIS, 11# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12# See the License for the specific language governing permissions and 13# limitations under the License. 14# ============================================================================== 15 16"""System configuration library.""" 17from __future__ import absolute_import 18from __future__ import division 19from __future__ import print_function 20 21import os.path as _os_path 22 23from tensorflow.python.framework.versions import CXX11_ABI_FLAG as _CXX11_ABI_FLAG 24from tensorflow.python.framework.versions import MONOLITHIC_BUILD as _MONOLITHIC_BUILD 25from tensorflow.python.util.tf_export import tf_export 26 27 28# pylint: disable=g-import-not-at-top 29@tf_export('sysconfig.get_include') 30def get_include(): 31 """Get the directory containing the TensorFlow C++ header files. 32 33 Returns: 34 The directory as string. 35 """ 36 # Import inside the function. 37 # sysconfig is imported from the tensorflow module, so having this 38 # import at the top would cause a circular import, resulting in 39 # the tensorflow module missing symbols that come after sysconfig. 40 import tensorflow as tf 41 return _os_path.join(_os_path.dirname(tf.__file__), 'include') 42 43 44@tf_export('sysconfig.get_lib') 45def get_lib(): 46 """Get the directory containing the TensorFlow framework library. 47 48 Returns: 49 The directory as string. 50 """ 51 import tensorflow as tf 52 return _os_path.join(_os_path.dirname(tf.__file__)) 53 54 55@tf_export('sysconfig.get_compile_flags') 56def get_compile_flags(): 57 """Get the compilation flags for custom operators. 58 59 Returns: 60 The compilation flags. 61 """ 62 flags = [] 63 flags.append('-I%s' % get_include()) 64 flags.append('-D_GLIBCXX_USE_CXX11_ABI=%d' % _CXX11_ABI_FLAG) 65 return flags 66 67 68@tf_export('sysconfig.get_link_flags') 69def get_link_flags(): 70 """Get the link flags for custom operators. 71 72 Returns: 73 The link flags. 74 """ 75 flags = [] 76 if not _MONOLITHIC_BUILD: 77 flags.append('-L%s' % get_lib()) 78 flags.append('-ltensorflow_framework') 79 return flags 80