-CPPFLAGS=-I../../../include -I../../../servers/slapd
-#LDFLAGS=-L/usr/local/openldap/lib
-#LDFLAGS=-L/home/mszulczynski/autogroup/openldap/lib/
-CC=gcc
+CPPFLAGS+=-I../../../include -I../../../servers/slapd
 
-all: autogroup.so
+all: autogroup.la
 
-autogroup.so: autogroup.c
-       $(CC) -shared -fPIC $(CPPFLAGS) $(LDFLAGS) -Wall -o $@ $?
+autogroup.lo:  autogroup.c
+       $(LIBTOOL) --mode=compile $(CC) $(CPPFLAGS) -Wall -c $?
+
+autogroup.la:  autogroup.lo
+       $(LIBTOOL) --mode=link $(CC) -version-info 0:0:0 \
+       -rpath $(PREFIX)/lib -module -o $@ $? 
 
 clean:
-       rm autogroup.so
+       rm -f autogroup.lo autogroup.la
+
+install: autogroup.la
+       mkdir -p $(PREFIX)/lib/openldap
+       $(LIBTOOL) --mode=install cp autogroup.la $(PREFIX)/lib/openldap
+       $(LIBTOOL) --finish $(PREFIX)/lib
 
 # $OpenLDAP$
 CPPFLAGS+=-I../../../include -I../../../servers/slapd 
 CPPFLAGS+=-DSLAPD_OVER_NOPS=SLAPD_MOD_DYNAMIC
-LIBS=-lldap_r -llber -lcrypto
+LIBS=-L$(PREFIX)/lib -lldap_r -llber -lcrypto
 
 all: nops.la
 
                   -rpath $(PREFIX)/lib -module -o $@ $? $(LIBS)
 
 clean:
-       rm nops.lo nops.la
+       rm -f nops.lo nops.la
+
+install: nops.la
+       mkdir -p $(PREFIX)/lib/openldap 
+       mkdir -p $(PREFIX)/man/man5
+       $(LIBTOOL) --mode=install cp nops.la $(PREFIX)/lib/openldap
+       $(LIBTOOL) --finish $(PREFIX)/lib
+       cp nops.5 $(PREFIX)/man/man5
 
 
 smbk5pwd.la:   smbk5pwd.lo
        $(LIBTOOL) --mode=link $(CC) $(OPT) -version-info 0:0:0 \
-       -rpath /usr/local/libexec/openldap -module -o $@ $? $(LIBS)
+       -rpath $(PREFIX)/lib -module -o $@ $? $(LIBS)
+
+clean:
+       rm -f smbk5pwd.lo smbk5pwd.la
+
+install: smbk5pwd.la
+       mkdir -p $(PREFIX)/lib/openldap
+       $(LIBTOOL) --mode=install cp smbk5pwd.la $(PREFIX)/lib/openldap
+       $(LIBTOOL) --finish $(PREFIX)/lib