title: C project: compiling multiple applications with shared sources
body: <p>I am starting a project which has several applications.   These applications share some common functionality in terms of source files.   Each application should have its own make file but be able to link in these shared source files from a common location.</p>
  
  <p>To illustrate this, here's my directory layout:</p>
  
  <pre><code>project/
      lib/
          shared1/
              shared1.c
              shared1.h
          shared2/
              shared2.c
              shared2.h
      app1/
          app1.c
          app1.h
          makefile
      app2/
          app2.c
          app2.h
          makefile
  </code></pre>
  
  <p>Currently one of the makefiles looks a bit like this:</p>
  
  <pre><code>CC=gcc
  XXXCFLAGS=-Wall -Wextra -pedantic -I../../lib/shared1
  CFLAGS=-I. $(XXXCFLAGS)
  DEPS = app2.h ../../lib/shared1/shared1.h
  OBJ = ${DEPS:.h=.o}
  LIBS=-lpthread
  
  %.o: %.c $(DEPS)
      $(CC) -c -o $@ $&lt; $(CFLAGS)
  
  app2: $(OBJ)
      $(CC) -o $@ $^ $(CFLAGS) $(LIBS)
  </code></pre>
  
  <ol>
  <li><p>Is this roughly the right way to go about managing shared source, or is there a better way.   Should they be separately compiled libraries?   If so, how?</p></li>
  <li><p>Are relative paths like this ok?</p></li>
  <li><p>Should I be using autotools for something like this?   After looking at examples I couldn't see how to link shared code or a library.</p></li>
  </ol>
  
  <p>Any guidance is most appreciated.</p>