Allow specifying lib directories and libs to link against on the command line.

pull/1/head
Andy Balaam 13 years ago
parent d908367de8
commit b1bc3a64c2
  1. 39
      libigcc/run.py
  2. 19
      test-igcc
  3. 24
      test-igcc-slow
  4. 27
      test/cpp/mylib.cpp
  5. 25
      test/cpp/mylib.h

@ -32,11 +32,17 @@ import version
# --------------
# One day these will be in a config file
prompt = "g++> "
compiler_command = ( "g++", "-x", "c++", "$include_dirs",
"-o", "$outfile", "-" )
compiler_command = ( "g++", "-x", "c++", "-o", "$outfile", "-",
"$include_dirs", "$lib_dirs", "$libs" )
include_dir_command = ( "-I$cmd", )
lib_dir_command = ( "-L$cmd", )
lib_command = ( "-l$cmd", )
include_command = ( "-I", "$include_dir" )
#---------------
incl_re = re.compile( r"\s*#\s*include\s" )
@ -68,21 +74,29 @@ def get_temporary_file_name():
outfile.close()
return outfilename
def append_multiple( single_cmd, cmdlist, ret ):
if cmdlist is not None:
for cmd in cmdlist:
for cmd_part in single_cmd:
ret.append(
cmd_part.replace( "$cmd" , cmd ) )
def get_compiler_command( options, outfilename ):
ret = []
for part in compiler_command:
if part == "$include_dirs":
if options.DIR is not None:
for incl_dir in options.DIR:
for incl_part in include_command:
ret.append(
incl_part.replace( "$include_dir" , incl_dir ) )
append_multiple( include_dir_command, options.INCLUDE, ret )
elif part == "$lib_dirs":
append_multiple( lib_dir_command, options.LIBDIR,ret )
elif part == "$libs":
append_multiple( lib_command, options.LIB, ret )
else:
ret.append( part.replace( "$outfile", outfilename ) )
return ret
def run_compile( subs_compiler_command, user_commands, user_includes ):
#print "$ " + ( " ".join( subs_compiler_command ) )
compile_process = subprocess.Popen( subs_compiler_command,
stdin = subprocess.PIPE, stderr = subprocess.PIPE )
stdoutdata, stderrdata = compile_process.communicate(
@ -151,9 +165,14 @@ def do_run( options, inputfile, exefilename ):
def parse_args( argv ):
parser = OptionParser( version="igcc " + version.VERSION )
parser.add_option( "-I", "", dest="DIR", action="append",
help = "Add the directory DIR to the list of directories to " +
parser.add_option( "-I", "", dest="INCLUDE", action="append",
help = "Add INCLUDE to the list of directories to " +
"be searched for header files." )
parser.add_option( "-L", "", dest="LIBDIR", action="append",
help = "Add LIBDIR to the list of directories to " +
"be searched for library files." )
parser.add_option( "-l", "", dest="LIB", action="append",
help = "Search the library LIB when linking." )
(options, args) = parser.parse_args( argv )

@ -294,6 +294,24 @@ g++>
run_program( commands, expected_output, argv = argv )
def test_lib():
commands = [ '#include "math.h"',
'int a = max( 4, 6 );',
r'printf( "%d\n", a );', ]
expected_output = (
r'''g++> #include "math.h"
g++> int a = max( 4, 6 );
g++> printf( "%d\n", a );
6
g++>
''' )
argv = [ "-lm" ]
run_program( commands, expected_output, argv = argv )
@ -313,6 +331,7 @@ def main():
test_welcome_message()
test_include_dir_on_cmd_line()
test_2_include_dirs_on_cmd_line()
test_lib()
#test_undo();
#test_edit_in_vim();

@ -0,0 +1,24 @@
#!/bin/bash
function test_lib_dir()
{
cd test/cpp && \
g++ -o mylib.o -c mylib.cpp && \
ar rc libmylib.a mylib.o && \
ranlib libmylib.a && \
cd ../.. && \
echo -e '#include "mylib.h"\ndefined_in_cpp();' | ./igcc -Itest/cpp -Ltest/cpp -lmylib | grep "defined_in_cpp saying hello" > /dev/null
RETVAL=$?
if [[ $RETVAL != 0 ]]; then
{
echo "test_lib_dir failed."
exit 1
}; fi
}
test_lib_dir && echo "All slow tests passed." && ./test-igcc

@ -0,0 +1,27 @@
// igcc - a read-eval-print loop for C/C++ programmers
//
// Copyright (C) 2009 Andy Balaam
//
// This program 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.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
#include <iostream>
#include "mylib.h"
void defined_in_cpp()
{
std::cout << "defined_in_cpp saying hello." << std::endl;
}

@ -0,0 +1,25 @@
// igcc - a read-eval-print loop for C/C++ programmers
//
// Copyright (C) 2009 Andy Balaam
//
// This program 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.
//
// This program 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 this program; if not, write to the Free Software
// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
// MA 02110-1301, USA.
#ifndef MYLIB_H
#define MYLIB_H
void defined_in_cpp();
#endif // MYLIB_H
Loading…
Cancel
Save