build_ext.py 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  1. # Build wxGUI extensions (vdigit and nviz)
  2. import os
  3. import sys
  4. def __read_variables(file, dict={}):
  5. """!Read variables from file (e.g. Platform.make)
  6. @param file file descriptor
  7. @param dict dictionary to store (variable, value)
  8. """
  9. for line in file.readlines():
  10. if len(line) < 1:
  11. continue # skip empty lines
  12. if line[0] == '#':
  13. continue # skip comments
  14. try:
  15. var, val = line.split('=', 1)
  16. except ValueError:
  17. continue
  18. dict[var.strip()] = val.strip()
  19. def update_opts(flag, macros, inc_dirs, lib_dirs, libs, extras):
  20. """!Update Extension options"""
  21. global variables
  22. line = variables[flag]
  23. fw_next = False
  24. for val in line.split(' '):
  25. key = val[:2]
  26. if fw_next:
  27. extras.append(val)
  28. fw_next = False
  29. elif key == '-I': # includes
  30. inc_dirs.append(val[2:])
  31. elif key == '-D': # macros
  32. if '=' in val[2:]:
  33. macros.append(tuple(val[2:].split('=')))
  34. else:
  35. macros.append((val[2:], None))
  36. elif key == '-L': # libs dir
  37. lib_dirs.append(val[2:])
  38. elif key == '-l':
  39. libs.append(val[2:])
  40. elif key == '-F': # frameworks dir
  41. extras.append(val)
  42. elif val == '-framework':
  43. extras.append(val)
  44. fw_next = True
  45. try:
  46. Platform_make = open(os.path.join('..', '..', '..',
  47. 'include', 'Make', 'Platform.make'))
  48. Grass_make = open(os.path.join('..', '..', '..',
  49. 'include', 'Make', 'Grass.make'))
  50. except IOError, e:
  51. print 'Unable to compile wxGUI vdigit extension.\n\n', e
  52. sys.exit(1)
  53. variables = {}
  54. __read_variables(Platform_make, variables)
  55. __read_variables(Grass_make, variables)