#!/usr/bin/python
# Jerone Young <jerone.young@canonical.com>

import subprocess
import string

stanza_prefix1 = "BUILT_MODULE_NAME"
stanza_prefix2 = "BUILT_MODULE_LOCATION"
stanza_prefix3 = "DEST_MODULE_LOCATION"
# XXX Need to fill in the module_location_prefix to suit the module being built.
# This value is actually ignored in Ubuntu, but is required by DKMS.
module_location_prefix = "/updates/kernel/"
count = 0

try:
    p1 = subprocess.Popen(["find", "-name",  "*.ko", "-type", "f"], stdout = subprocess.PIPE)
    output = p1.communicate()[0]
except subprocess.CalledProcessError, exc:
    print exc.output, "Non zero return code = ", exc.returncode 
output = output.splitlines()

for line in output:
	line = line.strip("./")
	split_line = line.split("/")

	module_name = ((split_line[len(split_line)-1]).split("."))[0]
	print stanza_prefix1 + "[" + str(count) + "]=\"" + module_name + "\"" 

	split_line.pop(len(split_line)-1)
	location_path = "./" + string.join(split_line,"/")
	print stanza_prefix2 + "[" + str(count) + "]=\"" + location_path + "\""

	dest_location = module_location_prefix
	print stanza_prefix3 + "[" + str(count) + "]=\"" + dest_location + "\""
 
	print ""
	count = count + 1
