awk ' 
BEGIN{
		var["dev"] = "DEVS=";
		var["vga"] = "VGAS=";
		var["ether"] = "ETHERS=";
		var["init"] = "INIT=";
		var["ip"] = "IP=";
		var["port"] = "PORT=";
		var["misc"] = "MISC=";
		var["lib"] = "LIBS=";
		var["link"] = "LINKS=";
		var["root"] = "ROOTFILES=";
		root = ENVIRON["ROOT"];
}
/^$/{		next;
}
/^#/{		next;
}
/^env/{
		enving = 1;
		next;
}
enving != 0 && /^[ 	]/{
		print $1 "=" $2;
}
/^(code|dev|ether|init|ip|lib|link|mod|misc|port|root|vga)/{
		enving = 0;
		if(current != "")
			print current;
		current = var[$1];
		type = $1;
		next;
}
/^[^ 	]/	{
		enving = 0;
		if(current != "")
			print current;
		current = "";
}
current && /^[ 	]/{
		if(type == "dev")
			file = "dev" $1;
		else if(type == "root"){
			if (NF > 1)
				file = $2;
			else if ($1 == "/osinit.dis")
				next;	# handled via explicit dependency
			else
				file = $1;
			if(have[file] == 0){
				current = current " " root file;
				have[file]++;
			}
			next;
		}
		else
			file = $1;
		if(type == "init")
			current = current " " file;
		else if(have[file] == 0){
			if(type != "dev" || system("test -f " file ".c") || system("test -f ../port/" file ".c")) {
				if(type == "lib")
					current = current " " file;
				else
					current = current " " file "'^.$O^'";
				have[file]++;
			}
		}
		for(i = 2; i <= NF; i++){
			if($i !~ "[+=-].*"){
				if(have[$i] == 0){
					others[++nothers] = $i;
					have[$i]++;
				}
			}
		}
		next;
}
END{
		if(current != "")
			print current;
		for(i = 1; i <= nothers; i++)
			x = x " " others[i] "'^.$O^' ";
		if(x)
			printf("OTHERS=%s\n", x);
}' $* | sed 's/
//'
