Import ('env', 'RuntimeDirEtc', 'InstallDirEtc', 'InstallDirLibEinit', 'RuntimeDirLibEinit')

import glob, os

files = []

def edoconfig (path):
 global files
 for i in glob.glob (path + '/*.xml'):
  files += [i]

edoconfig ('.')
edoconfig ('subsystems.d')
edoconfig ('rules.edev')

cfg = []

for i in files:
 env.FixConfiguration ('build/data/' + i, i)
 if i == './einit.xml':
  env.Install (InstallDirLibEinit, 'build/data/einit.xml')
 else:
  env.FixConfiguration ('build/data/' + i, i)
  env.InstallAs (InstallDirLibEinit + '/defaults/' + i, 'build/data/' + i)
  try:
   odata = ""
   ndata = ""
   f = open(RuntimeDirLibEinit + '/defaults/' + i, "r")
   if f:
    odata = f.read ()
    f.close()

   f = open('build/data/' + i, "r")
   if f:
    ndata = f.read ()
    f.close()

   if ndata != odata:
#    print ('no match: ' + 'build/data/' + i + ' && ' + RuntimeDirLibEinit + '/defaults/' + i)
    env.InstallAs (InstallDirEtc + '/' + i, i)
   else:
#    print ('match: ' + 'build/data/' + i + ' && ' + RuntimeDirLibEinit + '/defaults/' + i)
    env.InstallAs (InstallDirEtc + '/' + i, RuntimeDirEtc + '/' + i)
  except:
#   print ('cant open of these files: ' + 'build/data/' + i + ' && ' + RuntimeDirLibEinit + '/defaults/' + i)
   env.InstallAs (InstallDirEtc + '/' + i, i)

env.Install (InstallDirLibEinit + '/schemata', glob.glob ('schema/*.rnc'))
