From 1709d5dc65b82ce1eda86636651f15cf939bc0f4 Mon Sep 17 00:00:00 2001 From: Jeffrey Walton Date: Sun, 6 Jan 2019 22:16:11 -0500 Subject: [PATCH] Update recipes for Nmake file --- TestPrograms/dump2def.cxx | 43 ++++++++++++++++++++++++++++++++------- cryptest.nmake | 20 ++++++++++++++++++ 2 files changed, 56 insertions(+), 7 deletions(-) diff --git a/TestPrograms/dump2def.cxx b/TestPrograms/dump2def.cxx index ad701dad1..1c707e115 100644 --- a/TestPrograms/dump2def.cxx +++ b/TestPrograms/dump2def.cxx @@ -1,8 +1,37 @@ // dump2def.cxx - Written and placed in public domain by Jeffrey Walton -// Create a module definitions file from a dumpbin file/ +// Create a module definitions file from a dumpbin file. // dump2def can be used to create a list of exports from // a static library. Then, the exports can used to build // a dynamic link library with the same exports. +// +// The workflow for Crypto++ is: +// +// 1. Open a Developer Prompt +// 2. CD to cryptopp/ directory +// 3. nmake /f cryptest.nmake cryptopp.dll +// +// The cryptopp.dll recipe first builds cryptlib.lib. Then it calls +// dumpbin.exe to export all symbols from cryptlib.lib and writes them +// to cryptopp.dump. The recipe then calls dump2def.exe to create a +// module definition file. Finally, the recipe builds cryptopp.dll +// using the module definition file cryptopp.def. The linker creates +// the import lib cryptopp.lib and export cryptopp.exp automatically. +// +// This is only "half the problem solved" for those who wish to use +// a DLL. The program must import the import lib cryptopp.lib. Then +// the program must ensure the library headers export the symbol or +// class with CRYPTOPP_DLL. CRYPTOPP_DLL is only present on some classes +// because the FIPS module only allowed approved algorithms like AES and +// SHA. Other classes like Base64Encoder and HexEncoder lack CRYPTOPP_DLL. +// +// CRYPTOPP_DLL simply adds declspec(dllimport) when CRYPTOPP_IMPORTS is +// defined. The limitation of requiring declspec(dllimport) is imposed by +// Microsoft. Microsoft does not allow a program to "import everything". +// +// If you would like to read more about the FIPS module and the pain it +// causes then see https://www.cryptopp.com/wiki/FIPS_DLL. In fact we +// recommend you delete the CryptDll and DllTest projects from the +// Visual Studio solution file. #include #include @@ -27,14 +56,14 @@ void PrintHelpAndExit(int code) std::cout << " dump2def " << std::endl; std::cout << " - Create a def file from and write it to " << std::endl; - + std::exit(code); } int main(int argc, char* argv[]) { // ******************** Handle Options ******************** // - + // Convenience item std::vector opts; for (size_t i=0; i as needed if (opts.size() == 2) { @@ -52,7 +81,7 @@ int main(int argc, char* argv[]) std::string::size_type pos = outfile.length() < 5 ? std::string::npos : outfile.length() - 5; if (pos == std::string::npos || outfile.substr(pos) != ".dump") PrintHelpAndExit(1); - + outfile.replace(pos, 5, ".def"); opts.push_back(outfile); } @@ -75,7 +104,7 @@ int main(int argc, char* argv[]) while (std::getline(infile, line)) { pos = line.find("public symbols"); - if (pos == std::string::npos) { continue; } + if (pos == std::string::npos) { continue; } // Eat the whitespace after the table heading infile >> std::ws; @@ -117,7 +146,7 @@ int main(int argc, char* argv[]) name.erase(pos); outfile << "LIBRARY " << name << std::endl; - outfile << "DESCRIPTION \"Crypto++ Library\"" << std::endl; + outfile << "DESCRIPTION \"Crypto++ Library\"" << std::endl; outfile << "EXPORTS" << std::endl; outfile << std::endl; diff --git a/cryptest.nmake b/cryptest.nmake index 12b1fd3c7..d8ab9d1e9 100644 --- a/cryptest.nmake +++ b/cryptest.nmake @@ -218,6 +218,26 @@ cryptest.exe: pch.pch cryptlib.lib $(TEST_OBJS) cryptlib.lib: $(LIB_OBJS) $(AR) $(ARFLAGS) $(LIB_OBJS) /out:$@ +#map2def source code available in TestPrograms/ +# map2def.exe: map2def.obj +# $(LD) map2def.obj kernel32.lib /out:$@ + +#dump2def source code available in TestPrograms/ +#dump2def.exe: dump2def.obj +# $(LD) dump2def.obj kernel32.lib /out:$@ + +cryptopp.map: + $(LD) $(LDFLAGS) /DLL /MAP /MAPINFO:EXPORTS $(LIB_OBJS) $(LDLIBS) /out:cryptopp.dll + +cryptopp.dump: cryptlib.lib + dumpbin /LINKERMEMBER cryptlib.lib > cryptopp.dump + +cryptopp.def: cryptlib.lib cryptopp.dump + dump2def.exe cryptopp.dump cryptopp.def + +cryptopp.dll: $(LIB_OBJS) cryptopp.def + $(LD) $(LDFLAGS) /DLL /DEF:cryptopp.def /IGNORE:4102 $(LIB_OBJS) $(LDLIBS) /out:$@ + clean: $(RM) /F /Q pch.pch $(LIB_OBJS) pch.obj rdrand-x86.obj rdrand-x64.obj x64masm.obj x64dll.obj cryptlib.lib $(TEST_OBJS) cryptest.exe *.pdb