Box2D Forums

It is currently Fri May 24, 2013 9:03 am

All times are UTC - 8 hours [ DST ]




Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next
Author Message
 Post subject: heres a makefile
PostPosted: Tue Mar 18, 2008 12:45 pm 
Offline

Joined: Mon Mar 17, 2008 9:17 am
Posts: 50
Hello,
I couldn't find a mingw makefile, as I wanted to use my own IDE, but apologies if there already is one. I've made a makefile for mingw that works with either mingw's makefile (mingw32-make) or msys make if MSYS is installed (if you have codeblocks you will probably only have mingw32-make). It works on the current version of box2d with the following targets:

box2d - just the library
examples - the testbed and helloworld, including the glui and glut. as an added bonus testbed doesn't create two windows :)
clean - remove .o files
veryclean - remove .o files and .a files
all - make library and examples

e.g. from the command line
mingw32-make
(will make everything)

mingw32-make box2d
(will make just the library)

substitute mingw32-make for 'make'

Just unzip it in the build folder. Don't know if it'll help anyone :)

I have MSYS, but I disabled it and it worked fine with mingw32-make, but obviously problems do occur sometimes...

The file is attached, but here it is if anyone wants to read it:
Code:
# targets are
#   box2d      - just create the box2d library
#   examples   - just create the examples
#   all      - create everything. or simply call make/mingw32-make by itself
#   clean      - remove all .o files
#   veryclean   - remove all .o and .a files

CC = gcc
CXX = g++
LD = g++
CFLAGS = -O2 -s -fexceptions
LIBDIR = ../../Library
LIBDIRMINGW = ..\..\Library
INCLUDEDIR = ../../Include
EXAMPLES = ../../Examples
SOURCE = ../../Source/
CONTRIB = ../../Contrib/
TESTLIBS = -lBox2d -lfreeglut -lglui -lGLU32 -lOpenGL32 -lWinMM -lGDI32
OBJDIR = obj

OBJ_CPP_CORE += $(addprefix $(OBJDIR)/core/,     $(subst $(SOURCE),,$(patsubst %.cpp,%.o,$(wildcard $(SOURCE)*/*.cpp))))
OBJ_CPP_CORE += $(addprefix $(OBJDIR)/core/,     $(subst $(SOURCE),,$(patsubst %.cpp,%.o,$(wildcard $(SOURCE)*/*/*.cpp))))
OBJ_CPP_GLUI += $(addprefix $(OBJDIR)/glui/,     $(subst $(CONTRIB)glui/,,$(patsubst %.cpp,%.o,$(wildcard $(CONTRIB)glui/*.cpp))))
OBJ_C_FREE   += $(addprefix $(OBJDIR)/freeglut/, $(subst $(CONTRIB)freeglut/,,$(patsubst %.c,%.o,$(wildcard $(CONTRIB)freeglut/*.c))))

ifeq ($(findstring /sh.exe, $(SHELL)), /sh.exe)
UNIX_TOOLS=1
endif

all: createdir box2d examples

examples: createdir hello glui freeglut testbed

box2d:  createdir $(OBJ_CPP_CORE)
   ar rc $(LIBDIR)/libbox2d.a $(OBJDIR)/core/*.o
   @echo   BOX2D LIBRARY MADE 

$(OBJDIR)/core/%.o: $(SOURCE)%.cpp
   $(CXX) $(CFLAGS) -o $(OBJDIR)/core/$(notdir $@) -c $<

createdir:
ifdef UNIX_TOOLS
   -mkdir $(OBJDIR)
   -mkdir $(OBJDIR)/core
   -mkdir $(OBJDIR)/glui
   -mkdir $(OBJDIR)/freeglut
else
   -mkdir $(OBJDIR)
   -mkdir $(OBJDIR)\core
   -mkdir $(OBJDIR)\glui
   -mkdir $(OBJDIR)\freeglut
endif
   @echo   TEMP AREA CREATED 
   
hello:
   $(CXX) $(CFLAGS) -I$(INCLUDEDIR) $(EXAMPLES)/HelloWorld/HelloWorld.cpp -L$(LIBDIR) -lBox2D -o HelloWorld.exe
   @echo   HELLO SAMPLE MADE 

glui: $(OBJ_CPP_GLUI)
   ar rc $(LIBDIR)/libglui.a $(OBJDIR)/glui/*.o
   @echo   GLUI LIBRARY MADE 

$(OBJDIR)/glui/%.o: $(CONTRIB)glui/%.cpp
   $(CXX) $(CFLAGS) -DFREEGLUT_STATIC -I$(CONTRIB)glui -o $(OBJDIR)/glui/$(notdir $@) -c $<

freeglut: $(OBJ_C_FREE)
   ar rc $(LIBDIR)/libfreeglut.a $(OBJDIR)/freeglut/*.o
   @echo   FREEGLUT LIBRARY MADE 

$(OBJDIR)/freeglut/%.o: $(CONTRIB)freeglut/%.c
   $(CC) $(CFLAGS) -DFREEGLUT_STATIC -I$(CONTRIB)freeglut -o $(OBJDIR)/freeglut/$(notdir $@) -c $<

testbed:
   $(CXX) $(CFLAGS) -DFREEGLUT_STATIC  -I$(INCLUDEDIR) -I$(CONTRIB) $(EXAMPLES)/TestBed/Tests/*.cpp $(EXAMPLES)/TestBed/Framework/*.cpp -L$(LIBDIR) $(TESTLIBS) -o TestBed.exe
   @echo   TESTBED DONE 

clean:
ifdef UNIX_TOOLS
   -rm $(OBJDIR)/core/*.o
   -rm $(OBJDIR)/glui/*.o
   -rm $(OBJDIR)/freeglut/*.o
else
   -del $(OBJDIR)\core\*.o
   -del $(OBJDIR)\glui\*.o
   -del $(OBJDIR)\freeglut\*.o
endif
   @echo  DONE CLEAN 

veryclean: clean
ifdef UNIX_TOOLS
   -rm $(LIBDIR)/*.a
else
   -del $(LIBDIRMINGW)\*.a
endif
   @echo  DONE VERYCLEAN 



Attachments:
mingw.zip [1.19 KiB]
Downloaded 337 times
Top
 Profile  
 
 Post subject: Re: heres a makefile
PostPosted: Wed Mar 19, 2008 6:10 pm 
Offline

Joined: Mon Feb 18, 2008 12:30 am
Posts: 88
Great! Works perfectly. This should definitely be included in the distribution.

I'm also going to try to add compiling the Python library to it and see if I get anywhere.


Top
 Profile  
 
 Post subject: Re: heres a makefile
PostPosted: Sun Dec 14, 2008 1:21 pm 
Offline

Joined: Sun Dec 14, 2008 1:18 pm
Posts: 21
From the date I think this was made for version 2.0, does this work with 2.0.1?
If not, would anyone mind making a Mingw makefile for version 2.0.1 as I don't know how to work with makefiles?


Top
 Profile  
 
 Post subject: Re: heres a makefile
PostPosted: Sun Feb 08, 2009 4:09 pm 
Offline

Joined: Sun Feb 08, 2009 1:57 pm
Posts: 34
The distributed makefiles works fine in mingw, there's just the matter of a few missing cstring includes.

You must have msys installed and configured for this to work.

If you unzip version 2.0.1 you will get a directory named Box2D_v2.0.1

Copy my patch into that directory, enter it in msys and type:
Code:
patch -p0 < cstring.1.patch

It will then add the missing '#include <cstring>'s
Note: this will only work if you have Box2d/Source under your current directory, you must adjust the argument to -p depending on your current directory


Then enter the directory named Box2d/Source (cd Box2d/Source) and type 'make'.

This will generate two static files Source/Gen/fixed/libbox2d.a and Source/Gen/float/libbox2d.a Choose then one you wish to use and use it as any library (this will make your binary larger since it includes all the box2d functionality directly into it).

If you wish to create a shared library (e.g. dll) there is the possibility of creating it from the object files under Source/Gen. But that is a different question.


Attachments:
File comment: Patch to add missing includes to box2d_v2.0.1.
Use it in the unzipped directory directly under Box2d.

cstring.1.patch [2.19 KiB]
Downloaded 230 times


Last edited by udoprog on Sun Feb 08, 2009 8:32 pm, edited 1 time in total.
Top
 Profile  
 
 Post subject: Re: heres a makefile
PostPosted: Sun Feb 08, 2009 5:20 pm 
Offline

Joined: Sun Dec 14, 2008 1:18 pm
Posts: 21
OMG, thanks so much, I still have some doubts though.

"You must have msys installed and configured for this to work."
What do you mean by configured? Do I have to do anything else other than installing it?

What is the difference between the "float" and the "fixed" ones?


Top
 Profile  
 
 Post subject: Re: heres a makefile
PostPosted: Sun Feb 08, 2009 7:30 pm 
Offline

Joined: Sun Feb 08, 2009 1:57 pm
Posts: 34
Have a look at this:
http://www.mingw.org/wiki/msys

Msys is a "minimalistic" gnu like system for windows, basically means a much... much more powerful shell than you basic 'cmd'.
It allows you to easily install and run GNU tools on windows, such as patch, diff, gcc... on windows.

As for the float vs fixed, the float version uses whatever float point variable type is available on your system (usually a 32 bit float value) for physics related math operations, while the 'fixed' instead uses a class named Fixed (which is named fixed because it has a fixed 'point' where it starts to represent decimals). Depending on you system using one or the other might be faster.
If this sounds a bit weird to you i recommend that you read on how a float point number is represented in memory. A fixed is the same, the 'float point' is just fixed : P.


Last edited by udoprog on Sun Feb 08, 2009 7:39 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: heres a makefile
PostPosted: Sun Feb 08, 2009 7:39 pm 
Offline

Joined: Sun Dec 14, 2008 1:18 pm
Posts: 21
thanks again, I'll look into it.

And you mentioned my binary would be bigger, how much bigger exactly?


Last edited by Leodick on Sun Feb 08, 2009 8:09 pm, edited 1 time in total.

Top
 Profile  
 
 Post subject: Re: heres a makefile
PostPosted: Sun Feb 08, 2009 7:40 pm 
Offline

Joined: Sun Feb 08, 2009 1:57 pm
Posts: 34
Using a static library basically just cuts and pastes. It will be as much bigger as the .a file.


Top
 Profile  
 
 Post subject: Re: heres a makefile
PostPosted: Sun Feb 08, 2009 8:23 pm 
Offline

Joined: Sun Dec 14, 2008 1:18 pm
Posts: 21
Following the tutorial on the link you posted, I installed "MSYS 1.0.10", "MSYS DTK 1.0" and "MSYS Core 1.0.11".
I skipped the "Set the environment variable HOME to C:\msys\1.0\home", because my windows vista doesn't seem to have this variable.
When i type what you wrote to patch the source I get this: (Picture attached)


Attachments:
Sem título.jpg
Sem título.jpg [ 65.15 KiB | Viewed 4614 times ]
Top
 Profile  
 
 Post subject: Re: heres a makefile
PostPosted: Sun Feb 08, 2009 8:28 pm 
Offline

Joined: Sun Feb 08, 2009 1:57 pm
Posts: 34
Leodick wrote:
Following the tutorial on the link you posted, I installed "MSYS 1.0.10", "MSYS DTK 1.0" and "MSYS Core 1.0.11".
I skipped the "Set the environment variable HOME to C:\msys\1.0\home", because my windows vista doesn't seem to have this variable.
When i type what you wrote to patch the source I get this: (Picture attached)


Since the patch was created in a directory under the one in which you are trying to apply it, you need to use -p1 as argument, to strip the first directory.

That is, my patch assumes that you have Box2d/Source under your working directory, when using -p1 it strips the 'Box2d' part.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 14 posts ]  Go to page 1, 2  Next

All times are UTC - 8 hours [ DST ]


Who is online

Users browsing this forum: No registered users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Powered by phpBB® Forum Software © phpBB Group