views:

130

answers:

2

Hello people, I wanted to create a cross-platform 2D game engine, and I would like to know how to create a cross-platform project with Makefile, so I can compile it to the platforms I choose with custom rule for any platform. I'm working on the windows enviroment with Visual C++ Express 2008, so it would be nice if I can use Visual C++ Express as the IDE.

My platforms are YET the Nintendo DS and the PC.

Please instruct me what to do.

Thanks in advance, Tamir.

+3  A: 

Don't use make, use a cross-platform tool like cmake, it will take care of the platform-specific generation for you. Like on Windows, it will generate the project files to use Visual Studio; on Linux, it will generate the GNU make files for you. You can set it up to find the right versions of the right libraries and everything. Cmake is great.

CMake is not a compiler (neither is make) - it is a cross-platform build automation system. It allows you to develop on any platform and it defaults to assuming you're developing for the platform you're running. You can specify parameters if you want to do other things. However, most of the "cross-platform" stuff is still left to your code. I would also recommend a library that has been tested on many platforms, like Boost. Using Boost can help keep all your code working smoothly on any system and there is basically no overhead to using it. Here is a nice guide to all the things you have to worry about (endian-ness, integer sizes, how to draw, etc.).

Travis Gockel
Thanks for the quick answer, I will try CMake and determine your answer as the best if this works.
Tamir
To get the idea of it, CMake will take care of compiling and such, but it's supporting just some specific platforms?Because I'm also planning to compile for the Nintendo DS (which uses an arm7/arm9 processor).
Tamir
I guess I should have been more clear...I'm editing my answer.
Travis Gockel
I already know boost, I don't think it will work on the DS.I want to create a project which I can just hit the build buttonand it will produce me both Windows library and Nintendo DS library.The DS library will use the arm compiler and the Windows library will use Visual Studio, but both will share the same code (which I can handle for both platforms).It would be nice if you'll help me setting up such a projectand I would also like to pass a PLATFORM definition to know which platform I am compiling to.
Tamir
Almost all of Boost will work on the DS (I'd venture to say all of it, but I'm not sure about some of the OS-dependent stuff, which isn't much). As far as setting things up goes, you can use compilation flags which you specify CMake to create in your makefiles so you can say `make DS` or `make PC` and it will setup the proper flags and defines for you.
Travis Gockel
Well, how can I setup such a project?
Tamir
Read the CMake documentation, it will tell you everything you need to know. Basically, you just have `CMakeList.txt`s in each directory, which point to the files you need in the directory, the things they rely on (import) and how they should be built. You can create settings in CMake and use them in your C++ code. Just read through the tutorial ( http://www.cmake.org/cmake/help/cmake_tutorial.html ), it's quite nice.
Travis Gockel
A: 

I know you can use Makefiles to do #defines, which is, in turn, a common trick for swapping out chunks of code. There are also ways to detect the platform, although that's mostly for Mac/Windows/Linux differences.

Also, Travis is probably right; having your makefiles themselves be cross-platform is really excellent, since it's easier to then setup build servers and things.

Narfanator