From e54b5f0d2e1f29d8efcd88250d4bd17558dc06b4 Mon Sep 17 00:00:00 2001 From: Timo Kreuzer Date: Mon, 6 Jun 2011 09:58:58 +0000 Subject: [PATCH] [SPEC2DEF] - Fix build of importlibraries on MSVC / amd64 svn path=/trunk/; revision=52110 --- reactos/msc.cmake | 9 ++++-- reactos/tools/spec2def/spec2def.c | 47 +++++++++++++++++++++++-------- 2 files changed, 42 insertions(+), 14 deletions(-) diff --git a/reactos/msc.cmake b/reactos/msc.cmake index 38269e779e5..5243125d5f5 100644 --- a/reactos/msc.cmake +++ b/reactos/msc.cmake @@ -24,6 +24,9 @@ endif() if(${ARCH} MATCHES amd64) add_definitions(-D__x86_64) + set(SPEC2DEF_ARCH x86_64) +else() + set(SPEC2DEF_ARCH i386) endif() link_directories("${REACTOS_BINARY_DIR}/importlibs" ${REACTOS_BINARY_DIR}/lib/sdk/crt) @@ -130,7 +133,7 @@ macro(add_importlib_target _exports_file) # Generate the asm stub file and the export def file add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def - COMMAND native-spec2def --ms --kill-at -r -n=${_name}${_suffix} -d=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def -l=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} + COMMAND native-spec2def --ms --kill-at -a=${SPEC2DEF_ARCH} -r -n=${_name}${_suffix} -d=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def -l=${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.asm ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_exports_file}) # Assemble the stub file @@ -149,7 +152,7 @@ macro(add_importlib_target _exports_file) # Build the importlib add_custom_command( OUTPUT ${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib - COMMAND LINK /LIB /NOLOGO /MACHINE:X86 /DEF:${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def /OUT:${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${_libraries} + COMMAND LINK /LIB /NOLOGO /DEF:${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def /OUT:${CMAKE_BINARY_DIR}/importlibs/lib${_name}.lib ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${_libraries} DEPENDS ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_stubs.obj ${CMAKE_BINARY_DIR}/importlibs/lib${_name}_exp.def) # Add the importlib target @@ -174,7 +177,7 @@ macro(spec2def _dllname _spec_file) get_filename_component(_file ${_spec_file} NAME_WE) add_custom_command( OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c - COMMAND native-spec2def --ms --kill-at -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} + COMMAND native-spec2def --ms --kill-at -a=${SPEC2DEF_ARCH} -n=${_dllname} -d=${CMAKE_CURRENT_BINARY_DIR}/${_file}.def -s=${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file} DEPENDS ${CMAKE_CURRENT_SOURCE_DIR}/${_spec_file}) set_source_files_properties(${CMAKE_CURRENT_BINARY_DIR}/${_file}.def ${CMAKE_CURRENT_BINARY_DIR}/${_file}_stubs.c PROPERTIES GENERATED TRUE) diff --git a/reactos/tools/spec2def/spec2def.c b/reactos/tools/spec2def/spec2def.c index d88d2e490b9..d0d1a136f68 100644 --- a/reactos/tools/spec2def/spec2def.c +++ b/reactos/tools/spec2def/spec2def.c @@ -10,7 +10,7 @@ typedef struct { char *pcName; - int nNameLength; + size_t nNameLength; char *pcRedirection; int nRedirectionLength; int nCallingConvention; @@ -21,11 +21,21 @@ typedef struct unsigned int uFlags; } EXPORT; +enum _ARCH +{ + ARCH_X86, + ARCH_AMD64, + ARCH_IA64, + ARCH_ARM, + ARCH_PPC +}; + typedef int (*PFNOUTLINE)(FILE *, EXPORT *); int gbKillAt = 0; int gbUseDeco = 0; int gbMSComp = 0; int no_redirections = 0; +int giArch = ARCH_X86; char *pszArchString = "i386"; char *pszArchString2; char *pszDllName = 0; @@ -151,7 +161,7 @@ OutputLine_stub(FILE *file, EXPORT *pexp) (pexp->uFlags & FL_STUB) == 0) return 0; fprintf(file, "int "); - if (strcmp(pszArchString, "i386") == 0 && + if ((giArch == ARCH_X86) && pexp->nCallingConvention == CC_STDCALL) { fprintf(file, "__stdcall "); @@ -218,8 +228,12 @@ OutputLine_stub(FILE *file, EXPORT *pexp) void OutputHeader_asmstub(FILE *file, char *libname) { - fprintf(file, "; File generated automatically, do not edit! \n\n" - ".586\n.model flat\n.code\n"); + fprintf(file, "; File generated automatically, do not edit! \n\n"); + + if (giArch == ARCH_X86) + fprintf(file, ".586\n.model flat\n"); + + fprintf(file, ".code\n"); } int @@ -231,6 +245,12 @@ OutputLine_asmstub(FILE *fileDest, EXPORT *pexp) fprintf(fileDest, "PUBLIC ordinal%d\nordinal%d: nop\n", pexp->nOrdinal, pexp->nOrdinal); } + else if (giArch == ARCH_AMD64) + { + fprintf(fileDest, "PUBLIC %.*s\n%.*s: nop\n", + pexp->nNameLength, pexp->pcName, + pexp->nNameLength, pexp->pcName); + } else if (pexp->nCallingConvention == CC_STDCALL) { fprintf(fileDest, "PUBLIC _%.*s@%d\n_%.*s@%d: nop\n", @@ -274,7 +294,7 @@ void PrintName(FILE *fileDest, EXPORT *pexp, int fRedir, int fDeco) { char *pcName = fRedir ? pexp->pcRedirection : pexp->pcName; - int nNameLength = fRedir ? pexp->nRedirectionLength : pexp->nNameLength; + size_t nNameLength = fRedir ? pexp->nRedirectionLength : pexp->nNameLength; if (fDeco && pexp->nCallingConvention == CC_FASTCALL) fprintf(fileDest, "@"); @@ -450,7 +470,7 @@ ParseFile(char* pcStart, FILE *fileDest, PFNOUTLINE OutputLine) } else if (CompareToken(pc, "-i386")) { - if (strcasecmp(pszArchString, "i386") != 0) included = 0; + if (giArch == ARCH_X86) included = 0; } else if (CompareToken(pc, "-private")) { @@ -572,7 +592,7 @@ ParseFile(char* pcStart, FILE *fileDest, PFNOUTLINE OutputLine) { /* Check for stdcall name */ char *p = strchr(pc, '@'); - if (p && (p - pc < exp.nNameLength)) + if (p && ((size_t)(p - pc) < exp.nNameLength)) { int i; exp.nNameLength = p - pc; @@ -694,15 +714,20 @@ int main(int argc, char *argv[]) } } - if ((strcasecmp(pszArchString, "x86_64") == 0) || - (strcasecmp(pszArchString, "ia64") == 0)) + if (strcasecmp(pszArchString, "i386") == 0) giArch = ARCH_X86; + else if (strcasecmp(pszArchString, "x86_64") == 0) giArch = ARCH_AMD64; + else if (strcasecmp(pszArchString, "ia64") == 0) giArch = ARCH_IA64; + else if (strcasecmp(pszArchString, "arm") == 0) giArch = ARCH_ARM; + else if (strcasecmp(pszArchString, "ppc") == 0) giArch = ARCH_PPC; + + if ((giArch == ARCH_AMD64) || (giArch = ARCH_IA64)) { pszArchString2 = "win64"; } else pszArchString2 = "win32"; - if (strcasecmp(pszArchString, "i386") == 0) + if (giArch == ARCH_X86) { gbUseDeco = 1; } @@ -711,7 +736,7 @@ int main(int argc, char *argv[]) if (!pszDllName) { char *p1, *p2; - int len; + size_t len; p1 = strrchr(argv[i], '\\'); if (!p1) p1 = strrchr(argv[i], '/');