tomcat-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cos...@apache.org
Subject cvs commit: jakarta-tomcat-connectors/jk/jkant/java/org/apache/jk/ant SoTask.java
Date Fri, 26 Oct 2001 23:28:50 GMT
costin      01/10/26 16:28:50

  Modified:    jk/jkant/java/org/apache/jk/ant SoTask.java
  Log:
  Almost done.
  
  Compile all the .so files, dependencies, linking, etc. If libtool is available
  everything should work.
  
  Still need to clean up and better organize the source, merge the 'special' cases
  ( using the existing Makefiles for example, or what apxs is doing on window - I
  don't know and I can't test )
  
  If you have some time, please give it a try and let me know if it works for you
  Just type "ant jkant" in j-t-c/jk - on linux it should compile all .so files for
  apache2, apache13, jni. ( you may need to set some properties with your locations )
  
  Revision  Changes    Path
  1.5       +159 -24   jakarta-tomcat-connectors/jk/jkant/java/org/apache/jk/ant/SoTask.java
  
  Index: SoTask.java
  ===================================================================
  RCS file: /home/cvs/jakarta-tomcat-connectors/jk/jkant/java/org/apache/jk/ant/SoTask.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- SoTask.java	2001/10/26 22:53:56	1.4
  +++ SoTask.java	2001/10/26 23:28:50	1.5
  @@ -186,6 +186,7 @@
   
       // XXX Add specific code for Linux and platforms where things are
       // clean, libtool should be just a fallback.
  +    String srcList[];
       
       public void execute() throws BuildException {
   	if( soFile==null )
  @@ -196,14 +197,14 @@
           if (buildDir == null) buildDir = project.getBaseDir();
   
   	DirectoryScanner ds=src.getDirectoryScanner( project );
  -        String [] list = ds.getIncludedFiles(); 
  -	if (list.length == 0) 
  +	srcList= ds.getIncludedFiles(); 
  +	if (srcList.length == 0) 
               throw new BuildException("No source files");
   
   	Vector compileList=new Vector();
   
  -        for (int i = 0; i < list.length; i++) {
  -	    File srcFile = (File)project.resolveFile(list[i]);
  +        for (int i = 0; i < srcList.length; i++) {
  +	    File srcFile = (File)project.resolveFile(srcList[i]);
               if (!srcFile.exists()) {
                   throw new BuildException("Source \"" + srcFile.getPath() +
                                            "\" does not exist!", location);
  @@ -224,15 +225,27 @@
   	    File f=(File)en.nextElement();
   	    executeLibtoolCompile(f.toString(), includeList );
   	}
  -	
   
  +	File soTarget=new File( buildDir, soFile + ".so" );
  +	if( compileList.size() == 0 && soTarget.exists()) {
  +	    // No dependency, no need to relink
  +	    return;
  +	}
  +
  +	executeLibtoolLink();
  +	
       }
   
       protected static GlobPatternMapper co_mapper=new GlobPatternMapper();
  +    protected static GlobPatternMapper lo_mapper=new GlobPatternMapper();
       static {
   	co_mapper.setFrom("*.c");
   	co_mapper.setTo("*.o");
       }
  +    static {
  +	lo_mapper.setFrom("*.c");
  +	lo_mapper.setTo("*.lo");
  +    }
       
       /** Verify if a .c file needs compilation.
        *	As with javac, we assume a fixed build structure, where all .o
  @@ -264,22 +277,35 @@
   	
       }
       
  -    /** Generate the .so file using 'standard' gcc flags. This assume
  -     *  a 'current' gcc on a 'normal' platform. 
  +    /** Compile  using 'standard' gcc flags. This assume a 'current' gcc on
  +     *  a 'normal' platform - no need for libtool
        */
  -    public void executeGcc() throws BuildException {
  -    }
  -
  -    /** Generate the .so file using libtool.
  -     *  XXX check version, etc.
  -     */
  -    public void executeLibtoolCompile(String source, String includeList[]) throws BuildException
{
  +    public void executeGcc(String source, String includeList[]) throws BuildException {
   	Commandline cmd = new Commandline();
   
  -	String libtool=project.getProperty("build.native.libtool");
  -	if(libtool==null) libtool="libtool";
   	String cc=project.getProperty("build.native.cc");
   	if(cc==null) cc="gcc";
  +	
  +	cmd.setExecutable( cc );
  +	addCCArgs( cmd, source, includeList );
  +
  +	int result=execute( cmd );
  +	if( result!=0 ) {
  +	    log("Compile failed " + result + " " +  source );
  +	    log("Output:" );
  +	    if( outputstream!=null ) 
  +		log( outputstream.toString());
  +	    log("StdErr:" );
  +	    if( errorstream!=null ) 
  +		log( errorstream.toString());
  +	    
  +	    throw new BuildException("Compile failed " + source);
  +	}
  +	closeStreamHandler();
  +
  +    }
  +
  +    private void addCCArgs(Commandline cmd, String source, String includeList[]) {
   	String extra_cflags=project.getProperty("build.native.extra_cflags");
   	String localCflags=cflags;
   	if( localCflags==null ) {
  @@ -290,12 +316,6 @@
   	    }
    	}
   
  -	cmd.setExecutable( libtool );
  -	
  -	cmd.createArgument().setValue("--mode=compile");
  -
  -	cmd.createArgument().setValue( cc );
  -
   	for( int i=0; i<includeList.length; i++ ) {
   	    cmd.createArgument().setValue("-I");
   	    cmd.createArgument().setValue(includeList[i] );
  @@ -306,14 +326,34 @@
   
   	if( localCflags != null )
   	    cmd.createArgument().setLine( localCflags );
  -	
  -	project.log( "Compiling " + source);
   
  +	project.log( "Compiling " + source);
   	cmd.createArgument().setValue( source );
  +    }
  +
  +    /** Compile using libtool.
  +     */
  +    public void executeLibtoolCompile(String source, String includeList[]) throws BuildException
{
  +	Commandline cmd = new Commandline();
   
  +	String libtool=project.getProperty("build.native.libtool");
  +	if(libtool==null) libtool="libtool";
  +
  +	cmd.setExecutable( libtool );
  +	
  +	cmd.createArgument().setValue("--mode=compile");
  +
  +	String cc=project.getProperty("build.native.cc");
  +	if(cc==null) cc="gcc";
  +
  +	cmd.createArgument().setValue( cc );
  +
  +	addCCArgs(cmd, source, includeList);
  +
   	int result=execute( cmd );
   	if( result!=0 ) {
   	    log("Compile failed " + result + " " +  source );
  +	    log("Command:" + cmd.toString());
   	    log("Output:" );
   	    if( outputstream!=null ) 
   		log( outputstream.toString());
  @@ -326,6 +366,101 @@
   	closeStreamHandler();
       }
   
  +    /** Link using gcc ( or ld -G ? ).
  +     */
  +    public void executeGccLink() throws BuildException {
  +
  +    }
  +    
  +    /** Link using libtool.
  +     */
  +    public void executeLibtoolLink() throws BuildException {
  +	Commandline cmd = new Commandline();
  +
  +	String libtool=project.getProperty("build.native.libtool");
  +	if(libtool==null) libtool="libtool";
  +
  +	cmd.setExecutable( libtool );
  +	
  +	cmd.createArgument().setValue("--mode=link");
  +
  +	String cc=project.getProperty("build.native.cc");
  +	if(cc==null) cc="gcc";
  +
  +	cmd.createArgument().setValue( cc );
  +	
  +	cmd.createArgument().setValue("-module");
  +	cmd.createArgument().setValue("-avoid-version");
  +	cmd.createArgument().setValue("-rpath");
  +	cmd.createArgument().setValue( buildDir.getAbsolutePath());
  +
  +	cmd.createArgument().setValue( "-o" );
  +	cmd.createArgument().setValue( soFile + ".la" );
  +
  +	// All .o files must be included
  +	project.log( "Linking " + soFile + ".la");
  +
  +	for( int i=0; i<srcList.length; i++ ) {
  +	    File srcF = (File)project.resolveFile(srcList[i]);
  +	    String name=srcF.getName();
  +	    String targetNA[]=lo_mapper.mapFileName( name );
  +	    if( targetNA!=null )
  +		cmd.createArgument().setValue( targetNA[0] );
  +	}
  +	
  +	int result=execute( cmd );
  +	if( result!=0 ) {
  +	    log("Link failed " + result );
  +	    log("Command:" + cmd.toString());
  +	    log("Output:" );
  +	    if( outputstream!=null ) 
  +		log( outputstream.toString());
  +	    log("StdErr:" );
  +	    if( errorstream!=null ) 
  +		log( errorstream.toString());
  +	    
  +	    throw new BuildException("Link failed " + soFile);
  +	}
  +	closeStreamHandler();
  +
  +	executeLibtoolInstall();
  +    }
  +
  +    /** Final step using libtool.
  +     */
  +    public void executeLibtoolInstall() throws BuildException {
  +	Commandline cmd = new Commandline();
  +
  +	String libtool=project.getProperty("build.native.libtool");
  +	if(libtool==null) libtool="libtool";
  +
  +	cmd.setExecutable( libtool );
  +	
  +	cmd.createArgument().setValue("--mode=install");
  +
  +	cmd.createArgument().setValue( "cp" );
  +
  +	File laFile=new File( buildDir, soFile + ".la" );
  +	cmd.createArgument().setValue( laFile.getAbsolutePath());
  +	
  +	File soFileF=new File( buildDir, soFile + ".so" );
  +	cmd.createArgument().setValue( soFileF.getAbsolutePath());
  +
  +	int result=execute( cmd );
  +	if( result!=0 ) {
  +	    log("Link/install failed " + result );
  +	    log("Command:" + cmd.toString());
  +	    log("Output:" );
  +	    if( outputstream!=null ) 
  +		log( outputstream.toString());
  +	    log("StdErr:" );
  +	    if( errorstream!=null ) 
  +		log( errorstream.toString());
  +	    
  +	    throw new BuildException("Link failed " + soFile);
  +	}
  +	closeStreamHandler();
  +    }
       
       // ==================== Execution utils ==================== 
   
  
  
  

Mime
View raw message