tags:

views:

82

answers:

3

Hello,

I am just looking for some guidelines, as this might seem like a very open question.

I have a project that has been compiled using Visual Studio 2008 sp1. I have to compile so it will run linux using gcc 4.4.1 C99.

It is a demo application that I didn't write myself.

The source code is written so it can be cross-platform (linux, windows), so the code will compile and run on linux. However, has it has been developed using VS, I don't have any makefile to use.

I could write a make file. But I am not sure about the dependences as there are about 20 files all together (*.c and *.h).

I am just wondering how can I write a makefile from a visual studio project? Is there any settings I can use? and what depends on what? Anything else?

Many thanks for any suggestions,

+3  A: 

One tool that you can use is CMake. CMake can generate a VS.net solution file, and it can generate a Unix makefile. This way is not easy, nor is it the without its bumps in the road. (Especially when the build sequence gets complex)

monksy
+1 for mentioning CMake. The CMake build system is awesome.
Michael Aaron Safyan
+1  A: 

Start with a very simple Makefile:

theapp: *.c *.h Makefile
    gcc *.c -o theapp

Those two lines will get you 90% of the way there (and, in a lot of cases, 100% of the way).

Now you can make and run your app in Unix simply with:

$ make && ./theapp

I don't recommend that you use those complex Makefile generators like automake unless you plan on releasing this stuff to the world.

For private projects, keep your makefiles simple and clean.

Frank Krueger
This just handles the Unix make. Having a cross platform project, one might want to use a tool to generate the appropriate make file per platform.
monksy
The demo application will only be run on a linux platform. So I am only worried about getting it to run on linux.
robUK
Having makefiles that are simple and clean is equally worthwhile when releasing to the world, too.
Mark E
Trust me, a hand-written simple Makefile is 1.618 billion times better than those autogen'd ones - you just have no idea what they're doing and customizing them could take hours of reading documentation. GCC is not a complicated program, write your own command line.
Frank Krueger
Makefiles should not explicitly indicate how to compile a file; simply stating that a ".o" file depends on a ".cpp" or ".c" file is sufficient for Make to know to invoke gcc, and is more portable.
Michael Aaron Safyan
+3  A: 

The makedepend utility will scan the C files you give it, using C preprocessing rules to determine their dependencies and output them to a Makefile.

This should do most of what you want.

caf