/ scripts / platform-is-supported
platform-is-supported
  1  #!/usr/bin/env python
  2  #
  3  # This script returns 0 when run on a platform supported by the current
  4  # branch of LinuxCNC, and 1 when run on an unsupported platform.  It is
  5  # intended to guide build automation on whether or not to try to build.
  6  #
  7  # Copyright: 2014, 2016
  8  # Author:    Sebastian Kuzminsky <seb@highlab.com>
  9  #
 10  # This program is free software; you can redistribute it and/or modify
 11  # it under the terms of the GNU General Public License as published by
 12  # the Free Software Foundation; either version 2 of the License, or
 13  # (at your option) any later version.
 14  #
 15  # This program is distributed in the hope that it will be useful,
 16  # but WITHOUT ANY WARRANTY; without even the implied warranty of
 17  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 18  # GNU General Public License for more details.
 19  #
 20  # You should have received a copy of the GNU General Public License
 21  # along with this program; if not, write to the Free Software
 22  # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 23  
 24  import os
 25  import sys
 26  import subprocess
 27  import re
 28  
 29  if sys.hexversion < 0x2070000:
 30      raise SystemExit, "System Python is too old"
 31  
 32  supported_oses = [ 'linux' ]
 33  supported_cpus = [ 'amd64', 'i386', 'arm' ]
 34  supported_kernel_flavors = [ 'rtai', 'rtpreempt', 'vanilla' ]
 35  
 36  
 37  def detect_os():
 38      return os.uname()[0].lower()
 39  
 40  
 41  def detect_kernel_flavor(uname):
 42      try:
 43          f = open("/boot/config-%s" % uname)
 44      except IOError:
 45          print "no kernel configuration found for %s" % uname
 46          sys.exit(1)
 47      l = f.read(-1)
 48      f.close()
 49  
 50      config_ipipe = re.search('^CONFIG_IPIPE', l, re.MULTILINE)
 51      config_xeno = re.search('^CONFIG_XENO_', l, re.MULTILINE)
 52      config_rtpreempt = re.search('^CONFIG_PREEMPT_RT', l, re.MULTILINE)
 53  
 54      if config_ipipe and not config_xeno and not config_rtpreempt:
 55          return 'rtai'
 56      elif config_ipipe and config_xeno and not config_rtpreempt:
 57          return 'xenomai'
 58      elif not config_ipipe and not config_xeno and config_rtpreempt:
 59          return 'rtpreempt'
 60      else:
 61          return 'vanilla'
 62  
 63  
 64  os = detect_os()
 65  
 66  if os == 'linux':
 67      cpu = subprocess.check_output(['dpkg-architecture', '-qDEB_HOST_ARCH_CPU']).strip()
 68      distributor = subprocess.check_output(['lsb_release', '--id', '--short']).strip()
 69      release = subprocess.check_output(['lsb_release', '--release', '--short']).strip()
 70      try:
 71          major, minor = re.split('\.', release)
 72      except ValueError as e:
 73          major = release
 74          minor = "0"
 75      release_major = int(major)
 76      release_minor = int(minor)
 77  
 78      uname = subprocess.check_output(['uname', '-r']).strip()
 79      kernel_flavor = detect_kernel_flavor(uname)
 80  
 81  else:
 82      print "unknown OS:", os
 83      sys.exit(1)
 84  
 85  
 86  print "os =", os
 87  print "cpu =", cpu
 88  print "distributor =", distributor
 89  print "release =", release
 90  print "    major =", release_major
 91  print "    minor =", release_minor
 92  print "uname = %s (%s)" % (uname, kernel_flavor)
 93  
 94  if os not in supported_oses:
 95      print "unsupported OS!"
 96      sys.exit(1)
 97  
 98  if cpu not in supported_cpus:
 99      print "unsupported CPU!"
100      sys.exit(1)
101  
102  if distributor == 'Ubuntu':
103      if release_major < 12:
104          print "release is too old!"
105          sys.exit(1)
106  
107  if kernel_flavor not in supported_kernel_flavors:
108      print "unsupported kernel flavor"
109      sys.exit(1)
110  
111  print "this platform is supported!"
112  sys.exit(0)
113