#encoding: utf-8
from distutils.core import setup, Extension
import os

drivers = [
	# (module_name, module_dir, module_src_dir)
	("tentcale_pi.AM2315","am2315","src"),
	("tentcale_pi.BMP180", "bmp180", "src"),
	("tentcale_pi.TSL2561", "tsl2561", "src")
]

def make_extensions(drivers):
	exts = []
	for (extension_name, extension_dir, extension_src_dir) in drivers:
		current_dir = os.path.realpath(__file__)
		ext_path = os.path.join(current_dir, extension_dir)
		src_path = os.path.join(ext_path, extension_src_dir)
		c_files = filter(lambda x: x.endswith(".c"), src_path)
		c_files = map(lambda f: os.path.join(current_dir, f), c_files)
		exts.append((extension_name, c_files, src_path))
	return exts
	
	
def make_manifest_file(extensions):
	with open("./MANIFEST.in","w+") as f:
		[ f.write("graft %s\n" % src_path) for (_,_,src_path) in extensions]
	

extensions = make_extensions(drivers)

make_manifest_file(extensions)

ext_modules = map(lambda (name, src_dir,_): Extension(name, src_dir), extensions) 

setup(
	name = "tentacle_pi",
	version = "0.1.0.dev1",
	description = "Tentacles for the Raspberry Pi!",
	
	ext_modules = ext_modules,
	
	author = "Alexander Rüedlinger",
	author_email = "a.rueedlinger@gmail.com",
	license = "MIT"
)

@@ -65,23 +65,23 @@
 ort os%0A%0A
-drivers
+DRIVERS
  = %5B%0A%09# 
@@ -250,16 +250,75 @@
 rc%22)%0A%5D%0A%0A
+CURRENT_DIR = os.path.dirname(os.path.realpath(__file__))%0A%0A
 def make
@@ -422,51 +422,8 @@
 rs:%0A
-%09%09current_dir = os.path.realpath(__file__)%0A
 %09%09ex
@@ -444,27 +444,27 @@
 th.join(
-current_dir
+CURRENT_DIR
 , extens
@@ -627,19 +627,19 @@
 oin(
-current_dir
+CURRENT_DIR
 , f)
@@ -768,11 +768,34 @@
 pen(
-%22./
+os.path.join(CURRENT_DIR,%22
 MANI
@@ -802,16 +802,17 @@
 FEST.in%22
+)
 ,%22w+%22) a
@@ -919,23 +919,23 @@
 ensions(
-drivers
+DRIVERS
 )%0A%0Amake_

fix hardcoded MANIFEST.in path