Creating a simple Makefile to build a shared library

The solution was to modify the XXFLAGS as follows:

FLAGS        = # -std=gnu99 -Iinclude
CFLAGS       = -fPIC -g #-pedantic -Wall -Wextra -ggdb3
LDFLAGS      = -shared

Example for C++ files. I've also included a clean target.

.PHONY : clean

CPPFLAGS= -fPIC -g
LDFLAGS= -shared

SOURCES = $(shell echo *.cpp)
HEADERS = $(shell echo *.h)
OBJECTS=$(SOURCES:.cpp=.o)

FIKSENGINE_LIBDIR=../../../../lib
FIKSENGINE_INCDIR=../../../../include

TARGET=$(FIKSENGINE_LIBDIR)/tinyxml.so

all: $(TARGET)

clean:
    rm -f $(OBJECTS) $(TARGET)

$(TARGET) : $(OBJECTS)
    $(CC) $(CPPFLAGS) $(OBJECTS) -o $@ $(LDFLAGS)

Compile with -shared:

gcc -o libfoo.so module1.o module2.o -shared

(This also works on MingW under Windows to produce DLLs.)