#
# Makefile.postamble-winnt
#
# For PR2 of OpenStep for Windows, building a framework requires manually creating the .DEF
# file declaring all symbols to be exported by the framework DLL.  Fortunately, we
# can automate this process in out makefile.
#
# WARNING: This technique is not sufficient if your framework exports extern pointers to
# data or functions.  It does, however, work for classes, categories, and methods.

tmpfile =  defgenout

$(DEFFILE):
	echo -n "Generating $(DEFFILE)..."
	echo "Tempfile = $(tmpfile)"
	(cd $(OFILE_DIR) ; $(OFILE_LIST_TOOL) -removePrefix $(OFILE_DIR)/ -removePrefix ../ $(NON_SUBPROJ_OFILES) $(SUBPROJ_OFILELISTS) $(OTHER_OFILES) $(OTHER_GENERATED_OFILES) $$adaptors -o $(NAME).ofileList) ;
	(cd $(OFILE_DIR); link -dump -symbols `cat $(NAME).ofileList` | egrep "(SECT).*(External).*(\|)" | egrep -v "(__GLOBAL_$I)|(_OBJC_)" | sed "s/ _/ /" > $(tmpfile))
	echo "LIBRARY $(NAME).dll" > $(DEFFILE)
	echo "EXPORTS" >> $(DEFFILE)
	cat $(OFILE_DIR)/$(tmpfile) | egrep "(SECT2)|(.objc_c)" | gawk '{printf "\t%s CONSTANT\n", $$NF}' >> $(DEFFILE)
	cat $(OFILE_DIR)/$(tmpfile) | egrep -v "(SECT2)|(.objc_c)" | gawk '{printf "\t%s\n", $$NF}'  >> $(DEFFILE)
	rm $(OFILE_DIR)/$(tmpfile);
	echo "Done"

def: $(DEFFILE)
	echo $(DEFFILE) built
