Cross-compilation using MingW

Started by
2 comments, last by droz 14 years ago
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.
Advertisement
Would you mind sending me the updated makefile? Or posting it here.

AngelCode.com - game development and more - Reference DB - game developer references
AngelScript - free scripting library - BMFont - free bitmap font generator - Tower - free puzzle game

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 libraryCXX ?= g++AR ?= arCXXFLAGS = -ggdbSRCDIR = ../../sourceOBJDIR = objSRCNAMES =   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.aOBJ_D = $(subst /,\,$(OBJ))BIN_D = $(subst /,\,$(BIN))DELETER = del /fCOPIER = copy /yINCLUDEFILES_D = ..\..\include\angelscript.hUNINSTALLFILES_D = $(MINGDIR)\lib\libangelscript.a $(MINGDIR)\include\angelscript.hall: $(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
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

This topic is closed to new replies.

Advertisement