Re: Makefile for library and application



On 3/13/06, Michael Ott <michael@xxxxxxxxxx> 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



Relevant Pages

  • Re: How do I add search paths to gcc
    ... for libraries and hearders and I added the paths ... LD_LIBRARY_PATH environment variable to set alternate ... what did the person who wrote your project's Makefile use? ... the dependency lines in a makefile are given to the shell (normally ...
    (freebsd-questions)
  • Re: make religion
    ... > Is it uncommon for all of these files to output to the same, ... foo, bar, and baz, and that you produce two executables, ... Each of the src subdirectories has its own makefile, ... All libraries and exes can use -I../../include to find ...
    (comp.unix.programmer)
  • RE: 64 bit OS environment variable
    ... You probably can mention the same in Makefile. ... specify /lib64 inside Makefile where it uses libraries instead of /lib. ... This email remains the property of the Australian Defence ... requested to contact the sender and delete the email. ...
    (RedHat)
  • Re: AMD Opteron + intel fortran (linux)
    ... new math libraries and MPI variants, I really have to do it in a more ... based on Python and with builtin support for multiple environments, ... makefile and Generic makefiles with separate include files for each ... separate compiler/OS combination. ...
    (comp.lang.fortran)
  • Re: AMD Opteron + intel fortran (linux)
    ... against multiple versions of libraries with different compilers? ... new math libraries and MPI variants, I really have to do it in a more ... makefile and Generic makefiles with separate include files for each ... multiple builds using the same source tree. ...
    (comp.lang.fortran)