# Description: awk script to translate a pair of object files to the corresponding pair of library archives, given a database of object files and archives
# Usage: awk -f object_archive.awk -vdb=database_file < object-pair-list
# Inputs: database_file has lines like "obj.o libx.a", input has lines like "obj1.o obj2.o"
# Output: "libx.a liby.a" if database has "obj1.o libx.a" and "obj2.o liby.a", and input is "obj1.o obj2.o"
# Application: convert partial ordering of object files generated by lorder into a partial ordering of library archives

# The following license covers this software, including makefiles and documentation:

# This software is covered by the zlib/libpng license.
# The zlib/libpng license is a recognized open source license by the
# Open Source Initiative: http://opensource.org/licenses/Zlib
# The zlib/libpng license is a recognized "\"free\"" software license by the
# Free Software Foundation: https://directory.fsf.org/wiki/License:Zlib
# ****************** Copyright notice (part of the license) *******************
# $Id: ~\|^` @(#)%M% copyright 2016 %Q%\ object_archive.awk $
# This software is provided 'as-is', without any express or implied warranty.
# In no event will the authors be held liable for any damages arising from the
# use of this software.
#
# Permission is granted to anyone to use this software for any purpose,
# including commercial applications, and to alter it and redistribute it freely,
# subject to the following restrictions:
#
# 1. The origin of this software must not be misrepresented; you must not claim
#    that you wrote the original software. If you use this software in a
#    product, an acknowledgment in the product documentation would be
#    appreciated but is not required.
#
# 2. Altered source versions must be plainly marked as such, and must not be
#    misrepresented as being the original software.
#
# 3. This notice may not be removed or altered from any source distribution.
# ****************************** (end of license) ******************************
# This is %M% version %I% dated %O%
# You may send bug reports to %Y% with subject "object_archive.awk".
# *****************************************************************************
# maintenance note: master file  %P%

BEGIN {
	script = "%M% %I%"
	if (script ~ /[%]M[%] [%]I[%]/)
		script = "object_archive.awk"
	if (1 > length(db)) {
		printf "%s: database file (db) required\n", script >> "/dev/stderr"
		exit 1
	}
	while (0 < getline < db) {
		if ($0 ~ /^[ \t]*[#]/) # ignore comment lines
			continue
		if ($0 ~ /^[ \t]*$/) # ignore whitespace-only lines
			continue
		if (2 != NF) # ignore malformed input
			continue
		arch[$1 ""] = $2
	}
}

{
	printf "%s %s\n", arch[$1 ""], arch[$2 ""]
	next
}

END {
}
