Search code examples
eclipsecygwineclipse-cdt

Eclipse Makefile project to be built within a Cygwin environment


We have a project (C) (not a Cygwin exe project, but some embedded cross-compiled one), which has a Makefile designed to be used from within a Cygwin environment. That is the intended use is to open a Cygwin terminal, go t the project directory and run make from there.

I can import this project in Eclipse as a Makefile project, but apparently the regular build command from within Eclipse won't work as it is trying to invoke make in the native (Windows) environment. Is there a way to make Eclipse to run the Cygwin, invoke a make command in it and have the regular CDT error parsers to work? Perhaps by creating a custom builder?


Solution

  • I have managed to work around this problem by using a build script invoking some cygwin commands:

    build.bat:

    @echo off
    c:\cygwin64\bin\bash --login -c "cd %cd:\=/%; make %*"
    

    Breakdown:

    c:\cygwin64\bin\bash --login -c "<command>" - used to invoke a command from within cygwin environment

    cd %cd:\=/%; - is a "dos" %cd% variable (current path) with backslashes replaced by slashes - to avoid these to be stripped down as unescaped.

    make %* - invoke the cygwin make command with all of the arguments passed to this batch file - this is to let Eclipse pass the build target and/or build flags.

    Now in "project build" tab in eclipse I replace the make command with build.bat and it is working like a charm. The only drawback i to have this file in addition to the other project files, but since it is pretty generic it can be reused in any project with these restrictions.