Skip to main content

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index] [List Home]
RE: [cdt-core-dev] Custom Toolchain w/MBS on Windows - backslashes vsforward slashes in paths

Leo & group,

I've never entered anything into Bugzilla before!
Golly, this is exciting! ;) If I'm unable to do it
I'll post another message asking for someone else to
do it.

After about 10 hours of playing with the CDT source
(which included learning Java, GNU Makefiles, and
regular expressions) I found a temporary work around. 
In the place where the GnuMakefileGenerator writes the
compiler/assembler/linker command to the makefile's
rules, I hacked a string replacement:

buildCmd = buildCmd.replaceAll( "@", "(subst /,
\\\\\\\\, \\$@)" );
buildCmd = buildCmd.replaceAll( "<", "(subst /,
\\\\\\\\, \\$<)" );

This changed the makefile cmd line from/to:

@xcc  $@  $<
@xcc  $(subst /,\\,$@) $(subst /,\\,$<)

In the long term I'll probably write a
CommandLineGenerator.

Before I hacked-in the above, I did research
throughout the MBS and GNU MBS code to find where and
how the forward slashes are implemented.  Here's what
I found:

In IManagedBuilderMakefileGenerator and
ManagedCommandLineGenerator, there is a variable
called SEPARATOR which is hard-coded to "/".  Changing
it to "\\" didn't work 100%.  I found that in the
GnuMakefileGenerator.java module, SEPARATOR is used in
some places, but a forward slash is hard-coded in
other places: In the code I have (v3.0.0 release from
Aug) I found hard-coded forward slashes at lines 1799,
1802, 2674, 2676, 2680, and 3367.  There may have been
others that I didn't write down...  That seemed to
change all the relative paths' forward slashes in the
makefiles to backslashes, except in one place - output
targets in the rules kept their forward slashes, such
as:

Src/%.obj: $(ROOT)\Src\%.c
  @echo <blahblahblah>

Src/%.exe: .\Src\%.obj
  @echo <blahblahblah>

The elements of the C_SRCS and OBJS macros contained
paths with backslashes as desired, but make would spit
back an error such as:  "Don't know how to make
.\Src\ODemo.obj" (since it only knows how to make
Src/ODemo.obj).  Other than that, it seemed like make
didn't mind any of the other backslashes throughout
the makefiles.

I never found exactly where this last forward slash
was inserted - I traced it back that the variable
"relativePath" GnuMakefileGenerator.java gets the
forward slashes from ?somewhere? non-obvious.  I
suspect that it's where the paths get manipulated as
"Path" objects, in particular when the
"setDevice(null)" method is called.  I haven't
experimented with this yet, but it looks like the Path
object uses forward or backslashes based on the device
type - if device == "WINDOWS" then it uses
backslashes.  I think setting to null defaults to
forward slashes.

If GNU make *does* accept using backslashes and I'm
not just dreaming here, I recommend that the
GnuMakefileGenerator (and MBS in general) be updated
to use the SEPARATOR identifier everywhere
consistently as well as use the Path setDevice()
method correctly.  Also, SEPARATOR should be set by an
option in the tool's GUI or a function call rather
than hardcoded, just like NEWLINE is:

public final String NEWLINE =
System.getProperty("line.separator");

There's also another line of code that I felt was
fishy in CygwinPathResolver.java at line 84:

result =
lines[0].replace(BS,SLASH).split(DELIMITER_WIN);

BS is '\\' and SLASH is '/'.  This code is changing
backslashes in path names to forward slashes.  If it's
using DELIMITER_WIN rather than DELIMITER_UNIX
(implying that the lines are being formatted for
Windows), shouldn't it be the other way around?

result =
lines[0].replace(SLASH,BS).split(DELIMITER_WIN); 

Whew.  That's all for me for now.  This sure was a
good way to learn a lot!!

--John



--- "Treggiari, Leo" <leo.treggiari@xxxxxxxxx> wrote:

> Hi John,
> 
> This looks like it is a problem in the MBS that will
> need to be fixed.
> Would you enter a bugzilla?  At this point, I'm not
> sure whether it is
> correct to always use the OS separator, or whether a
> compiler like
> Cygwin insists upon the Linux separator.  If the
> latter is true, then
> the separator to use may need to be specified per
> tool.
> 
> Regards,
> Leo
> 
> -----Original Message-----
> From: cdt-core-dev-bounces@xxxxxxxxxxx
> [mailto:cdt-core-dev-bounces@xxxxxxxxxxx] On Behalf
> Of John K
> Sent: Tuesday, October 18, 2005 2:29 PM
> To: cdt-core-dev@xxxxxxxxxxx
> Subject: [cdt-core-dev] Custom Toolchain w/MBS on
> Windows - backslashes
> vsforward slashes in paths
> 
> Hi all,
> 
> I'm having a heck of a time integrating our
> toolchain
> (custom for a 16-bit x86 embedded proc) with the
> Managed Build System.  I've been able to create a
> plug-in, create a project, and get the builder to
> generate a makefile and invoke "make", but make uses
> forward slashes in all of the source file path names
> when it calls the compiler command.  How do I get it
> to use backslashes?  
> 
> I've searched the MBS, eclipse docs, and the web for
> literally two days and I haven't found anything that
> addresses it.  I found an example of how to
> integrate
> MSVC with Eclipse (using make), but they used a
> really
> really simple example that didn't need any relative
> paths to get to the source code modules!
> 
> When I try building, I get:
> 
> **********
> Building file: ../Src/ODemo.c
> Invoking: Custom C/C++ Compiler
> xcc Src/ODemo.obj ../Src/ODemo.c
> XXXXX Compiler Version X
> Copyright (c) XXXXX, Inc. All Rights Reserved.
> 
> Error: Invalid optimization option '.obj'
> Error: Command line contains more than one file to
> compile
> Error: Invalid option '/Src'
> Error: Invalid optimization option '.c'
> Unable to open '..'
> make: *** [Src/ODemo.obj] Error 9
> **********
> 
> I'm guessing it's assuming that I want it to run
> inside the Cygwin environment, but I've read in the
> GNU make docs that it can be run in a DOS style
> shell
> by changing the SHELL variable.  I tried making a
> makefile.init with SHELL=command.com and I get:
> 
> **********
> E:\Work\ODemo>Specified COMMAND search directory bad
> Parameter format not correct
> Too many parameters
> Invalid switch
> Too many parameters
> Invalid switch
> Invalid switch
> Microsoft Windows 2000 [Version 5.00.2195]
> (C) Copyright 1985-2000 Microsoft Corp. 
> **********
> 
> If I try SHELL=cmd.exe I get:
> 
> **********
> E:\Work\ODemo\Release>Microsoft Windows 2000
> [Version
> 5.00.2195]
> (C) Copyright 1985-2000 Microsoft Corp.
> 
> '++' is not recognized as an internal or external
> command,
> operable program or batch file.
> make: *** [Src/ODemo.obj] Error 1
> **********
> 
> I'm guessing the '++' error is because make is
> giving
> its echo statements to cmd.exe: 'Invoking: Custom
> C/C++ Compiler'.
> 
> Any ideas?
> 
> Also, are there any better make/build utilities out
> there for Eclipse CDT projects on Windows?
> 
> Thanks,
> 
> John
> 
> 
> 
> 
> 
> 
> 	
> 		
> __________________________________ 
> Yahoo! Mail - PC Magazine Editors' Choice 2005 
> http://mail.yahoo.com
> _______________________________________________
> cdt-core-dev mailing list
> cdt-core-dev@xxxxxxxxxxx
>
https://dev.eclipse.org/mailman/listinfo/cdt-core-dev
> _______________________________________________
> cdt-core-dev mailing list
> cdt-core-dev@xxxxxxxxxxx
>
https://dev.eclipse.org/mailman/listinfo/cdt-core-dev
> 



	
		
__________________________________ 
Yahoo! Mail - PC Magazine Editors' Choice 2005 
http://mail.yahoo.com


Back to the top