[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: Makefile for library and application



On 3/13/06, Michael Ott <michael@zolnott.de> wrote:
> I want to write an application which includes library which are also
> written by me.
>
> I can create a makefile for an application and i can create makefile for
> libraries. But is it possible to write both in one makefile with
> subdirs. One for the source of the application, one for the libs and a
> few for the libraries which i want also use for other applications.

It's pretty simple to handle multiple subdirectories.  Here's a
makefile stub for gmake:

DIRS := mylib myapp

.PHONY : $(DIRS)

default : $(DIRS)

$(DIRS) :
<tab>$(MAKE) -C $@

Obviously, you'd want to replace "mylib" and "myapp".  This also
assumes that you have makefiles in the subdirectories, since for
compiling multiple libraries or applications that's generally easier
than trying to make one big makefile for everything.  That's not to
say it can't be done, though.  You'd probably want something like

$(MYLIBSRCS) := $(wildcard mylib/*.c)
$(MYLIBOBJS) := $(patsubst %.c,libmylib.a(%.o),$(MYLIBSRCS))

.PHONY : mylib

mylib : $(MYLIBOBJS)

I'm not sure if this will actually work properly, since I haven't
tested it.  It'll also tend to make your makefile more difficult to
read and maintain.

--
Michael A. Marsh
http://www.umiacs.umd.edu/~mmarsh
http://mamarsh.blogspot.com



Reply to: