improve compile script and use template