Advertisement

a makefile

Started by November 11, 2007 10:28 AM
3 comments, last by me minus 16 years, 11 months ago
Can somebody provide me witha makefile that should search for all *.c files inside a folder recursively and compile them ready to be integrated into a *.so archive(in .o forms) I mean: A -a.c -b.h -c.c A/B -d.c -e.h -f.h A/B/C -g.c the result should be a.o,c.o,d.o,g.o all ready to be integrated into a so file
I suppose you have some makefile with specific files for compilation.

You can add shell commands to your script by using $(shell xxx).

In your case it would probably be something like "find . | grep *.c"
or "ls | grep *.c".

Hope that helps.
Advertisement
Honestly, by the time you've made your makefile automatically handle packaging into shared objects, dependencies (e.g., rebuilding a source file that's affected by a modified header), and other tasks that are easy to write in manually but difficult to automate, you'll have recreated Automake or a similar build tool.

Automake (and its affiliated autotools suite) has more than a bit of a learning curve, but I've found it very worthwhile. There are other Makefile generating or replacing tools as well, such as Scons, Ant, imake, cmake, et cetera but I have yet to properly try any of them.

Quote: Original post by hydroo
In your case it would probably be something like "find . | grep *.c"
or "ls | grep *.c".

Try "find . -name '*.c' to simplify a bit.
Autotools (including libtool) introduction without automatic source scanning.
Makefile.am:
lib_LTLIBRARIES = libmyprogram.lalibmyprogram_la_SOURCES = A/a.c A/c.c A/B/d.c A/B/C/g.clibmyprogram_laincludedir      = $(includedir)/myprogramlibmyprogram_lainclude_HEADERS = A/b.h A/B/e.h A/B/f.h

configure.ac:
AC_INIT(myprogram, 0.0.0)AM_INIT_AUTOMAKEAC_PROG_LIBTOOLAC_LANG(C)AC_OUTPUT([Makefile])

Before your first build, you'd have to run some setup programs. Basically:
libtoolize --automake --copyaclocalautomake --add-missing --copy --foreignautoconf

After that, run configure:
./configure --prefix=/tmp/myprogramtest --enable-maintainer-mode

Then make by trying simply "make" and install to your specified prefix with "make install". If you modify Makefile.am but maintainer mode is enabled, the Makefile will automatically be regenerated at the next call to make.
a good paper to read is
http://www.cmcrossroads.com/articles/ask-mr.-make/painless-non%11recursive-make.html

It do not autocompile files but simplifies the task of adding files to the right module/so-file.

for more make fluff:
http://www.cmcrossroads.com/articles/ask-mr.-make.html

This topic is closed to new replies.

Advertisement