Commits

Anonymous committed 92cd854

use $INCLUDE path (Mark Hammond)

  • Participants
  • Parent commits 9a9f3f5
  • Branches legacy-trunk

Comments (0)

Files changed (1)

Tools/scripts/h2py.py

 
 filedict = {}
 
+try:
+	searchdirs=string.splitfields(os.environ['include'],';')
+except KeyError:
+	try:
+		searchdirs=string.splitfields(os.environ['INCLUDE'],';')
+	except KeyError:
+		searchdirs=['/usr/include']
+
 def main():
 	opts, args = getopt.getopt(sys.argv[1:], 'i:')
 	for o, a in opts:
 			outfp = open(outfile, 'w')
 			outfp.write('# Generated by h2py from %s\n' % filename)
 			filedict = {}
-			if filename[:13] == '/usr/include/':
-				filedict[filename[13:]] = None
+			for dir in searchdirs:
+				if filename[:len(dir)] == dir:
+					filedict[filename[len(dir)+1:]] = None	# no '/' trailing
+					break
 			process(fp, outfp)
 			outfp.close()
 			fp.close()
 			filename = line[a:b]
 			if not filedict.has_key(filename):
 				filedict[filename] = None
-				outfp.write(
-					'\n# Included from %s\n' % filename)
-				inclfp = open('/usr/include/' + filename, 'r')
-				process(inclfp, outfp, env)
+				inclfp = None
+				for dir in searchdirs:
+					try:
+						inclfp = open(dir + '/' + filename, 'r')
+						break
+					except IOError:
+						pass
+				if inclfp:
+					outfp.write(
+						'\n# Included from %s\n' % filename)
+					process(inclfp, outfp, env)
+				else:
+					sys.stderr.write('Warning - could not find file %s' % filename)
+
 main()
-