Building LLVM on Windows

Hello,

Thanks to recent changes in the SVN, I was able to successfully build LLVM under Windows in the following environments:

1. Cygwin;
2. MinGW/MSYS;
3. "gcc -mno-cygwin" (a.k.a MinGW on Cygwin).

For 3., I've had to make a few manual changes to the build system. Care is needed because non-Cygwin external commands require Windows paths and Cygwin's make does not like path names with colon in them (as in C:\...). Currently, the only such external command in LLVM's build seems to be tblgen.

I describe below what I've done in case others are interested (I believe that minimal fixes to the configure script would be enough to have everything work out of the box.)

(
The OCaml bindings needs some more work (I've haven't succeeded yet) to compile under Mingw:
- the statement CFLAGS+=... in bindings/ocaml/Makefile.ocaml is destroyed if we set CFLAGS in Makefile.config (this might be solved by using =? instead of = in Makefile.config);
- the variables OCAMLC, OCAMLOPT, OCAMLDEP in Makefile.config are Windows paths (they should be Cygwin paths);
- there should be quotes when adding to CFLAGS in Makefile.ocaml:
CFLAGS += -I"$(shell $(OCAMLC) -where)";
- use $(SYSPATH) as below for all the ocaml commands;
- replace .a with .lib in Makefile.ocaml;
- adapt llvm-config to produce .lib suffixes for --libnames;
- ... (probably other things)
)

* Run the configure script

CFLAGS=-mno-cygwin CXXFLAGS=-mno-cygwin ./configure --prefix=... --build=i686-pc-mingw32 --disable-threads --disable-ltdl-install

* Add the following lines to Makefile.config:

CFLAGS=-mno-cygwin
CXXFLAGS=-mno-cygwin
SYSPATH = $(shell echo $(1) | cygpath -m -f -)

(I could not figure out how to have the configure script pass CFLAGS and CXXFLAGS to Makefile.config. I've tried to add them on configure's command line and in the environment as above. Is this a bug?)

(The configure script could produce the SYSPATH above when asked to compile for MinGW on Cygwin, and just "SYSPATH = $(1)" otherwise.)

* Set variables in include/llvm/Config/config.h:

HAVE_ARGZ_H = 0
HAVE_LIBDL = 0

(The configure script find Cygwin libraries which should not be used here. When asked to compile for MinGW on Cygwin, it should not try to find those libraries.)

* Arrange so that Windows path are passed to the tblgen tool, using the SYSPATH function defined above (might be better to factorize all the calls to tblgen with such a function).

Index: lib/VMCore/Makefile

Hi Alain,

Thanks for all this! I’ll restrict my comments to the ocaml bindings…

The OCaml bindings needs some more work (I’ve haven’t succeeded yet) to compile under Mingw:

  • the statement CFLAGS+=… in bindings/ocaml/Makefile.ocaml is destroyed if we set CFLAGS in Makefile.config (this might be solved by using =? instead of = in Makefile.config);

Can you explain the cause of this behavior? CFLAGS += appears in Makefile.ocaml after include …/Makefile.config to avoid precisely this problem.

  • the variables OCAMLC, OCAMLOPT, OCAMLDEP in Makefile.config are Windows paths (they should be Cygwin paths);

I don’t have a Cygwin environment to test in. Please apply the attached configure.patch to see if it’s suitable (autoconf.patch is the source). If it works well, I’ll commit it.

  • there should be quotes when adding to CFLAGS in Makefile.ocaml:
    CFLAGS += -I"$(shell $(OCAMLC) -where)";

Done.

  • use $(SYSPATH) as below for all the ocaml commands;

Looks like you set SYSPATH by hand? I’ll hold off on this for now.

  • replace .a with .lib in Makefile.ocaml;
  • adapt llvm-config to produce .lib suffixes for --libnames;

I guess we need a configure test?

— Gordon

P.S. — http://lists.cs.uiuc.edu/pipermail/llvmdev/2008-January/011992.html

autoconf.patch (1.05 KB)

configure.patch (214 KB)

Hello,

Thanks to recent changes in the SVN, I was able to successfully build LLVM under Windows in the following environments:

1. Cygwin;
2. MinGW/MSYS;
3. "gcc -mno-cygwin" (a.k.a MinGW on Cygwin).

Great, thats good news, as it did not want to build when I tried it last.

The real issue is building llvm-gcc and llvm-gcc-4.2 though.

Aaron