#    This file is part of MKF.
#
#    MKF is free software; you can redistribute it and/or modify
#    it under the terms of the GNU General Public License as published by
#    the Free Software Foundation; either version 2 of the License, or
#    (at your option) any later version.
#
#    MKF is distributed in the hope that it will be useful,
#    but WITHOUT ANY WARRANTY; without even the implied warranty of
#    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
#    GNU General Public License for more details.
#
#    You should have received a copy of the GNU General Public License
#    along with MKF; if not, write to the Free Software
#    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
#
#    Copyright (c) 2004 Alexandre Becoulet <alexandre.becoulet@epita.fr>

# static lib archiver invocation
_if_var_eq		cmd_linker
 var_define		cmd_linker	ld
_end_if

_if_var_eq		use_linker

 _if_in_path		{PVAR,cmd_linker}

  _if_stdout_match	GNU	{PVAR,cmd_linker} -V
   msg_info		GNU linker found ({PVAR,cmd_linker})
   var_define		use_linker	gnu
  _else

   _if_stdout_match	Solaris	{PVAR,cmd_linker} -V
    msg_info		Solaris linker found ({PVAR,cmd_linker})
    var_define		use_linker	solaris
   _else

    msg_info		unknown linker found ({PVAR,cmd_linker})
    var_define		use_linker	ld
   _end_if
  _end_if

 _else
  msg_error		no linker found
 _end_if

_end_if

# object merge link

_if_var_eq		mkf_pretty_print	yes
 command_add		o	o	@echo "   LD (partial .o)   {OUT}"
_end_if
command_add		o	o	{PVAR,cmd_linker} -r {JVAR,opt_o_linker} -o {OUT} {SRC,.*\.o}

# dynamic lib linker invocation
_if_var_eq		use_linker	solaris
 msg_info		using ld -G for dynamic library generation
 var_append		opt_so_linker	-G
_else
 msg_info		using ld -shared for dynamic library generation
 var_append		opt_so_linker	-shared
_end_if

_if_var_eq		static		yes
 var_append		opt_exe_linker	-static
_end_if

_if_var_eq		mkf_pretty_print	yes
 command_add		o	so	@echo "   LD (shared .so)   {OUT}"
_end_if
command_add		o	so	{PVAR,cmd_linker} {JVAR,opt_so_linker} -o {OUT} {SRC,.*\.o} {JLIST,-l,_libs} {JLIST,-l,libs}

_if_var_eq		mkf_pretty_print	yes
 command_add		o	noext	@echo "   CC (exe linking)  {OUT}"
_end_if
command_add		o	noext	{JVAR,cmd_c_compiler} {JVAR,opt_exe_linker} \
					-o {OUT} {SRC,.*\.o} {JLIST,-L,lib_dirs} {JLIST,-l,_libs} {JLIST,-l,libs}

_if_var_eq		mkf_pretty_print	yes
 command_add		o	a	@echo "   AR                {OUT}"
_end_if
command_add		o	a	ar -rc {OUT} {SRC,.*\.o}

_if_var_eq		mkf_pretty_print	yes
 command_add		o	a	@echo "   RANLIB            {OUT}"
_end_if
command_add		o	a	ranlib {OUT}

