Make file for shared objects

dear Experts,

please help,

actually i am trying to create a .so(shared object through make file through ld)
i am not understaning how to proceed i have tried like
through command like i can do it in 2 step like
my progam :test2.c

$gcc -fPIC -c test2.c
$ld -shared -soname test2.so -o test2.so -lc test2.o

this gives me so
but same thing i am trying to achiee through Makefile



PROGRAM = test2.c
INCLUDEDIRS = \
	-I$(ARCENGINEHOME)/include \
	-I/usr/X11R6/include


LIBDIRS = \
	-L$(ARCENGINEHOME)/bin \
	-L/usr/X11R6/lib


LIBS = -larcsdk //here it is giving me error

CXXSOURCES = test2.c # list of source files
CXXOBJECTS = $(CXXSOURCES:.c=.o) # expands to list of object files
CXXFLAGS = -DESRI_UNIX $(INCLUDEDIRS)
CXX = g++

LDFLAGS = $(LIBDIRS) $(LIBS)
all: $(PROGRAM)
$(PROGRAM): $(CXXOBJECTS)
$(CXX) -o $@ $(CXXOBJECTS) $(LDFLAGS)
basic_sample.o: basic_sample.cpp basic_sample.h
$(CXX) $(CXXFLAGS) -c -o basic_sample.o basic_sample.cpp
clean:
$(RM) -f $(CXXOBJECTS) $(PROGRAM)
run:
./$(PROGRAM)

[/code]

but here i want to add test.a which takes the object files like

ar -ur test2.a test2.o

and through this i want to create test2.so
please help me how to achieve this.

expecting your help.

I think this would be better placed in the High Level Programming - The UNIX and Linux Forums forum.

I assume

PROGRAM = test2.c

should be something like

PROGRAM = test2

Since you already have the commands to create static and shared libraries, all you have to do is add to the makefile the library as a target, the object files as dependencies and put this command as the rule, e.g.

test2.so: test2.o
        ld -shared -soname test2.so -o test2.so -lc test2.o
test2.a: test2.o
        ar -ur test2.a test2.o

and then run make test2.a test2.so to see if it works.
You can then (and perhaps should) generalise the rules with automatic variables and so on.