[ODE] linux gcc crosscompiling to win32

Peter Honeder peter at gryps.org
Tue Mar 11 10:44:01 2003


This is a multi-part message in MIME format.
--------------030104030901060404080900
Content-Type: text/plain; charset=us-ascii; format=flowed
Content-Transfer-Encoding: 7bit

Hello all!

I have patched the configurator and the main Makefile to compile e.g. 
ODE on linux for a pc-mingw32 host. The problem was to seperate the 
parts of the building system (mainly gcc and settings) and the target 
system.

what the patches do:
Makefile:
- CCTARGET as the compiler for the target system (e.g. 
i686-pc-mingw32-gcc) for the ode files and for some of the compilations 
the configurator does (only header file checking), defaults to CC if not 
specified in makefile.*
- DEFINES_L for the compiler defines for the local system (if required), 
defaults to the values of DEFINES if not specified in makefile.*
- C_EXEOUT_L for the local exe out switch of the compiler, defaults to 
C_EXEOUT if not specified

configurator.c:
- added another parameter to include the target compiler command
- added copmiletarget to compile a file for the target system not the 
build system (uses the second parameter)

I have also included a sample makefile.unix-gcc-cross-mingw32 to show 
how to do a linux to win32 build.
All the old makefile.* files should still work because all the new 
values default to older ones.

I don't know if the changes are all correct and work correctly in any 
cases so please review it. If you see something that could be wrong 
please tell me I can try ode cross compiling nearly anytime and because 
we are using it in our project I would be really interested in having a 
correct version.

Have fun,

Peter

--
Peter Honeder

--------------030104030901060404080900
Content-Type: text/plain;
 name="makefile.unix-gcc-cross-mingw32"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="makefile.unix-gcc-cross-mingw32"

WINDOWS=1
THIS_DIR=./
DEL_CMD=rm -f
CC=gcc
CCTARGET=i686-pc-mingw32-gcc
OBJ=.o
C_FLAGS=-c -Wall -fno-rtti -fno-exceptions -Wall -I/usr/local/win32gcc/include -I/usr/local/win32gcc/i686-pc-mingw32/include -L/usr/local/win32gcc/i686-pc-mingw32/lib -DWIN32
C_INC=-I
C_OUT=-o 
C_EXEOUT=-o 
C_EXEOUT_L=-o
C_DEF=-D
C_OPT=-O
AR=i686-pc-mingw32-ar rc 
RANLIB=
LIB_PREFIX=lib
LIB_SUFFIX=.a
LINK_OPENGL=-lcomctl32 -lkernel32 -luser32 -lgdi32 -lopengl32 -lglu32 -lstdc++
LINK_MATH=-lm
RC_RULE=i686-pc-mingw32-windres -I rc -O coff $< $@

ifeq ($(BUILD),release)
OPT=2
C_FLAGS+=-fomit-frame-pointer -ffast-math
endif

ifeq ($(BUILD),debug)
OPT=0
C_FLAGS+=-g
endif

# some other possible flags:
#   -malign-double -mpentiumpro -march=pentiumpro

--------------030104030901060404080900
Content-Type: text/plain;
 name="Makefile-gcc-cross-mingw32.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="Makefile-gcc-cross-mingw32.patch"

27a28
> 
132a134,145
> ##############################################################################
> # check if target compiler specified
> 
> DEFINES_L=
> ifndef CCTARGET
> # set some default values if a target compiler has not been spcified
> # e.g. the user does not want to cross compile
> CCTARGET=$(CC)
> C_EXEOUT_L=$(C_EXEOUT)
> DEFINES_L=$(DEFINES)
> endif
> 
247c260
< ifeq ($WINDOWS16),1)
---
> ifeq ($(WINDOWS16),1)
252c265
< ifeq ($WINDOWS16),1)
---
> ifeq ($(WINDOWS16),1)
260c273
< 	$(CC) $(C_FLAGS) $(C_INC)$(INCPATH) $(DEFINES) $(C_OPT)1 $(C_OUT)$@ $<
---
> 	$(CCTARGET) $(C_FLAGS) $(C_INC)$(INCPATH) $(DEFINES) $(C_OPT)1 $(C_OUT)$@ $<
263c276
< 	$(CC) $(C_FLAGS) $(C_INC)$(INCPATH) $(DEFINES) $(C_OPT)$(OPT) $(C_OUT)$@ $<
---
> 	$(CCTARGET) $(C_FLAGS) $(C_INC)$(INCPATH) $(DEFINES) $(C_OPT)$(OPT) $(C_OUT)$@ $<
266c279
< 	$(CC) $(C_EXEOUT)$@ $< $(ODE_LIB) $(DRAWSTUFF_LIB) $(RESOURCE_FILE) $(LINK_OPENGL) $(LINK_MATH)
---
> 	$(CCTARGET) $(C_EXEOUT)$@ $< $(ODE_LIB) $(DRAWSTUFF_LIB) $(RESOURCE_FILE) $(LINK_OPENGL) $(LINK_MATH)
270d282
< 
274d285
< 
280c291
< 	$(THIS_DIR)$(CONFIGURATOR_EXE) $(CONFIG_H) "$(CC) $(DEFINES) $(C_EXEOUT)" "$(DEL_CMD)" $(THIS_DIR)
---
> 	$(THIS_DIR)$(CONFIGURATOR_EXE) $(CONFIG_H) "$(CC) $(DEFINES_L) $(C_EXEOUT_L)" "$(CCTARGET) $(DEFINES) $(C_EXEOUT)" "$(DEL_CMD)" $(THIS_DIR)

--------------030104030901060404080900
Content-Type: text/plain;
 name="configurator.c-gcc-cross-mingw32.patch"
Content-Transfer-Encoding: 7bit
Content-Disposition: inline;
 filename="configurator.c-gcc-cross-mingw32.patch"

29c29
< 	<delete-command-line> <THIS_DIR-variable>
---
>   <target-compiler-command-line> <delete-command-line> <THIS_DIR-variable>
183c183
< /* run a compile command */
---
> /* run a buildcompiler compile command */
196a197,208
> /* run a targetcompiler compiler command */
> char *compiletarget_cmd_line = 0;
> void compiletarget (char *output, char *input)
> {
>   char cmd[1000];
>   strcpy (cmd,compiletarget_cmd_line);
>   strcat (cmd,output);
>   strcat (cmd," ");
>   strcat (cmd,input);
>   printf ("%s\n",cmd);
>   system (cmd);
> }
235a248
> /* uses the target compiler to handle cross compiling correctly */
251c264
<     compile ("ctest.exe","ctest.c");
---
>     compiletarget ("ctest.exe","ctest.c");
438,439c451,452
<   if (argc < 4 || argc > 5)
<     fatal_error ("configurator expects 3 or 4 arguments");
---
>   if (argc < 5 || argc > 6)
>     fatal_error ("configurator expects 4 or 5 arguments");
441,442c454,456
<   delete_cmd_line = argv[3];
<   if (argc >= 5) run_prefix = argv[4];
---
>   compiletarget_cmd_line = argv[3];
>   delete_cmd_line = argv[4];
>   if (argc >= 6) run_prefix = argv[5];

--------------030104030901060404080900--