-NT_DYN_DEFS = -DLIBLBER_DECL=dllimport -DLIBLDAP_DECL=dllimport
-
-DEFINES = $(@PLAT@_@LIB_LINKAGE@_DEFS)
-
-# The tricky part about building slapd in NT is that it will export symbols
-# like a DLL. The symbols that it exports should be representative of all
-# of the static symbols that it knows about.
-
-NT_EXP = slapd.exp
-NT_IMPLIB = libslapd.a
-NT_DUMMY = symdummy.o
-
-# Add extra def targets here
-EXTRA_DEFS =
-
-# NT needs this if libltdl is built statically. You'll have to fix the path
-# to point to where libltdl was built, then put ltdl.def in EXTRA_DEFS
-ltdl.def: ../../../libtool/libltdl/*.o
- dlltool --export-all-symbols --output-def $@ $^
-
-DYNAMIC_DEFS = liblber.def libldap_r.def
-
-STATIC_DEFS = libavl.def libldbm.def libldif.def liblutil.def slapd.def \
- $(EXTRA_DEFS)
-
-libavl.def: $(LDAP_LIBDIR)/libavl/*.o
- dlltool --export-all-symbols --output-def $@ `ls $^ | grep -v test`
-
-liblber.def: $(LDAP_LIBDIR)/liblber/*.o
- dlltool --export-all-symbols --output-def $@ `ls $^ | grep -v test`
-
-libldap_r.def: $(LDAP_LIBDIR)/libldap_r/*.o
- dlltool --export-all-symbols --output-def $@ `ls $^ | grep -v test`
-
-libldbm.def: $(LDAP_LIBDIR)/libldbm/*.o
- dlltool --export-all-symbols --output-def $@ `ls $^ | grep -v test`
-
-libldif.def: $(LDAP_LIBDIR)/libldif/*.o
- dlltool --export-all-symbols --output-def $@ `ls $^ | grep -v test`
-
-liblutil.def: $(LDAP_LIBDIR)/liblutil/*.o
- dlltool --export-all-symbols --output-def $@ `ls $^ | grep -v test`
-
-slapd.def: $(OBJS) version.o
- dlltool --export-all-symbols --exclude-symbols main,ServiceMain@8 --output-def $@ `ls $^ | grep -v test`
-
-# We don't want to include symbols from dynamic libraries.
-all.def: $(STATIC_DEFS) $(DYNAMIC_DEFS)
- cat $(STATIC_DEFS) | grep " @ " | sed -e 's/ @ [0-9]*//' > $@
- if [ "@LIB_LINKAGE@" != "DYN" ] ; \
- then \
- cat $(DYNAMIC_DEFS) | grep " @ " | sed -e 's/ @ [0-9]*//' >> $@; \
- fi
- echo EXPORTS > tmp.def
- sort $@ >> tmp.def
- rm -f $@
- dlltool --input-def tmp.def --output-def $@
- rm -f tmp.def
-
-DUMMYTMP = symdummytmp.c
-
-symdummy.c: all.def $(ALL_DEFS)
- rm -f $@
- echo "static void never_called() {" > $(DUMMYTMP)
- cat $< | grep " @ " | while read line; \
+NT_SLAPD_DEPENDS = slapd.exp
+NT_SLAPD_OBJECTS = slapd.exp symdummy.o $(OBJS) version.o
+
+UNIX_SLAPD_DEPENDS = $(SLAPD_STATIC_DEPENDS) version.o $(SLAPD_L)
+UNIX_SLAPD_OBJECTS = $(OBJS) version.o
+
+SLAPD_DEPENDS = $(@PLAT@_SLAPD_DEPENDS)
+SLAPD_OBJECTS = $(@PLAT@_SLAPD_OBJECTS)
+
+# Notes about slapd for Windows
+# =============================
+# slapd.exe must export all of its global symbols, just like a DLL.
+# The purpose of this is to allow dynamic modules (dynamic backends
+# or external dynamic modules) to bind with the symbols at run-time.
+#
+# Exporting symbols from an .EXE is a bit tricky and involves multiple
+# steps. First a .DEF file must be generated. The .DEF file indicates
+# the set of symbols that are to be exported. Many times, it's possible
+# to manually create this file with an editor. However, with slapd,
+# we want to export EVERY global symbol that it knows about (NOT including
+# symbols that are imported from other DLLs). The set of symbols to
+# export INCLUDES symbols from all static libraries that slapd gets
+# linked with, e.g. avl, ldbm, lunicode, lutil, etc. This list
+# will also include liblber and libldap_r if they were built as static
+# libraries. ALSO included will be symbols from other STATIC libraries
+# outside the domain of the OpenLDAP source tree, e.g. regex, ltdl,
+# crypto, ssl, sasl, etc. (If these libraries are dynamic, we won't want
+# to include their symbols in the list). The correct set of symbols
+# CAN be determined at build time. The slapd.def target automatically
+# determines the correct set of symbols and generates the slapd.def file.
+#
+# The slapd.def file, serving multiple purposes, will:
+#
+# 1) be used to generate libslapd.a, the import library for slapd.exe.
+#
+# 2) be used to generate the symdummy.c file.
+#
+# 3) be used to help create slapd.exp, the binary-formated slapd export file.
+#
+# The import library is used by dynamic modules at link time. With this
+# library, dynamic modules indicate to the linker that it will resolve
+# these symbols from the slapd.exe binary at run-time. Of course, whenever
+# a module imports dynamic symbols, those symbols should be marked with
+# the __declspec(dllimport) directive in the header files that the dynamic
+# modules build with. In OpenLDAP, this is handled automatically in the
+# header files. (See ldap_cdefs.h for an explanation). Writers of
+# dynamic backend modules should keep in mind that slapd.exe might export
+# other global symbols that are not part of OpenLDAP (e.g. regex, ltdl,
+# crypto, ssl, sasl, etc.) When a writer actually uses (i.e. imports) these
+# symbols, he must verify that the header files from these external packages
+# include a mechanism to mark imported symbols with the __declspec(dllimport)
+# directive. Whether or not such a mechanism exists, the writer must be
+# able to include these directives appropriately when their symbols are
+# being imported from slapd.exe. The directive is not completely necessary
+# for functions, but it is required for variables.
+#
+# The symdummy.c file basically references EVERY symbol available to slapd.exe,
+# including symbols that slapd.exe never actually refereneced. The file
+# is compiled and included at link time. Without this object file, slapd.exe
+# would NOT export symbols that it never referenced. The reason that these
+# symbols must still be exported is because a dynamic module may want to
+# use a symbol even if it had not been referenced by slapd.exe.
+#
+
+#
+# slapd.def REALLY depends upon all slapd objects and all static libraries
+# included in $(LIBS), including static libraries outside of OpenLDAP.
+# When slapd.def is built, the absolute paths to all static libraries
+# (both inside and outside of OpenLDAP) are generated. We don't have
+# any way to include this generated list as a dependency of slapd.def (sigh).
+# Thus, we do the best we can by depending on version.o, which depends
+# on its own very long list of dependencies.
+#
+slapd.def: libbackends.a version.o
+ @for i in $(LDFLAGS) ; do \
+ path=`expr "$$i" : "-L\(.*\)"`; \
+ if test $$? != 0; then continue; fi; \
+ paths="$$paths $$path"; \
+ done; \
+ objs=""; \
+ for i in $(OBJS) version.o $(LIBS) ; do \
+ obj="" ; \
+ case $$i in \
+ -l*) \
+ done="" ;\
+ base=`expr "$$i" : "-l\(.*\)"`; \
+ for p in $$paths ; do \
+ for ext in la dll a ; do \
+ path=$$p/lib$$base.$$ext; \
+ test ! -f $$path && continue; \
+ if test $$ext = la ; then \
+ for t in dlname old_library ; do \
+ line=`grep "^$$t=" $$path`; \
+ lib=`expr "$$line" : "[^']*'\(.*\)'"`; \
+ test -n "$$lib" && test -f $$p/$$lib && \
+ path=$$p/$$lib && break; \
+ done; \
+ test $$t = dlname && ext=dll; \
+ test $$t = old_library && ext=a; \
+ fi; \
+ if test $$ext = a ; then \
+ obj=$$path; \
+ fi; \
+ done=done; \
+ break; \
+ done; \
+ test -n "$$done" && break; \
+ done; \
+ test -z "$$obj" && continue; \
+ ;; \
+ *.o | *.a) \
+ obj=$$i; \
+ esac; \
+ objs="$$objs $$obj"; \
+ done; \
+ echo dlltool --exclude-symbols main,ServiceMain@8 --export-all-symbols \
+ --output-def $@.tmp $$objs; \
+ dlltool --exclude-symbols main,ServiceMain@8 --export-all-symbols \
+ --output-def $@.tmp $$objs;
+ echo EXPORTS > $@
+ $(SED) -e 1,2d -e 's/ @ [0-9][0-9]*//' $@.tmp | sort >> $@
+ $(RM) $@.tmp
+
+symdummy.c: slapd.def
+ $(RM) $@
+ @echo "generating $@..."; \
+ echo "static void never_called() {" > $@.tmp; \
+ cat $< | while read line; \