ProgrammingThis forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
I wonder if there is some software that can generate a makefile for a project, that automatically figures out on what .h files the source files depend?
Depending on why you want to automate that:
If your project become too big to handle makefiles by hand, take a look to autotools, it helps you to generate makefile depending on what libraries your project need, then your project will be buildable with the magic "./configure" and "make" couple.
If your project is not so big but you're too lazy (no blame there), any reasonable ide will do the job by just adding files to your project.
You can try eclipse, kdevelopp, code::blocks, anjuta...
About the IDE suggestion, I was kinda considering them but I am reluctant because when I used Windows I used Visual C++ and it was a nasty experience. Also i tried code::blockas under Windows and it isolates you from what's going on and seemed hard to understand. Maybe some of the other ones are better.
I tries autotools before, but I just could not understand it and it just seems so over-complicated that you can break your head trying to understand it.
Why not just have a file that lists all the .c files, and a program that automatically figures out the dependencies and creates a Makefile?
I was thinking about IDEs, and I thought what do you think would be the best IDE for plain C projects?
I looked at Code::Blocks, Eclipse, and KDevelop, and it seems like Code::Blocks and Eclipse are just too bloated and fancy, and KDevelop is too oriented for C++/Qt projects.
I'm looking at KDevelop 4 and it looks like all the templates are either KDE4 or Qt. I remember there being choices for non-GUI apps before. I guess it's been a while since I looked at it! For non-GUI apps, I'd much rather set up autotools and edit my sources with a text editor. I don't really think an IDE is necessary otherwise.
Kevin Barry
Will it check for dependencies recursively (i.e. if main.c includes foo.h, and foo.h includes bar.h, will changing bar.h cause main.c to be recompiled)?
Seems to me that I saw somewhere that make does not do this.
The point of make is to check dependencies for changes (i.e. change in mod date.) The point of automake and autoconf is to generate the makefiles by determining those dependencies.
Kevin Barry
I thought that the Makefile that ntubski posted just needs you to input your .c files and it does the rest automatically. (by the way, is it possible to just say "src/*.c"?)
I also wonder if it is possible to have the .o files go into a different directory?
Why would I want something like automake and autoconf then?
A simple Makefile using GCC's dependency generation works for a lot of simple cases, but isn't portable and doesn't work nicely for complex build needs.
What exactly is CMake and VS, and how does gcc's dependency generation work and why is it not portable? I thought that make figures out the dependencies.
What exactly is CMake and VS, and how does gcc's dependency generation work and why is it not portable? I thought that make figures out the dependencies.
make doesn't figure out dependencies, rather, given a set of depencies it will regenerate files with the minimum needed work. To figure out depencies between C files you need a tool that understands preprocessor #directives, eg: gcc (see Preprocessor Options). It's not portable in the sense that other compilers might not have an option to do this.
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.