When an input yacc file ends in .yy and the yacc -d flag is used, expect a generated...
[scons.git] / src / engine / SCons / Defaults.py
index 6fa053d2a49a5387c62e653e63f6c0d27a94d958..e2bb3b436ca7d802745048e554f64bd78b0305c0 100644 (file)
@@ -69,14 +69,19 @@ CScan = SCons.Scanner.C.CScan()
 FortranScan = SCons.Scanner.Fortran.FortranScan()
 
 def yaccEmitter(target, source, env, **kw):
-    # Yacc can be configured to emit a .h file as well
-    # as a .c file, if -d is specified on the command line.
-    if len(source) and \
-       os.path.splitext(SCons.Util.to_String(source[0]))[1] in \
-       [ '.y', '.yy'] and \
-       '-d' in string.split(env.subst("$YACCFLAGS")):
-        target.append(os.path.splitext(SCons.Util.to_String(target[0]))[0] + \
-                      '.h')
+    # If -d is specified on the command line, yacc will emit a .h
+    # or .hpp file as well as a .c or .cpp file, depending on whether
+    # the input file is a .y or .yy, respectively.
+    if len(source) and '-d' in string.split(env.subst("$YACCFLAGS")):
+        suff = os.path.splitext(SCons.Util.to_String(source[0]))[1]
+        h = None
+        if suff == '.y':
+            h = '.h'
+        elif suff == '.yy':
+            h = '.hpp'
+        if h:
+            base = os.path.splitext(SCons.Util.to_String(target[0]))[0]
+            target.append(base + h)
     return (target, source)
 
 def CFile():