88da818491e8edc74e29c6b0eab365ba09d56eb9
[reactos.git] / reactos / tools / rbuild / backend / mingw / linkers / ld.mak
1 # -exclude-all-symbols disables autoexporting all symbols *if none were found* (either in a DEF file or using __declspec(dllexport)
2 LDFLAG_DLL:=-shared -exclude-all-symbols
3 LDFLAG_DRIVER:=-shared --subsystem=native -exclude-all-symbols
4 LDFLAG_NOSTDLIB:=-nostartfiles -nostdlib
5 LDFLAG_CONSOLE:=--subsystem=console
6 LDFLAG_WINDOWS:=--subsystem=windows
7 LDFLAG_NATIVE:=--subsystem=native
8
9 LDFLAG_EXCLUDE_ALL_SYMBOLS=-exclude-all-symbols
10 DLLTOOL_FLAGS=--kill-at
11 ifeq ($(ARCH),amd64)
12 DLLTOOL_FLAGS= --no-leading-underscore
13 endif
14
15 #~ #(module, objs, deps, ldflags, output, def, libs, entry, base)
16 #(module, objs, deps, ldflags, output, def, libs, entry, base, extralibs)
17 define RBUILD_LINK
18
19 ifneq ($(6),)
20 ${call RBUILD_intermediate_dir,$(5)}$$(SEP)lib${call RBUILD_name,$(5)}.a: $(6) | ${call RBUILD_intermediate_path,$(5)}
21 $$(ECHO_IMPLIB)
22 $${dlltool} --def $(6) $(DLLTOOL_FLAGS) --output-lib=$$@
23
24 ${call RBUILD_intermediate_dir,$(5)}$$(SEP)lib${call RBUILD_name,$(5)}.delayimp.a: $(6) | ${call RBUILD_intermediate_path,$(5)}
25 $$(ECHO_IMPLIB)
26 $${dlltool} --def $(6) $(DLLTOOL_FLAGS) --output-delaylib=$$@
27
28 ${call RBUILD_intermediate_path_noext,$(5)}.exp: $(6) | ${call RBUILD_intermediate_path,$(5)}
29 $$(ECHO_IMPLIB)
30 $${dlltool} --def $(6) $(DLLTOOL_FLAGS) --output-exp=$$@
31
32 $(1)_CLEANFILES+=\
33 ${call RBUILD_intermediate_dir,$(5)}$$(SEP)lib$(notdir $(5)).a \
34 ${call RBUILD_intermediate_dir,$(5)}$$(SEP)lib$(notdir $(5)).delayimp.a \
35 ${call RBUILD_intermediate_path_noext,$(5)}.exp
36 endif
37
38 # TODO: refactor this out of here and into rules.mak
39 ${call RBUILD_intermediate_dir,$(5)}$$(SEP)$(1)_objs.rsp: $(2) $$(if $(6),${call RBUILD_intermediate_path_noext,$(5)}.exp) $(3) | ${call RBUILD_intermediate_dir,$(5)}
40 $$(ECHO_RSP)
41 -@$${rm} $$@ 2>$$(NUL)
42 $${cp} $$(NUL) $$@ >$$(NUL)
43 $$(foreach obj,$(2) $$(if $(6),${call RBUILD_intermediate_path_noext,$(5)}.exp),$$(Q)echo $$(QUOTE)$$(subst \,\\,$$(obj))$$(QUOTE)>>$$@$$(NL))
44
45 $(1)_CLEANFILES+=${call RBUILD_intermediate_dir,$(5)}$$(SEP)$(1)_objs.rsp
46
47 $(5): ${call RBUILD_intermediate_dir,$(5)}$$(SEP)$(1)_objs.rsp $(7) $(3) $$(RSYM_TARGET) $$(PEFIXUP_TARGET) | ${call RBUILD_dir,$(5)}
48 $$(ECHO_LD)
49 #~ $${ld} --entry=$(8) --image-base=$(9) @${call RBUILD_intermediate_dir,$(5)}$$(SEP)$(1)_objs.rsp $(7) ${call RBUILD_ldflags,$(1),$(4)} -o $$@
50 $${ld} --entry=$(8) --image-base=$(9) @${call RBUILD_intermediate_dir,$(5)}$$(SEP)$(1)_objs.rsp --start-group $(10) $(7) --end-group ${call RBUILD_ldflags,$(1),$(4)} -o $$@
51 ifneq ($(or $(6),$$(MODULETYPE$$($(1)_TYPE)_KMODE)),)
52 $$(ECHO_PEFIXUP)
53 $$(Q)$$(PEFIXUP_TARGET) $$@ $(if $(6),-exports) $$(if $$(MODULETYPE$($(1)_TYPE)_KMODE),-sections)
54 endif
55 ifeq ($(ROS_BUILDMAP),full)
56 $$(ECHO_OBJDUMP)
57 $${objdump} -d -S $$@ > ${call RBUILD_output_path_noext,$(5)}.map
58 else
59 ifeq ($(ROS_BUILDMAP),yes)
60 $$(ECHO_NM)
61 $${nm} --numeric-sort $$@ > ${call RBUILD_output_path_noext,$(5)}.map
62 endif
63 endif
64 ifeq ($(ROS_BUILDNOSTRIP),yes)
65 $$(ECHO_CP)
66 $${cp} $(5) $(basename $(5)).nostrip$(suffix $(5)) 1>$(NUL)
67 endif
68 ifneq ($(ROS_GENERATE_RSYM),no)
69 $$(ECHO_RSYM)
70 $$(Q)$$(RSYM_TARGET) $$@ $$@
71 endif
72 ifeq ($(ROS_LEAN_AND_MEAN),yes)
73 $$(ECHO_STRIP)
74 $${strip} -s -x -X $$@
75 endif
76
77 ifneq ($(ROS_BUILDMAP),)
78 $(1)_CLEANFILES+=${call RBUILD_output_path_noext,$(5)}.map
79 endif
80
81 ifeq ($(ROS_BUILDNOSTRIP),yes)
82 $(1)_CLEANFILES+=$(basename $(5)).nostrip$(suffix $(5))
83 endif
84
85 endef
86
87 #~ #(module, def, deps, ldflags, libs, entry, base)
88 #~ RBUILD_LINK_RULE=${call RBUILD_LINK,$(1),$(value $(1)_OBJS),$(3),$(4),$(value $(1)_TARGET),$(2),$(5) $(value $(1)_LIBS) $(5),$(6),$(7)}
89 #(module, def, deps, ldflags, libs, entry, base, extralibs)
90 RBUILD_LINK_RULE=${call RBUILD_LINK,$(1),$(value $(1)_OBJS),$(3),$(4),$(value $(1)_TARGET),$(2),$(value $(1)_LIBS),$(6),$(7),$(5)}