#!/usr/bin/env python
import sys,os

args = sys.argv[1:]
if '-static' not in args:
	os.execvp('g++', ['g++']+args)

libs = []
otherargs = []
for arg in args:
	if arg == '-static':
		continue
	if arg.startswith('/usr/lib') or (arg.startswith('-l') and arg not in ('-lm','-ldl','-lpthread')):
		libs.append(arg)
	else:
		otherargs.append(arg)

gargv=['gcc']+otherargs+['-Wl,-Bstatic']+libs+['-lstdc++','-Wl,-Bdynamic','-static-libgcc','-lm','-ldl']
os.execvp('gcc', gargv)
