1#!/usr/bin/env python 2# Copyright (c) 2012 The Chromium Authors. All rights reserved. 3# Use of this source code is governed by a BSD-style license that can be 4# found in the LICENSE file. 5 6"""Wrapper around swig. 7 8Sets the SWIG_LIB environment var to point to Lib dir 9and defers control to the platform-specific swig binary. 10 11Depends on swig binaries being available at ../../third_party/swig. 12""" 13 14import os 15import subprocess 16import sys 17 18 19def main(): 20 swig_dir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), 21 os.pardir, os.pardir, 'third_party', 'swig')) 22 lib_dir = os.path.join(swig_dir, "Lib") 23 os.putenv("SWIG_LIB", lib_dir) 24 dir_map = { 25 'darwin': 'mac', 26 'linux2': 'linux', 27 'linux3': 'linux', 28 'win32': 'win', 29 } 30 # Swig documentation lies that platform macros are provided to swig 31 # preprocessor. Provide them ourselves. 32 platform_flags = { 33 'darwin': '-DSWIGMAC', 34 'linux2': '-DSWIGLINUX', 35 'linux3': '-DSWIGLINUX', 36 'win32': '-DSWIGWIN', 37 } 38 swig_bin = os.path.join(swig_dir, dir_map[sys.platform], 'swig') 39 args = [swig_bin, platform_flags[sys.platform]] + sys.argv[1:] 40 args = [x.replace('/', os.sep) for x in args] 41 return subprocess.call(args) 42 43 44if __name__ == "__main__": 45 sys.exit(main()) 46