diff --git a/config/makeConfigAppInclude.pl b/config/makeConfigAppInclude.pl
index f8d52a9983718a5761953cdc24626b9c069e2607..a1ee0750120802972c3c2bd6d66ae198af92c318 100644
--- a/config/makeConfigAppInclude.pl
+++ b/config/makeConfigAppInclude.pl
@@ -13,6 +13,8 @@ $savedir = Cwd::getcwd();
 Cwd::chdir($top);
 $top_abs = Cwd::getcwd();
 Cwd::chdir($savedir);
+# Add TOP to macro list.
+$applications{TOP} = $top_abs;
 
 unlink("${outfile}");
 open(OUT,">${outfile}") or die "$! opening ${outfile}";
@@ -38,14 +40,16 @@ foreach $file (@files) {
 		#prefix = post
 		($prefix,$post) = /(.*)\s* \s*(.*)/;
 	    }
-	    else {
-#		$base = $applications{$macro};
-                if ($macro eq "TOP") {
-                    $base = $top;
+	    else
+	    {
+		$base = $applications{$macro};
+		if ($base eq "")
+		{
+		    #print "error: $macro was not previously defined\n";
+		}
+		else
+		{
 		    $post = $base . $post;
-		    #print "info: \$macro= $macro \$base= $base \$post= $post\n";
-                } else {
-		    print "error: $macro is not TOP\n";
 		}
 	    }
 	    push(@files,"$post")
@@ -59,14 +63,14 @@ foreach $file (@files) {
 		# prefix = post
 		($prefix,$post) = /(.*)\s*=\s*(.*)/;
 	    } else {
-                if ($macro eq "TOP") {
-                    $base = $top_abs;
+		$base = $applications{$macro};
+		if ($base eq "") {
+		    #print "error: $macro was not previously defined\n";
+		} else {
 		    $post = $base . $post;
-		    #print "info: \$macro= $macro \$base= $base \$post= $post\n";
-                } else {
-		    print "error: $macro is not TOP\n";
 		}
 	    }
+	    $applications{$prefix} = $post;
 	    if ( -d "$post") { #check that directory exists
 		print OUT "\n";
 		if ( -d "$post/bin/$arch") { #check that directory exists
diff --git a/config/makeIocCdCommands.pl b/config/makeIocCdCommands.pl
index 79a85656439af047b18a347b8ae2d52d3a1d8c36..87e103595ccfcb22f1af92e3f112cfc6b7f058a0 100644
--- a/config/makeIocCdCommands.pl
+++ b/config/makeIocCdCommands.pl
@@ -2,7 +2,6 @@ eval 'exec perl -S $0 ${1+"$@"}'  # -*- Mode: perl -*-
     if $running_under_some_shell; # makeIocCdCommands.pl
 
 use Cwd;
-use Env;
 
 $cwd  = cwd();
 #hack for sun4
@@ -25,6 +24,8 @@ print OUT "top = \"$top\"\n";
 $topbin = "${top}/bin/${arch}";
 #skip check that top/bin/${arch} exists; src may not have been builT
 print OUT "topbin = \"$topbin\"\n";
+# Add TOP to macro list.
+$applications{TOP} = $top;
 
 @files =();
 push(@files,"$top/config/RELEASE");
@@ -45,13 +46,13 @@ foreach $file (@files) {
 		    ($prefix,$post) = /(.*)\s* \s*(.*)/;
 		}
 		else {
-                    if ($macro eq "TOP") {
-                       $base = $top;
-                       $post = $base . $post;
-                       #print "info: \$macro= $macro \$base= $base \$post= $post\n";
-                    } else {
-                       print "error: $macro is not TOP\n";
-                    }
+		    $base = $applications{$macro};
+		    if ($base eq "") {
+			#print "error: $macro was not previously defined\n";
+		    }
+		    else {
+			$post = $base . $post;
+		    }
 		}
 		push(@files,"$post")
 	    }
@@ -64,14 +65,14 @@ foreach $file (@files) {
 		    # prefix = post
 		    ($prefix,$post) = /(.*)\s*=\s*(.*)/;
 		} else {
-                    if ($macro eq "TOP") {
-                       $base = $top;
-                       $post = $base . $post;
-                       #print "info: \$macro= $macro \$base= $base \$post= $post\n";
-                    } else {
-                       print "error: $macro is not TOP\n";
-                    }
+		    $base = $applications{$macro};
+		    if ($base eq "") {
+			#print "error: $macro was not previously defined\n";
+		    } else {
+			$post = $base . $post;
+		    }
 		}
+		$applications{$prefix} = $post;
 		$app = lc($prefix);
 		if ( -d "$post") { #check that directory exists
 		    print OUT "$app = \"$post\"\n";