Added PIC static library support and library/include symink features
[nil.git] / nil / setup.py
blob3e819ac4aa344f573f3de1708749e24f6b8ffcc2
1 import subprocess, os
2 import nil.environment
4 def has_command(arguments):
5 try:
6 process = subprocess.Popen(arguments, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
7 process.wait()
8 return True
9 except OSError:
10 return False
12 def run(arguments):
13 try:
14 process = subprocess.Popen(arguments, stdin = subprocess.PIPE, stdout = subprocess.PIPE, stderr = subprocess.PIPE)
15 process.wait()
16 return process.returncode == 0
17 except OSError:
18 return None
20 def command(input):
21 print 'Executing: %s' % input
22 return os.system(input) != 0
24 def symlink(target, link_name):
25 if os.path.exists(link_name):
26 return True
28 return command('sudo ln -s %s %s' % (target, link_name))
30 def install_packages(packages):
31 apt = 'apt-get'
32 if has_command(apt):
33 for package in packages:
34 result = run(['dpkg', '-s', package])
35 if result == None:
36 print 'Failed to execute package manager'
37 sys.exit(1)
38 if not result:
39 print 'Installing missing package %s' % package
40 os.system('sudo apt-get install %s' % package)
41 else:
42 print 'Unable to install the specified packages (%s) - only Ubuntu and Debian are currently supported.' % packages
43 return False
45 def setup_local_symlink(local_directory, target, link):
46 root = os.path.dirname(nil.environment.get_script_path())
48 target_path = os.path.join(root, target)
49 symlink_path = os.path.join('/usr/local', local_directory, link)
51 symlink(target_path, symlink_path)
53 def include(target):
54 setup_local_symlink('include', target, target)
56 def library(target):
57 setup_local_symlink('lib', target, os.path.basename(target))