build_ext.py 1.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  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):
  20. """Update Extension options"""
  21. global variables
  22. line = variables[flag]
  23. for val in line.split(' '):
  24. key = val[:2]
  25. if key == '-I': # includes
  26. inc_dirs.append(val[2:])
  27. elif key == '-D': # macros
  28. if '=' in val[2:]:
  29. macros.append(tuple(val[2:].split('=')))
  30. else:
  31. macros.append((val[2:], None))
  32. elif key == '-L': # libs dir
  33. lib_dirs.append(val[2:])
  34. elif key == '-l':
  35. libs.append(val[2:])
  36. try:
  37. Platform_make = open(os.path.join('..', '..', '..',
  38. 'include', 'Make', 'Platform.make'))
  39. Grass_make = open(os.path.join('..', '..', '..',
  40. 'include', 'Make', 'Grass.make'))
  41. except IOError, e:
  42. print 'Unable to compile wxGUI vdigit extension.\n\n', e
  43. sys.exit(1)
  44. variables = {}
  45. __read_variables(Platform_make, variables)
  46. __read_variables(Grass_make, variables)