#!/usr/bin/python
import sys, os, os.path
import callcatcher

args = sys.argv[1:]

if len(args) == 0:
	print 'Usage: e.g. callcatcher gcc test.c -o test'
else:
	#--hijack gcc/g++ and detect output file
	if sys.argv.count('-c'):
		callcatcher.compile(args)
	else:
		callcatcher.link(args)
	
	#--call original invocation---
	program = ''
	for arg in sys.argv[1:]:
		program = program + ' ' + callcatcher.shellquote(arg)
	os.execvp(sys.argv[1], sys.argv[1:])
