Description: Check if we have the grass include and Make files
 GRASS 6 used a shell script for g.extension.
 GRASS 7 reimplemented the shell script in Python.
 .
 The original version of this patch was made by M. Hamish Bowman,
 and ported to Python by Bas Couwenberg.
Author: M. Hamish Bowman <hamish.webmail@gmail.com>
Author: Bas Couwenberg <sebastic@xs4all.nl>

--- a/scripts/g.extension/g.extension.py
+++ b/scripts/g.extension/g.extension.py
@@ -122,6 +122,7 @@ import atexit
 import shutil
 import zipfile
 import tempfile
+import subprocess
 
 from urllib2 import HTTPError
 from urllib import urlopen
@@ -144,6 +145,20 @@ def check_progs():
         if not grass.find_program(prog, '--help'):
             grass.fatal(_("'%s' required. Please install '%s' first.") % (prog, prog))
 
+def check_pkg(pkg):
+    process = subprocess.Popen(["dpkg-query", "-l", pkg], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
+    output = process.communicate()[0]
+
+    installed = 0
+    for line in output.split('\n'):
+        result = re.match('^ii', line)
+        if result:
+            installed = 1
+            break
+
+    if installed == 0:
+       grass.fatal(_("This module requires the \"%s\" package.") % pkg)
+
 # expand prefix to class name
 def expand_module_class_name(c):
     name = { 'd'   : 'display',
@@ -1014,6 +1029,8 @@ def main():
     # check dependecies
     if sys.platform != "win32":
         check_progs()
+        # check if we have the grass include and Make files
+        check_pkg("grass-dev")
 
     # manage proxies
     global PROXIES
