Index: codegen/codegen.py
===================================================================
--- codegen/codegen.py	(revision 964)
+++ codegen/codegen.py	(working copy)
@@ -1661,7 +1661,8 @@
     py_ssize_t_clean = False
     for opt, arg in opts:
         if opt in ('-o', '--override'):
-            o = override.Overrides(arg)
+            # Warning: user has to make sure all -D options appear before -o
+            o = override.Overrides(arg, defines)
         elif opt in ('-p', '--prefix'):
             prefix = arg
         elif opt in ('-r', '--register'):
Index: codegen/override.py
===================================================================
--- codegen/override.py	(revision 964)
+++ codegen/override.py	(working copy)
@@ -22,7 +22,7 @@
 import_pat = re.compile(r'\s*import\s+(\S+)\.([^\s.]+)\s+as\s+(\S+)')
 
 class Overrides:
-    def __init__(self, filename=None):
+    def __init__(self, filename=None, defines=None):
         self.modulename = None
         self.ignores = {}
         self.glob_ignores = []
@@ -46,9 +46,9 @@
         self.newstyle_constructors = {}
         self.dynamicnamespace = False
         if filename:
-            self.handle_file(filename)
+            self.handle_file(filename, defines)
 
-    def handle_file(self, filename):
+    def handle_file(self, filename, defines=None):
         oldpath = os.getcwd()
 
         fp = open(filename, 'r')
@@ -75,14 +75,18 @@
             linenum = linenum + 1
         if lines:
             bufs.append((string.join(lines, ''), startline))
-        if not bufs: return
+        if not bufs:
+            return
 
+        if defines is None:
+            defines = { }
+
         for buf, startline in bufs:
-            self.__parse_override(buf, startline, filename)
+            self.__parse_override(buf, startline, filename, defines)
 
         os.chdir(oldpath)
 
-    def __parse_override(self, buffer, startline, filename):
+    def __parse_override(self, buffer, startline, filename, defines):
         pos = string.find(buffer, '\n')
         if pos >= 0:
             line = buffer[:pos]
@@ -91,6 +95,21 @@
             line = buffer ; rest = ''
         words = string.split(line)
         command = words[0]
+
+        # All conditionals must go first.
+        if command in ('ifdef'):
+            if not ':' in line:
+                raise ValueError('colon character expected after a conditional statement')
+
+            conditional, statement = line.split(':', 1)
+            conditional_command, condition = command, conditional[len(command):].strip()
+            words = statement.split()
+            command = words[0]
+
+            if conditional_command == 'ifdef':
+                if condition not in defines:
+                    return
+
         if (command == 'ignore' or
             command == 'ignore-' + sys.platform):
             "ignore/ignore-platform [functions..]"
