diff --git a/reactos/Makefile b/reactos/Makefile index 52c59dd049c..e6a7d58b371 100644 --- a/reactos/Makefile +++ b/reactos/Makefile @@ -242,6 +242,7 @@ ifeq ($(HALFVERBOSEECHO),yes) ECHO_OBJDUMP =@echo $(QUOTE)[OBJDUMP] $@$(QUOTE) ECHO_RBUILD =@echo $(QUOTE)[RBUILD] $@$(QUOTE) ECHO_RSYM =@echo $(QUOTE)[RSYM] $@$(QUOTE) + ECHO_PEFIXUP =@echo $(QUOTE)[PEFIXUP] $@$(QUOTE) ECHO_WMC =@echo $(QUOTE)[WMC] $@$(QUOTE) ECHO_NCI =@echo $(QUOTE)[NCI] $@$(QUOTE) ECHO_CABMAN =@echo $(QUOTE)[CABMAN] $<$(QUOTE) diff --git a/reactos/ReactOS-amd64.rbuild b/reactos/ReactOS-amd64.rbuild index 149506bda87..f33c20f8be7 100644 --- a/reactos/ReactOS-amd64.rbuild +++ b/reactos/ReactOS-amd64.rbuild @@ -20,7 +20,6 @@ - -Os @@ -48,9 +47,14 @@ -Wno-multichar -Wno-format - -disable-stdcall-fixup - -static - --unique=.eh_frame + + + -disable-stdcall-fixup + -static + --unique=.eh_frame + -file-alignment=0x1000 + -section-alignment=0x1000 + @@ -191,7 +195,7 @@ - + diff --git a/reactos/ReactOS-arm.rbuild b/reactos/ReactOS-arm.rbuild index de897e8629c..aac72e02a0c 100644 --- a/reactos/ReactOS-arm.rbuild +++ b/reactos/ReactOS-arm.rbuild @@ -8,17 +8,16 @@ - + - + - - + - + include/reactos/arm @@ -32,12 +31,14 @@ -Wno-attributes - + - + --strip-debug -static + -file-alignment=0x1000 + -section-alignment=0x1000 diff --git a/reactos/ReactOS-i386.rbuild b/reactos/ReactOS-i386.rbuild index 6f295ee8dbf..b6fc035dd91 100644 --- a/reactos/ReactOS-i386.rbuild +++ b/reactos/ReactOS-i386.rbuild @@ -16,7 +16,6 @@ - @@ -30,6 +29,8 @@ -disable-stdcall-fixup + -file-alignment=0x1000 + -section-alignment=0x1000 diff --git a/reactos/tools/rbuild/backend/codeblocks/codeblocks.cpp b/reactos/tools/rbuild/backend/codeblocks/codeblocks.cpp index 74479a857d7..b1fb3f1c406 100644 --- a/reactos/tools/rbuild/backend/codeblocks/codeblocks.cpp +++ b/reactos/tools/rbuild/backend/codeblocks/codeblocks.cpp @@ -598,7 +598,7 @@ CBBackend::_generate_cbproj ( const Module& module ) if ( sys ) { - fprintf ( OUT, "\t\t\t\t\t\r\n", "_", module.GetEntryPoint(false) == "" ? "DriverEntry@8" : module.GetEntryPoint(false).c_str ()); + fprintf ( OUT, "\t\t\t\t\t\r\n", "_", module.GetEntryPoint() == "" ? "DriverEntry@8" : module.GetEntryPoint().c_str ()); fprintf ( OUT, "\t\t\t\t\t\r\n", baseaddr == "" ? "0x10000" : baseaddr.c_str () ); fprintf ( OUT, "\t\t\t\t\t\r\n" ); } @@ -623,7 +623,7 @@ CBBackend::_generate_cbproj ( const Module& module ) } else if ( dll ) { - fprintf ( OUT, "\t\t\t\t\t\r\n", "_", module.GetEntryPoint(false).c_str () ); + fprintf ( OUT, "\t\t\t\t\t\r\n", "_", module.GetEntryPoint().c_str () ); fprintf ( OUT, "\t\t\t\t\t\r\n", baseaddr == "" ? "0x40000" : baseaddr.c_str () ); if ( module.type == Win32DLL) diff --git a/reactos/tools/rbuild/backend/mingw/linkers/ld.mak b/reactos/tools/rbuild/backend/mingw/linkers/ld.mak index a8de2ed235b..812f30ec874 100644 --- a/reactos/tools/rbuild/backend/mingw/linkers/ld.mak +++ b/reactos/tools/rbuild/backend/mingw/linkers/ld.mak @@ -1,32 +1,70 @@ -#~ #(module, objs, deps, ldflags, output, libs, subsys, entry, base, falign, salign) -#~ define RBUILD_LINK +LDFLAG_DLL:=-shared +LDFLAG_DRIVER:=-shared --subsystem=native +LDFLAG_NOSTDLIB:=-nostartfiles -nostdlib +LDFLAG_CONSOLE:=--subsystem=console +LDFLAG_WINDOWS:=--subsystem=windows +LDFLAG_NATIVE:=--subsystem=native -#~ $(5) ${call RBUILD_output_dir,$(5)}$$(SEP)$(basename $(notdir $(5))).map: $(2) $(3) $(6) | ${call RBUILD_dir,$(5)} - #~ $$(ECHO_CC) - #~ $${ld} -subsystem=$(7) -entry=$(8) -base=$(9) -file-alignment=$(10) -section-alignment=$(11) $(2) $(6) ${call RBUILD_ldflags,$(1),$(4)} -o $(5) -#~ ifeq ($(ROS_BUILDMAP),full) - #~ $$(ECHO_OBJDUMP) - #~ $${objdump} -d -S $$@ > ${call RBUILD_output_dir,$(5)}$$(SEP)$(basename $(notdir $(5))).map -#~ else -#~ ifeq ($(ROS_BUILDMAP),yes) - #~ $$(ECHO_NM) - #~ $${nm} --numeric-sort $$@ > ${call RBUILD_output_dir,$(5)}$$(SEP)$(basename $(notdir $(5))).map -#~ endif -#~ endif -#~ ifeq ($(ROS_BUILDNOSTRIP),yes) - #~ $$(ECHO_CP) - #~ $${cp} $(5) $(basename $(5)).nostrip$(suffix $(5)) 1>$(NUL) -#~ endif -#~ ifneq ($(ROS_GENERATE_RSYM),no) - #~ $$(ECHO_RSYM) - #~ $$(Q)$$(rsym_TARGET) $$@ $$@ -#~ endif -#~ ifeq ($(ROS_LEAN_AND_MEAN),yes) - #~ $$(ECHO_STRIP) - #~ $${strip} -s -x -X $$@ -#~ endif +#(module, objs, deps, ldflags, output, def, libs, entry, base) +define RBUILD_LINK -#~ endef +ifneq ($(6),) +${call RBUILD_intermediate_dir,$(5)}$$(SEP)lib${call RBUILD_name,$(5)}.a: $(6) | ${call RBUILD_intermediate_path,$(5)} + $$(ECHO DLLTOOL) + $${dlltool} --def $(6) --kill-at --output-lib=$$@ -#~ #(module, dependencies, ldflags, subsys, entry, base, falign, salign) -#~ RBUILD_LINK_RULE=${call RBUILD_LINK,$(1),$(1)_OBJS,$(2),$(3),$(1)_TARGET,$(1)_LIBS,$(4),$(5),$(6),$(7),$(8)} +${call RBUILD_intermediate_dir,$(5)}$$(SEP)lib${call RBUILD_name,$(5)}.delayimp.a: $(6) | ${call RBUILD_intermediate_path,$(5)} + $$(ECHO DLLTOOL) + $${dlltool} --def $(6) --kill-at --output-delaylib=$$@ + +${call RBUILD_intermediate_path_noext,$(5)}.exp: $(6) | ${call RBUILD_intermediate_path,$(5)} + $$(ECHO DLLTOOL) + $${dlltool} --def $(6) --kill-at --output-exp=$$@ + +$(1)_CLEANFILES+=\ + ${call RBUILD_intermediate_dir,$(5)}$$(SEP)lib$(notdir $(5)).a \ + ${call RBUILD_intermediate_dir,$(5)}$$(SEP)lib$(notdir $(5)).delayimp.a \ + ${call RBUILD_intermediate_path_noext,$(5)}.exp +endif + +$(5): $(2) $$(if $(6),${call RBUILD_intermediate_path_noext,$(5)}.exp) $(7) $(3) $$(RSYM_TARGET) $$(PEFIXUP_TARGET) | ${call RBUILD_dir,$(5)} + $$(ECHO_LD) + $${ld} --entry=$(8) --image-base=$(9) $(2) $$(if $(6),${call RBUILD_intermediate_path_noext,$(5)}.exp) $(7) ${call RBUILD_ldflags,$(1),$(4)} -o $$@ +ifneq ($(or $(6),$$(MODULETYPE$$($(1)_TYPE)_KMODE)),) + $$(ECHO_PEFIXUP) + $$(Q)$$(PEFIXUP_TARGET) $$@ $(if $(6),-exports) $$(if $$(MODULETYPE$($(1)_TYPE)_KMODE),-sections) +endif +ifeq ($(ROS_BUILDMAP),full) + $$(ECHO_OBJDUMP) + $${objdump} -d -S $$@ > ${call RBUILD_output_path_noext,$(5)}.map +else +ifeq ($(ROS_BUILDMAP),yes) + $$(ECHO_NM) + $${nm} --numeric-sort $$@ > ${call RBUILD_output_path_noext,$(5)}.map +endif +endif +ifeq ($(ROS_BUILDNOSTRIP),yes) + $$(ECHO_CP) + $${cp} $(5) $(basename $(5)).nostrip$(suffix $(5)) 1>$(NUL) +endif +ifneq ($(ROS_GENERATE_RSYM),no) + $$(ECHO_RSYM) + $$(Q)$$(RSYM_TARGET) $$@ $$@ +endif +ifeq ($(ROS_LEAN_AND_MEAN),yes) + $$(ECHO_STRIP) + $${strip} -s -x -X $$@ +endif + +ifneq ($(ROS_BUILDMAP),) +$(1)_CLEANFILES+=${call RBUILD_output_path_noext,$(5)}.map +endif + +ifeq ($(ROS_BUILDNOSTRIP),yes) +$(1)_CLEANFILES+=$(basename $(5)).nostrip$(suffix $(5)) +endif + +endef + +#(module, def, deps, ldflags, libs, entry, base) +RBUILD_LINK_RULE=${call RBUILD_LINK,$(1),$(value $(1)_OBJS),$(3),$(4),$(value $(1)_TARGET),$(2),$(5) $(value $(1)_LIBS) $(5),$(6),$(7)} diff --git a/reactos/tools/rbuild/backend/mingw/mingw.cpp b/reactos/tools/rbuild/backend/mingw/mingw.cpp index 77893a1006d..472e5960dac 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.cpp +++ b/reactos/tools/rbuild/backend/mingw/mingw.cpp @@ -38,16 +38,16 @@ const struct ModuleHandlerInformations ModuleHandlerInformations[] = { { HostTrue, "", "", "" }, // BuildTool { HostFalse, "", "", "" }, // StaticLibrary { HostFalse, "", "", "" }, // ObjectLibrary - { HostFalse, "", "", "" }, // Kernel - { HostFalse, "", "", "" }, // KernelModeDLL - { HostFalse, "-D__NTDRIVER__", "", "" }, // KernelModeDriver - { HostFalse, "", "", "" }, // NativeDLL - { HostFalse, "-D__NTAPP__", "", "" }, // NativeCUI - { HostFalse, "", "", "" }, // Win32DLL - { HostFalse, "", "", "" }, // Win32OCX - { HostFalse, "", "", "" }, // Win32CUI - { HostFalse, "", "", "" }, // Win32GUI - { HostFalse, "", "", "-nostartfiles -nostdlib" }, // BootLoader + { HostFalse, "", "", "$(LDFLAG_DRIVER)" }, // Kernel + { HostFalse, "", "", "$(LDFLAG_DRIVER)" }, // KernelModeDLL + { HostFalse, "-D__NTDRIVER__", "", "$(LDFLAG_DRIVER)" }, // KernelModeDriver + { HostFalse, "", "", "$(LDFLAG_DLL)" }, // NativeDLL + { HostFalse, "-D__NTAPP__", "", "$(LDFLAG_NATIVE)" }, // NativeCUI + { HostFalse, "", "", "$(LDFLAG_DLL)" }, // Win32DLL + { HostFalse, "", "", "$(LDFLAG_DLL)" }, // Win32OCX + { HostFalse, "", "", "$(LDFLAG_CONSOLE)" }, // Win32CUI + { HostFalse, "", "", "$(LDFLAG_WINDOWS)" }, // Win32GUI + { HostFalse, "", "", "" }, // BootLoader { HostFalse, "", "-f bin", "" }, // BootSector { HostFalse, "", "", "" }, // Iso { HostFalse, "", "", "" }, // LiveIso @@ -55,8 +55,8 @@ const struct ModuleHandlerInformations ModuleHandlerInformations[] = { { HostFalse, "", "", "" }, // RpcServer { HostFalse, "", "", "" }, // RpcClient { HostFalse, "", "", "" }, // Alias - { HostFalse, "", "", "-nostartfiles -nostdlib" }, // BootProgram - { HostFalse, "", "", "" }, // Win32SCR + { HostFalse, "", "", "" }, // BootProgram + { HostFalse, "", "", "$(LDFLAG_WINDOWS)" }, // Win32SCR { HostFalse, "", "", "" }, // IdlHeader { HostFalse, "", "", "" }, // IdlInterface { HostFalse, "", "", "" }, // EmbeddedTypeLib @@ -64,7 +64,7 @@ const struct ModuleHandlerInformations ModuleHandlerInformations[] = { { HostFalse, "", "", "" }, // RpcProxy { HostTrue, "", "", "" }, // HostStaticLibrary { HostFalse, "", "", "" }, // Cabinet - { HostFalse, "", "", "" }, // KeyboardLayout + { HostFalse, "", "", "$(LDFLAG_DLL)" }, // KeyboardLayout { HostFalse, "", "", "" }, // MessageHeader }; @@ -413,17 +413,17 @@ MingwBackend::GenerateGlobalProperties ( } string -MingwBackend::GenerateProjectLFLAGS () const +MingwBackend::GenerateProjectLDFLAGS () const { - string lflags; + string ldflags; for ( size_t i = 0; i < ProjectNode.linkerFlags.size (); i++ ) { LinkerFlag& linkerFlag = *ProjectNode.linkerFlags[i]; - if ( lflags.length () > 0 ) - lflags += " "; - lflags += linkerFlag.flag; + if ( ldflags.length () > 0 ) + ldflags += " "; + ldflags += linkerFlag.flag; } - return lflags; + return ldflags; } void @@ -478,24 +478,21 @@ MingwBackend::GenerateGlobalVariables () const // Would be nice to have our own C++ runtime fputs ( "BUILTIN_CXXINCLUDES+= $(TARGET_CPPFLAGS)\n", fMakefile ); - } - // Because RosBE gcc is built to suck - fputs ( "BUILTIN_HOST_CINCLUDES+= $(HOST_CFLAGS)\n", fMakefile ); - fputs ( "BUILTIN_HOST_CPPINCLUDES+= $(HOST_CFLAGS)\n", fMakefile ); - fputs ( "BUILTIN_HOST_CXXINCLUDES+= $(HOST_CPPFLAGS)\n", fMakefile ); + fprintf ( fMakefile, "PROJECT_CCLIBS := $(shell ${TARGET_CC} -print-libgcc-file-name)\n" ); + fprintf ( fMakefile, "PROJECT_CXXLIBS := $(shell ${TARGET_CPP} -print-file-name=libstdc++.a) $(shell ${TARGET_CPP} -print-file-name=libgcc.a) $(shell ${TARGET_CPP} -print-file-name=libmingw32.a) $(shell ${TARGET_CPP} -print-file-name=libmingwex.a) $(shell ${TARGET_CPP} -print-file-name=libcoldname.a)\n" ); + + /* hack to get libgcc_eh.a, should check mingw version or something */ + if (Environment::GetArch() == "amd64") + { + fprintf ( fMakefile, "PROJECT_LPPFLAGS += $(shell ${TARGET_CPP} -print-file-name=libgcc_eh.a)\n" ); + } + } MingwModuleHandler::GenerateParameters ( "PROJECT", "+=", ProjectNode.non_if_data ); MingwModuleHandler::GenerateParameters ( "PROJECT_HOST", "+=", ProjectNode.host_non_if_data ); - // TODO: linker flags - fprintf ( fMakefile, "PROJECT_LFLAGS := '$(shell ${TARGET_CC} -print-libgcc-file-name)' %s\n", GenerateProjectLFLAGS ().c_str () ); - fprintf ( fMakefile, "PROJECT_LPPFLAGS := '$(shell ${TARGET_CPP} -print-file-name=libstdc++.a)' '$(shell ${TARGET_CPP} -print-file-name=libgcc.a)' '$(shell ${TARGET_CPP} -print-file-name=libmingw32.a)' '$(shell ${TARGET_CPP} -print-file-name=libmingwex.a)' '$(shell ${TARGET_CPP} -print-file-name=libcoldname.a)'\n" ); - /* hack to get libgcc_eh.a, should check mingw version or something */ - if (Environment::GetArch() == "amd64") - { - fprintf ( fMakefile, "PROJECT_LPPFLAGS += '$(shell ${TARGET_CPP} -print-file-name=libgcc_eh.a)'\n" ); - } + fprintf ( fMakefile, "PROJECT_LDFLAGS := %s\n", GenerateProjectLDFLAGS ().c_str () ); // TODO: use symbolic names for module types for ( size_t i = 0; i < sizeof(ModuleHandlerInformations) / sizeof(ModuleHandlerInformations[0]); ++ i ) @@ -509,15 +506,6 @@ MingwBackend::GenerateGlobalVariables () const ModuleHandlerInformations[i].cflags ); } - if ( ModuleHandlerInformations[i].cflags && ModuleHandlerInformations[i].cflags[0] ) - { - fprintf ( fMakefile, - "MODULETYPE%d_%sFLAGS:=%s\n", - (int)i, - "CXX", - ModuleHandlerInformations[i].cflags ); - } - if ( ModuleHandlerInformations[i].nasmflags && ModuleHandlerInformations[i].nasmflags[0] ) { fprintf ( fMakefile, @@ -526,8 +514,29 @@ MingwBackend::GenerateGlobalVariables () const "NASM", ModuleHandlerInformations[i].nasmflags ); } + + if ( ModuleHandlerInformations[i].linkerflags && ModuleHandlerInformations[i].linkerflags[0] ) + { + fprintf ( fMakefile, + "MODULETYPE%d_%sFLAGS:=%s\n", + (int)i, + "LD", + ModuleHandlerInformations[i].linkerflags ); + } } + fprintf ( fMakefile, + "MODULETYPE%d_KMODE:=yes\n", + (int)Kernel ); + + fprintf ( fMakefile, + "MODULETYPE%d_KMODE:=yes\n", + (int)KernelModeDLL ); + + fprintf ( fMakefile, + "MODULETYPE%d_KMODE:=yes\n", + (int)KernelModeDriver ); + fprintf ( fMakefile, "\n" ); } diff --git a/reactos/tools/rbuild/backend/mingw/mingw.h b/reactos/tools/rbuild/backend/mingw/mingw.h index d7bd6fcac78..c4331b9c152 100644 --- a/reactos/tools/rbuild/backend/mingw/mingw.h +++ b/reactos/tools/rbuild/backend/mingw/mingw.h @@ -66,7 +66,7 @@ private: void GenerateHeader () const; void GenerateGlobalProperties ( const char* assignmentOperation, const IfableData& data ) const; - std::string GenerateProjectLFLAGS () const; + std::string GenerateProjectLDFLAGS () const; void GenerateDirectories (); void GenerateGlobalVariables () const; bool IncludeInAllTarget ( const Module& module ) const; diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp index 6960c0ae769..1609d63ec9c 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.cpp +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.cpp @@ -290,9 +290,7 @@ MingwModuleHandler::GetModuleArchiveFilename () const { if ( IsStaticLibrary ( module ) ) return GetTargetFilename ( module, NULL ); - return new FileLocation ( IntermediateDirectory, - module.output->relative_path, - ReplaceExtension ( module.name, ".temp.a" ) ); + return NULL; } /*static*/ bool @@ -1359,25 +1357,6 @@ MingwModuleHandler::GenerateBuildMapCode ( const FileLocation *mapTarget ) "endif\n" ); } -void -MingwModuleHandler::GenerateBuildNonSymbolStrippedCode () -{ - fprintf ( fMakefile, "# BUILD NO STRIP CODE\n" ); - - fprintf ( fMakefile, - "ifeq ($(ROS_BUILDNOSTRIP),yes)\n" ); - - FileLocation nostripFilename ( OutputDirectory, - module.output->relative_path, - GetBasename ( module.output->name ) + ".nostrip" + GetExtension ( *module.output ) ); - CLEAN_FILE ( nostripFilename ); - - OutputCopyCommand ( *module.output, nostripFilename ); - - fprintf ( fMakefile, - "endif\n" ); -} - void MergeStringVector ( const Backend* backend, const vector& input, @@ -1438,158 +1417,61 @@ MingwModuleHandler::GenerateCleanObjectsAsYouGoCode () const } void -MingwModuleHandler::GenerateRunRsymCode () const +MingwModuleHandler::GenerateLinkerCommand () const { - fprintf ( fMakefile, "# RUN RSYM CODE\n" ); - fprintf ( fMakefile, - "ifneq ($(ROS_GENERATE_RSYM),no)\n" ); - fprintf ( fMakefile, - "\t$(ECHO_RSYM)\n" ); - fprintf ( fMakefile, - "\t$(Q)$(RSYM_TARGET) $@ $@\n\n" ); - fprintf ( fMakefile, - "endif\n" ); -} + string definitionFilename; + + const FileLocation *DefinitionFilename = GetDefinitionFilename (); -void -MingwModuleHandler::GenerateRunStripCode () const -{ - fprintf ( fMakefile, "# RUN STRIP CODE\n" ); - fprintf ( fMakefile, - "ifeq ($(ROS_LEAN_AND_MEAN),yes)\n" ); - fprintf ( fMakefile, - "\t$(ECHO_STRIP)\n" ); - fprintf ( fMakefile, - "\t${strip} -s -x -X $@\n\n" ); - fprintf ( fMakefile, - "endif\n" ); -} - -void -MingwModuleHandler::GenerateLinkerCommand ( - const string& dependencies, - const string& linkerParameters, - const string& pefixupParameters ) -{ - const FileLocation *target_file = GetTargetFilename ( module, NULL ); - const FileLocation *definitionFilename = GetDefinitionFilename (); - string linker = "${ld}"; - string objectsMacro = GetObjectsMacro ( module ); - string libsMacro = GetLibsMacro (); - - fprintf ( fMakefile, "# LINKER COMMAND\n" ); - - string target_macro ( GetTargetMacro ( module ) ); - string target_folder ( backend->GetFullPath ( *target_file ) ); + if ( DefinitionFilename ) { + definitionFilename = backend->GetFullName (*DefinitionFilename); + delete DefinitionFilename; + } string linkerScriptArgument; - if ( module.linkerScript != NULL ) + if ( module.linkerScript != NULL ) { + if ( module.project.configuration.Linker == GnuLd ) linkerScriptArgument = ssprintf ( " -T %s", backend->GetFullName ( *module.linkerScript->file ).c_str () ); else - linkerScriptArgument = ""; - - /* check if we need to add default C++ libraries, ie if we have - * a C++ user-mode module without the -nostdlib linker flag - */ - bool link_defaultlibs = module.cplusplus && - linkerParameters.find ("-nostdlib") == string::npos && - !(module.type == KernelModeDLL || module.type == KernelModeDriver); - - if ( !module.HasImportLibrary() ) - { - fprintf ( fMakefile, - "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n", - target_macro.c_str (), - definitionFilename ? backend->GetFullName ( *definitionFilename ).c_str () : "", - dependencies.c_str (), - target_folder.c_str () ); - fprintf ( fMakefile, "\t$(ECHO_LD)\n" ); - - fprintf ( fMakefile, - "\t%s %s%s %s %s %s %s -o %s\n", - linker.c_str (), - linkerParameters.c_str (), - linkerScriptArgument.c_str (), - objectsMacro.c_str (), - link_defaultlibs ? "$(PROJECT_LPPFLAGS) " : "", - libsMacro.c_str (), - GetLinkerMacro ().c_str (), - target_macro.c_str () ); - } - else - { - FileLocation temp_exp ( IntermediateDirectory, - module.output->relative_path, - module.name + ".exp" ); - CLEAN_FILE ( temp_exp ); - - fprintf ( fMakefile, - "%s: %s | %s\n", - backend->GetFullName ( temp_exp ).c_str (), - definitionFilename ? backend->GetFullName ( *definitionFilename ).c_str () : "", - backend->GetFullPath ( temp_exp ).c_str () ); - fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" ); - - fprintf ( fMakefile, - "\t${dlltool} --dllname %s --def %s --output-exp $@%s%s\n", - module.GetDllName ().c_str (), - definitionFilename ? backend->GetFullName ( *definitionFilename ).c_str () : "", - module.mangledSymbols ? "" : " --kill-at", - module.underscoreSymbols ? " --add-underscore" : "" ); - - fprintf ( fMakefile, - "%s: %s %s $(RSYM_TARGET) $(PEFIXUP_TARGET) | %s\n", - target_macro.c_str (), - backend->GetFullName ( temp_exp ).c_str (), - dependencies.c_str (), - target_folder.c_str () ); - fprintf ( fMakefile, "\t$(ECHO_LD)\n" ); - - fprintf ( fMakefile, - "\t%s %s%s %s %s %s %s %s -o %s\n", - - linker.c_str (), - linkerParameters.c_str (), - linkerScriptArgument.c_str (), - backend->GetFullName ( temp_exp ).c_str (), - objectsMacro.c_str (), - link_defaultlibs ? "$(PROJECT_LPPFLAGS) " : "", - libsMacro.c_str (), - GetLinkerMacro ().c_str (), - target_macro.c_str () ); - - fprintf ( fMakefile, - "\t$(Q)$(PEFIXUP_TARGET) %s -exports%s\n", - target_macro.c_str (), - pefixupParameters.c_str() ); + fprintf ( stderr, + "Linker doesn't support linker scripts: linker script %s ignored for module %s\n", + backend->GetFullName ( *module.linkerScript->file ).c_str (), + module.name.c_str() ); } - GenerateBuildMapCode (); - GenerateBuildNonSymbolStrippedCode (); - GenerateRunRsymCode (); - GenerateRunStripCode (); - GenerateCleanObjectsAsYouGoCode (); + string extraLibraries; + if ( ModuleHandlerInformations[module.type].DefaultHost == HostFalse ) { + if ( module.cplusplus ) { + switch ( module.type ) + { + case Win32DLL: + case Win32OCX: + case Win32CUI: + case Win32GUI: + case Win32SCR: + extraLibraries = "$$(PROJECT_CXXLIBS)"; + break; - if ( definitionFilename ) - delete definitionFilename; - delete target_file; -} + default: + extraLibraries = "$$(PROJECT_CCLIBS)"; + break; + } + } else + extraLibraries = "$$(PROJECT_CCLIBS)"; + } -void -MingwModuleHandler::GeneratePhonyTarget() const -{ - string targetMacro ( GetTargetMacro ( module ) ); - const FileLocation *target_file = GetTargetFilename ( module, NULL ); + delete PassThruCacheDirectory ( new FileLocation ( module.output->directory, module.output->relative_path, "" ) ); + delete PassThruCacheDirectory ( new FileLocation ( IntermediateDirectory, module.output->relative_path, "" ) ); - fprintf ( fMakefile, "# PHONY TARGET\n" ); fprintf ( fMakefile, - ".PHONY: %s\n\n", - targetMacro.c_str ()); - fprintf ( fMakefile, "%s: | %s\n", - targetMacro.c_str (), - backend->GetFullPath ( *target_file ).c_str () ); - - delete target_file; + "$(eval $(call RBUILD_LINK_RULE,%s,%s,%s,%s,%s,%s,%s))\n", + module.name.c_str(), + definitionFilename.c_str(), + module.xmlbuildFile.c_str(), + linkerScriptArgument.c_str(), + extraLibraries.c_str(), + module.GetEntryPoint().c_str(), + module.baseaddress.c_str() ); } void @@ -1598,8 +1480,6 @@ MingwModuleHandler::GenerateObjectFileTargets ( const IfableData& data ) size_t i; string moduleDependencies; - fprintf ( fMakefile, "# OBJECT FILE TARGETS\n" ); - const vector& compilationUnits = data.compilationUnits; for ( i = 0; i < compilationUnits.size (); i++ ) { @@ -1642,8 +1522,6 @@ MingwModuleHandler::GenerateObjectFileTargets ( const IfableData& data ) void MingwModuleHandler::GenerateObjectFileTargets () { - fprintf ( fMakefile, "# OBJECT FILE TARGETS\n" ); - if ( module.pch && use_pch ) { @@ -1660,12 +1538,9 @@ MingwModuleHandler::GenerateObjectFileTargets () pchCxxRule.Execute ( fMakefile, backend, module, module.pch->file, clean_files, dependencies ); else pchRule.Execute ( fMakefile, backend, module, module.pch->file, clean_files, dependencies ); - - fprintf ( fMakefile, "\n" ); } GenerateObjectFileTargets ( module.non_if_data ); - fprintf ( fMakefile, "\n" ); } /* caller needs to delete the returned object */ @@ -1673,6 +1548,10 @@ const FileLocation* MingwModuleHandler::GenerateArchiveTarget () { const FileLocation *archiveFilename = GetModuleArchiveFilename (); + + if ( archiveFilename == NULL ) + return NULL; + const FileLocation *definitionFilename = GetDefinitionFilename (); fprintf ( fMakefile, "# ARCHIVE TARGET\n" ); @@ -1687,11 +1566,8 @@ MingwModuleHandler::GenerateArchiveTarget () backend->GetFullName ( *definitionFilename ).c_str () ); fprintf ( fMakefile, - "\t${dlltool} --dllname %s --def %s --output-lib $@%s%s\n", - module.GetDllName ().c_str (), - backend->GetFullName ( *definitionFilename ).c_str (), - module.mangledSymbols ? "" : " --kill-at", - module.underscoreSymbols ? " --add-underscore" : "" ); + "\t${dlltool} --def %s --kill-at --output-lib $@\n", + backend->GetFullName ( *definitionFilename ).c_str () ); } else arRule1.Execute ( fMakefile, backend, module, archiveFilename, clean_files ); @@ -1727,7 +1603,7 @@ MingwModuleHandler::GetLibsMacro () const string MingwModuleHandler::GetLinkerMacro () const { - return ssprintf ( "$(%s_LFLAGS)", + return ssprintf ( "$(%s_LDFLAGS)", module.name.c_str () ); } @@ -1842,7 +1718,7 @@ MingwModuleHandler::GenerateOtherMacros () { set used_defs; - linkerflagsMacro = ssprintf ("%s_LFLAGS", module.name.c_str ()); + linkerflagsMacro = ssprintf ("%s_LDFLAGS", module.name.c_str ()); libsMacro = ssprintf("%s_LIBS", module.name.c_str ()); const FileLocation * pchPath = GetPrecompiledHeaderPath (); @@ -1897,28 +1773,6 @@ MingwModuleHandler::GenerateOtherMacros () GenerateParameters ( module.name.c_str(), "+=", module.non_if_data ); - const char *linkerflags = ModuleHandlerInformations[module.type].linkerflags; - if ( strlen( linkerflags ) > 0 ) - { - fprintf ( fMakefile, - "%s += %s\n\n", - linkerflagsMacro.c_str (), - linkerflags ); - } - - // FIXME: make rules for linker, move standard flags there - if ( ModuleHandlerInformations[module.type].DefaultHost == HostFalse ) - { - if ( module.cplusplus ) - fprintf ( fMakefile, - "%s+= $(PROJECT_LPPFLAGS)\n\n", - linkerflagsMacro.c_str () ); - else - fprintf ( fMakefile, - "%s+= $(PROJECT_LFLAGS)\n\n", - linkerflagsMacro.c_str () ); - } - GenerateMacros ( "+=", module.non_if_data, @@ -1957,7 +1811,9 @@ MingwModuleHandler::GenerateRules () if ( !ReferenceObjects ( module ) ) { const FileLocation* ar_target = GenerateArchiveTarget (); - delete ar_target; + + if ( ar_target ) + delete ar_target; } @@ -2158,61 +2014,6 @@ MingwModuleHandler::GetDefinitionFilename () const } } -void -MingwModuleHandler::GenerateImportLibraryTarget ( - const FileLocation *defFilename, - const FileLocation *library_target, - bool delayimp) -{ - string empty = "tools" + sSep + "rbuild" + sSep + "empty.def"; - - fprintf ( fMakefile, "# IMPORT LIBRARY RULE\n" ); - - fprintf ( fMakefile, "%s:", - backend->GetFullName ( *library_target ).c_str () ); - - if ( defFilename ) - { - fprintf ( fMakefile, " %s", - backend->GetFullName ( *defFilename ).c_str () ); - } - - fprintf ( fMakefile, " | %s\n", - backend->GetFullPath ( *library_target ).c_str () ); - - fprintf ( fMakefile, "\t$(ECHO_DLLTOOL)\n" ); - - fprintf ( fMakefile, - "\t${dlltool} --dllname %s --def %s %s %s%s%s\n\n", - module.GetDllName ().c_str (), - defFilename ? backend->GetFullName ( *defFilename ).c_str () - : empty.c_str (), - delayimp ? "--output-delaylib" : "--output-lib", - backend->GetFullName ( *library_target ).c_str (), - module.mangledSymbols ? "" : " --kill-at", - module.underscoreSymbols ? " --add-underscore" : "" ); -} - -void -MingwModuleHandler::GenerateImportLibraryTargetIfNeeded () -{ - if ( module.importLibrary != NULL ) - { - const FileLocation *library_target = GetImportLibraryFilename ( module, &clean_files, false ); - const FileLocation *delayimp_target = GetImportLibraryFilename ( module, &clean_files, true ); - const FileLocation *defFilename = GetDefinitionFilename (); - - GenerateImportLibraryTarget(defFilename, library_target, false); - GenerateImportLibraryTarget(defFilename, delayimp_target, true); - - if ( defFilename ) - delete defFilename; - delete library_target; - delete delayimp_target; - - } -} - void MingwModuleHandler::GetSpecObjectDependencies ( vector& dependencies, @@ -2402,30 +2203,8 @@ MingwKernelModuleHandler::Process () void MingwKernelModuleHandler::GenerateKernelModuleTarget () { - string targetMacro ( GetTargetMacro ( module ) ); - string workingDirectory = GetWorkingDirectory ( ); - string libsMacro = GetLibsMacro (); - - GenerateImportLibraryTargetIfNeeded (); - - if ( module.non_if_data.compilationUnits.size () > 0 ) - { - GenerateRules (); - - string dependencies = libsMacro + " " + objectsMacro; - - string linkerParameters = ssprintf ( "-subsystem=native -entry=%s -image-base=%s", - module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (), - module.baseaddress.c_str () ); - - GenerateLinkerCommand ( dependencies, - linkerParameters + " $(NTOSKRNL_SHARED)", - " -sections" ); - } - else - { - GeneratePhonyTarget(); - } + GenerateRules (); + GenerateLinkerCommand (); } @@ -2453,29 +2232,8 @@ MingwKernelModeDLLModuleHandler::Process () void MingwKernelModeDLLModuleHandler::GenerateKernelModeDLLModuleTarget () { - string targetMacro ( GetTargetMacro ( module ) ); - string workingDirectory = GetWorkingDirectory (); - string libsMacro = GetLibsMacro (); - - GenerateImportLibraryTargetIfNeeded (); - - if ( module.non_if_data.compilationUnits.size () > 0 ) - { - GenerateRules (); - - string dependencies = libsMacro + " " + objectsMacro; - - string linkerParameters = ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared", - module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (), - module.baseaddress.c_str () ); - GenerateLinkerCommand ( dependencies, - linkerParameters, - " -sections" ); - } - else - { - GeneratePhonyTarget(); - } + GenerateRules (); + GenerateLinkerCommand (); } @@ -2502,29 +2260,8 @@ MingwNativeDLLModuleHandler::Process () void MingwNativeDLLModuleHandler::GenerateNativeDLLModuleTarget () { - string targetMacro ( GetTargetMacro (module) ); - string workingDirectory = GetWorkingDirectory ( ); - string libsMacro = GetLibsMacro (); - - GenerateImportLibraryTargetIfNeeded (); - - if ( module.non_if_data.compilationUnits.size () > 0 ) - { - GenerateRules (); - - string dependencies = libsMacro + " " + objectsMacro; - - string linkerParameters = ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared", - module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (), - module.baseaddress.c_str () ); - GenerateLinkerCommand ( dependencies, - linkerParameters, - "" ); - } - else - { - GeneratePhonyTarget(); - } + GenerateRules (); + GenerateLinkerCommand (); } @@ -2551,29 +2288,8 @@ MingwNativeCUIModuleHandler::Process () void MingwNativeCUIModuleHandler::GenerateNativeCUIModuleTarget () { - string targetMacro ( GetTargetMacro (module) ); - string workingDirectory = GetWorkingDirectory ( ); - string libsMacro = GetLibsMacro (); - - GenerateImportLibraryTargetIfNeeded (); - - if ( module.non_if_data.compilationUnits.size () > 0 ) - { - GenerateRules (); - - string dependencies = libsMacro + " " + objectsMacro; - - string linkerParameters = ssprintf ( "-subsystem=native -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000", - module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (), - module.baseaddress.c_str () ); - GenerateLinkerCommand ( dependencies, - linkerParameters, - "" ); - } - else - { - GeneratePhonyTarget(); - } + GenerateRules (); + GenerateLinkerCommand (); } @@ -2641,29 +2357,8 @@ MingwWin32DLLModuleHandler::Process () void MingwWin32DLLModuleHandler::GenerateWin32DLLModuleTarget () { - string targetMacro ( GetTargetMacro (module) ); - string workingDirectory = GetWorkingDirectory ( ); - string libsMacro = GetLibsMacro (); - - GenerateImportLibraryTargetIfNeeded (); - - if ( module.non_if_data.compilationUnits.size () > 0 ) - { - GenerateRules (); - - string dependencies = libsMacro + " " + objectsMacro; - - string linkerParameters = ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared", - module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (), - module.baseaddress.c_str () ); - GenerateLinkerCommand ( dependencies, - linkerParameters, - "" ); - } - else - { - GeneratePhonyTarget(); - } + GenerateRules (); + GenerateLinkerCommand (); } @@ -2682,29 +2377,8 @@ MingwWin32OCXModuleHandler::Process () void MingwWin32OCXModuleHandler::GenerateWin32OCXModuleTarget () { - string targetMacro ( GetTargetMacro (module) ); - string workingDirectory = GetWorkingDirectory ( ); - string libsMacro = GetLibsMacro (); - - GenerateImportLibraryTargetIfNeeded (); - - if ( module.non_if_data.compilationUnits.size () > 0 ) - { - GenerateRules (); - - string dependencies = libsMacro + " " + objectsMacro; - - string linkerParameters = ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000 -shared", - module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (), - module.baseaddress.c_str () ); - GenerateLinkerCommand ( dependencies, - linkerParameters, - "" ); - } - else - { - GeneratePhonyTarget(); - } + GenerateRules (); + GenerateLinkerCommand (); } @@ -2730,29 +2404,8 @@ MingwWin32CUIModuleHandler::Process () void MingwWin32CUIModuleHandler::GenerateWin32CUIModuleTarget () { - string targetMacro ( GetTargetMacro (module) ); - string workingDirectory = GetWorkingDirectory ( ); - string libsMacro = GetLibsMacro (); - - GenerateImportLibraryTargetIfNeeded (); - - if ( module.non_if_data.compilationUnits.size () > 0 ) - { - GenerateRules (); - - string dependencies = libsMacro + " " + objectsMacro; - - string linkerParameters = ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000", - module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (), - module.baseaddress.c_str () ); - GenerateLinkerCommand ( dependencies, - linkerParameters, - "" ); - } - else - { - GeneratePhonyTarget(); - } + GenerateRules (); + GenerateLinkerCommand (); } @@ -2778,29 +2431,8 @@ MingwWin32GUIModuleHandler::Process () void MingwWin32GUIModuleHandler::GenerateWin32GUIModuleTarget () { - string targetMacro ( GetTargetMacro (module) ); - string workingDirectory = GetWorkingDirectory ( ); - string libsMacro = GetLibsMacro (); - - GenerateImportLibraryTargetIfNeeded (); - - if ( module.non_if_data.compilationUnits.size () > 0 ) - { - GenerateRules (); - - string dependencies = libsMacro + " " + objectsMacro; - - string linkerParameters = ssprintf ( "-subsystem=windows -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000", - module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (), - module.baseaddress.c_str () ); - GenerateLinkerCommand ( dependencies, - linkerParameters, - "" ); - } - else - { - GeneratePhonyTarget(); - } + GenerateRules (); + GenerateLinkerCommand (); } @@ -2845,7 +2477,7 @@ MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget () if (Environment::GetArch() == "arm") { fprintf ( fMakefile, - "\t${gcc} -Wl,--subsystem,native -o %s %s %s %s\n", + "\t${gcc} -Wl,--subsystem,native -o %s %s %s %s -nostartfiles -nostdlib\n", backend->GetFullName ( junk_tmp ).c_str (), objectsMacro.c_str (), libsMacro.c_str (), @@ -2854,7 +2486,7 @@ MingwBootLoaderModuleHandler::GenerateBootLoaderModuleTarget () else { fprintf ( fMakefile, - "\t${gcc} -Wl,--subsystem,native -Wl,-Ttext,0x8000 -o %s %s %s %s\n", + "\t${gcc} -Wl,--subsystem,native -Wl,-Ttext,0x8000 -o %s %s %s %s -nostartfiles -nostdlib\n", backend->GetFullName ( junk_tmp ).c_str (), objectsMacro.c_str (), libsMacro.c_str (), @@ -3400,29 +3032,8 @@ MingwTestModuleHandler::GetModuleSpecificCompilationUnits ( vector 0 ) - { - GenerateRules (); - - string dependencies = libsMacro + " " + objectsMacro; - - string linkerParameters = ssprintf ( "-subsystem=console -entry=%s -image-base=%s -file-alignment=0x1000 -section-alignment=0x1000", - module.GetEntryPoint(!(Environment::GetArch() == "arm")).c_str (), - module.baseaddress.c_str () ); - GenerateLinkerCommand ( dependencies, - linkerParameters, - "" ); - } - else - { - GeneratePhonyTarget(); - } + GenerateRules (); + GenerateLinkerCommand (); } diff --git a/reactos/tools/rbuild/backend/mingw/modulehandler.h b/reactos/tools/rbuild/backend/mingw/modulehandler.h index 57aaad29570..b0687177d9a 100644 --- a/reactos/tools/rbuild/backend/mingw/modulehandler.h +++ b/reactos/tools/rbuild/backend/mingw/modulehandler.h @@ -113,15 +113,9 @@ protected: std::string GetLinkerMacro () const; static std::string GetDebugFormat (); void GenerateCleanObjectsAsYouGoCode () const; - void GenerateRunRsymCode () const; - void GenerateRunStripCode () const; - void GenerateLinkerCommand ( const std::string& dependencies, - const std::string& linkerParameters, - const std::string& pefixupParameters ); - void GeneratePhonyTarget() const; + void GenerateLinkerCommand () const; void GenerateBuildMapCode ( const FileLocation *mapTarget = NULL ); void GenerateRules (); - void GenerateImportLibraryTarget (const FileLocation *defFilename, const FileLocation *library_target, bool delayimp); void GenerateImportLibraryTargetIfNeeded (); void GetDefinitionDependencies ( std::vector& dependencies ) const; std::string GetLinkingDependencies () const; diff --git a/reactos/tools/rbuild/backend/mingw/rules.mak b/reactos/tools/rbuild/backend/mingw/rules.mak index 9b9cc8cc1f4..40e30f7bdcd 100644 --- a/reactos/tools/rbuild/backend/mingw/rules.mak +++ b/reactos/tools/rbuild/backend/mingw/rules.mak @@ -19,7 +19,7 @@ RBUILD_intermediate_dir=${call RBUILD_fullpath,$(value INTERMEDIATE)$(SEP)$(dir RBUILD_output_dir=${call RBUILD_fullpath,$(value OUTPUT)$(SEP)$(dir ${call RBUILD_strip_prefixes,$(1)})} #(source) -RBUILD_source_name=$(basename $(notdir $(1))) +RBUILD_name=$(basename $(notdir $(1))) #(source) RBUILD_dir=${call RBUILD_fullpath,$(dir ${call RBUILD_compress_prefixes,$(1)})} diff --git a/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp b/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp index 21595b69a88..812e11c4b0e 100644 --- a/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp +++ b/reactos/tools/rbuild/backend/msvc/vcprojmaker.cpp @@ -467,7 +467,7 @@ MSVCBackend::_generate_vcproj ( const Module& module ) { fprintf ( OUT, "\t\t\tvalue == "true"; - else - underscoreSymbols = false; - isStartupLib = GetBooleanAttribute ( moduleNode, "isstartuplib" ); isCRT = GetBooleanAttribute ( moduleNode, "iscrt", GetDefaultModuleIsCRT () ); @@ -1359,12 +1351,13 @@ Module::GetInvocationTarget ( const int index ) const } string -Module::GetEntryPoint(bool leadingUnderscore) const +Module::GetEntryPoint() const { string result = ""; if (entrypoint == "0" || entrypoint == "0x0") return "0"; - if (leadingUnderscore) + + if (Environment::GetArch() != "arm") result = "_"; result += entrypoint; @@ -1874,10 +1867,6 @@ ImportLibrary::ImportLibrary ( const Project& project, if ( dllname ) this->dllname = dllname->value; - else if ( module->type == StaticLibrary || module->type == HostStaticLibrary ) - throw XMLInvalidBuildFileException ( - node.location, - " dllname attribute required." ); size_t index = definition->value.find_last_of ( "/\\" ); if ( index == string::npos ) diff --git a/reactos/tools/rbuild/rbuild.h b/reactos/tools/rbuild/rbuild.h index 6d70f3afcd5..f8ae933a130 100644 --- a/reactos/tools/rbuild/rbuild.h +++ b/reactos/tools/rbuild/rbuild.h @@ -378,8 +378,6 @@ public: ImportLibrary* delayImportLibrary; Metadata* metadata; Bootsector* bootSector; - bool mangledSymbols; - bool underscoreSymbols; bool isUnicode; bool isDefaultEntryPoint; Bootstrap* bootstrap; @@ -420,7 +418,7 @@ public: bool IsDLL () const; std::string GetPathWithPrefix ( const std::string& prefix ) const; // "path/prefixfoo.exe" std::string GetPathToBaseDir() const; // "../" offset to rootdirectory - std::string GetEntryPoint(bool leadingUnderscore) const; + std::string GetEntryPoint() const; void GetTargets ( string_list& ) const; std::string GetInvocationTarget ( const int index ) const; bool HasFileWithExtension ( const IfableData&, const std::string& extension ) const;