help-make
[Top][All Lists]
Advanced

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

examples of generic build makefiles for shared libs, etc??


From: Robert P. J. Day
Subject: examples of generic build makefiles for shared libs, etc??
Date: Fri, 21 Apr 2006 12:28:29 -0400 (EDT)

  (i asked about something like this once upon a time in a slightly
different context.)

  i'm about to rewrite a bunch of ".mk" Makefiles, each of which is
responsible for building a different kind of object.  as an example,
if i have some source files, and i want to build a shared library, my
*main* Makefile would consist of nothing more than:

  TARGET = fred
  SOURCES = f1.c f2.c f3.c (etc etc)

  include sharedlib.mk

where, in the simple case, sharedlib.mk needs nothing more than that
information to take those source files and create libfred.so.  a
trivial implementation of sharedlib.mk might be:

=============================================================
TARGETLIB = lib${TARGET}.so

OBJECTS = $(subst .c,.o,${SOURCES})
DEPENDS = $(subst .c,.d,${SOURCES})

.PHONY: build clean

build: ${TARGETLIB}

${TARGETLIB}: CFLAGS += -shared
${TARGETLIB}: ${OBJECTS}
        ${CC} ${CPPFLAGS} ${CFLAGS} ${EXTRA_CFLAGS} $^ -o $@
        ${STRIP} $@

${OBJECTS}: CFLAGS += -fPIC
${OBJECTS}: %.o: %.c
        ${CC} ${CPPFLAGS} ${CPP_INCLUDES} ${CFLAGS} -c $< -o $@

clean:
        -rm ${TARGETLIB} ${OBJECTS} ${DEPENDS}

include makedepend.mk
==============================================================

  anyway, you get the idea -- i'm sure thousands of people before me
have done something like this.  in addition, i'd like to spiff this up
a bit -- creating a shared library should allow someone to set the
real name and "soname", specify whether it should be stripped and so
on.  other ".mk" files could be defined that would, given just the
information they need, create an executable, or an archive lib, or
whatever.

  is there a publicly available set of makefiles that do this already?
i know it's pretty standard stuff but i'd be interested in seeing how
the pros do it.  thanks.

rday




reply via email to

[Prev in Thread] Current Thread [Next in Thread]