Sign in to follow this  
_Vicious_

Cross-compilation using MingW

Recommended Posts

Hello! Recently I've started using MingW for cross-compilation of linux and windows binaries for our project. However, cross-compilation of Angelscript posed a few problems: 1) Makefile for MingW has its binaries hardcoded to g++ and ar, making it impossible to compile a windows binary in linux. My suggestion is to slightly modify the makefile to use variables in this manner: -CXX = g++ +CXX ?= g++ +AR ?= ar ... - ar rcs $(BIN) $(OBJ) + $(AR) rcs $(BIN) $(OBJ) That'll keep the current behavior but simultaneously allow cross-compilation in this manner: CC=i586-mingw32msvc-gcc AR=i586-mingw32msvc-ar make 2) GnuC and MingW makefiles produce the same library file for all platforms, so running one after another may produce incorrect results. I worked around this by removing libangelscript.a before launching 'make'. but a platform/OS dependent suffix would be a better solution.

Share this post


Link to post
Share on other sites
Sure (the angelscript version we're using is a bit outdated though):

# Angelscript MingW makefile

# Type 'make' then 'make install' to complete the installation of the library



CXX ?= g++

AR ?= ar

CXXFLAGS = -ggdb

SRCDIR = ../../source

OBJDIR = obj

SRCNAMES =
as_arrayobject.cpp
as_atomic.cpp
as_builder.cpp
as_bytecode.cpp
as_callfunc.cpp
as_callfunc_mips.cpp
as_callfunc_ppc_64.cpp
as_callfunc_ppc.cpp
as_callfunc_sh4.cpp
as_callfunc_x86.cpp
as_compiler.cpp
as_configgroup.cpp
as_context.cpp
as_datatype.cpp
as_generic.cpp
as_gc.cpp
as_memory.cpp
as_module.cpp
as_objecttype.cpp
as_outputbuffer.cpp
as_parser.cpp
as_restore.cpp
as_scriptcode.cpp
as_scriptengine.cpp
as_scriptfunction.cpp
as_scriptnode.cpp
as_scriptstruct.cpp
as_string.cpp
as_string_util.cpp
as_thread.cpp
as_tokenizer.cpp
as_typeinfo.cpp
as_variablescope.cpp

OBJ = $(addprefix $(OBJDIR)/, $(notdir $(SRCNAMES:.cpp=.o)))

BIN = ../../lib/libangelscript.a

OBJ_D = $(subst /,\,$(OBJ))

BIN_D = $(subst /,\,$(BIN))

DELETER = del /f

COPIER = copy /y

INCLUDEFILES_D = ..\..\include\angelscript.h

UNINSTALLFILES_D = $(MINGDIR)\lib\libangelscript.a $(MINGDIR)\include\angelscript.h



all: $(BIN)



$(BIN): $(OBJ)

$(AR) rcs $(BIN) $(OBJ)

@echo -------------------------------------------------------------------

@echo Done. Now type 'make install' to install the library on your MinGW.



$(OBJDIR)/%.o: $(SRCDIR)/%.cpp

$(CXX) $(CXXFLAGS) -o $@ -c $<





clean:

$(DELETER) $(OBJ_D) $(BIN_D)



install: $(BIN)

$(COPIER) $(BIN_D) $(MINGDIR)\lib

$(COPIER) $(INCLUDEFILES_D) $(MINGDIR)\include

@echo -------------------------------------------------------------------

@echo Angelscript library installed. Enjoy!



uninstall:

$(DELETER) $(UNINSTALLFILES_D)

@echo -------------------------------------------------------------------

@echo Angelscript library uninstalled.



.PHONY: all clean install uninstall

Share this post


Link to post
Share on other sites
You should look into using CMake (http://www.cmake.org/) for your build scripts. It can generate MSVC (v6-10), MingW, GNU C, CodeBlocks, etc for you, and it does support cross-compiling. If you are interested I can write the CMake files for you and you can give it a try.

-- Jeremy

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this