sbsv2/raptor/lib/flm/win32.flm
changeset 0 044383f39525
child 3 e1eecf4d390d
child 590 360bd6b35136
equal deleted inserted replaced
-1:000000000000 0:044383f39525
       
     1 # Copyright (c) 2007-2009 Nokia Corporation and/or its subsidiary(-ies).
       
     2 # All rights reserved.
       
     3 # This component and the accompanying materials are made available
       
     4 # under the terms of the License "Eclipse Public License v1.0"
       
     5 # which accompanies this distribution, and is available
       
     6 # at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     7 #
       
     8 # Initial Contributors:
       
     9 # Nokia Corporation - initial contribution.
       
    10 #
       
    11 # Contributors:
       
    12 #
       
    13 # Description:
       
    14 # WINSCW EXE/DLL/IMPLIB/LIB Function Like Makefile (FLM)
       
    15 # Knows how to build all possible executables for the WINSCW emulator build
       
    16 #
       
    17 #
       
    18 
       
    19 # passed in values, stripped of whitespace
       
    20 COPY_FOR_STATIC_LINKAGE:=$(strip $(COPY_FOR_STATIC_LINKAGE))
       
    21 DEFFILE:=$(strip $(DEFFILE))
       
    22 DEFFILEKEYWORD:=$(strip $(DEFFILEKEYWORD))
       
    23 EPOCALLOWDLLDATA:=$(strip $(EPOCALLOWDLLDATA))
       
    24 EXPORTLIBRARY:=$(strip $(EXPORTLIBRARY))
       
    25 BASEADDRESS:=$(strip $(BASEADDRESS))
       
    26 LINKAS:=$(strip $(LINKAS))
       
    27 NOEXPORTLIBRARY:=$(strip $(NOEXPORTLIBRARY))
       
    28 SECUREID:=$(strip $(SECUREID))
       
    29 UID2:=$(strip $(UID2))
       
    30 UID3:=$(strip $(UID3))
       
    31 VENDORID:=$(strip $(VENDORID))
       
    32 VID:=$(strip $(VID))
       
    33 WIN32_HEADERS:=$(strip $(WIN32_HEADERS))
       
    34 
       
    35 # local variables
       
    36 BINDIR:=
       
    37 BINDIRSTATICLINK:=
       
    38 BINTARGET:=
       
    39 BINTARGETSTATICLINK:=
       
    40 BLDDIR:=
       
    41 CHECKLIB_TYPE:=
       
    42 CREATABLEPATHS:=
       
    43 CLEANTARGETS:=
       
    44 CW_RUNTIME:=
       
    45 ENTRYSYMBOL:=
       
    46 IMPORTLIBLINKAS:=
       
    47 IMPORTLIBTARGET:=
       
    48 LIBDIR:=
       
    49 LINKER_FIRSTSTATLIB:=
       
    50 MAINLINKAS:=
       
    51 NEWLIBFILE:=
       
    52 RELEASABLES:=
       
    53 STATLIBDIR:=
       
    54 STDCPP_BUILD:=
       
    55 STDCPPTAGFILE:=
       
    56 UID1:=
       
    57 WIN32_LIBRARIES:=
       
    58 
       
    59 # FIVESPACES variable created to ensure that a suitable gap of space characters can
       
    60 # be placed between the separate arguments in the call to a tool (if required).
       
    61 # This is a workaround for a problem in Cygwin, where separate arguments are interpreted
       
    62 # as a single argument when passed to bash.
       
    63 FIVESPACES=$(BLANK)     $(BLANK)
       
    64 
       
    65 # CW runtime varies based on TARGETTYPE requirements, with wrapper FLMs dictating the choice
       
    66 # We override a CW-specific environment variable to do this, in common with ABLD
       
    67 ifeq ($(CW_STATIC_RUNTIME),1)
       
    68   CW_RUNTIME:=$(CW_RUNTIME_STATIC)
       
    69   CFLAGS:=$(CFLAGS) $(OPT.RUNTIME)staticmulti
       
    70 else
       
    71   CW_RUNTIME:=$(CW_RUNTIME_NONSTATIC)
       
    72   CFLAGS:=$(CFLAGS) $(OPT.RUNTIME)dllmulti
       
    73 endif
       
    74 MWSym2LibraryFiles:=$(subst $(CHAR_SPACE),$(DIRSEP),$(CW_RUNTIME) $(CW_DEFAULT_LIBS))
       
    75 ifneq ($(WIN32_LIBRARY),)
       
    76   WIN32_HEADERS:=1
       
    77   WIN32_LIBRARIES:=$(addprefix $(OPT.LIBFILE),$(WIN32_LIBRARY))
       
    78 endif
       
    79 
       
    80 # top-level definitions
       
    81 BINDIR:=$(RELEASEPATH)/$(FULLVARIANTPATH)
       
    82 
       
    83 # TARGETPATH and COPY_FOR_STATIC_LINKAGE only apply when TARGETPATH is a sub-directory of /sys/bin
       
    84 TARGETPATH_APPEND:=$(subst \,/,$(TARGETPATH))
       
    85 ifneq ($(findstring /sys/bin/,$(TARGETPATH_APPEND)),)
       
    86   ifeq ($(COPY_FOR_STATIC_LINKAGE),1)
       
    87     BINDIRSTATICLINK:=$(BINDIR)
       
    88   endif
       
    89   BINDIR:=$(BINDIR)/z$(TARGETPATH_APPEND)
       
    90 else
       
    91   COPY_FOR_STATIC_LINKAGE:=0
       
    92 endif
       
    93 
       
    94 BLDDIR:=$(OUTPUTPATH)/$(FULLVARIANTPATH)
       
    95 LIBDIR:=$(RELEASEPATH)/$(LINKPATH)
       
    96 STATLIBDIR:=$(RELEASEPATH)/$(FULLVARIANTPATH)
       
    97 CREATABLEPATHS:=$(BLDDIR) $(BINDIR) $(BINDIRSTATICLINK)
       
    98 
       
    99 # Deduce whether we should be performing a build with standard CPP characteristics
       
   100 # This operates differently per-OS release, although OE TARGETTYPEs always build with standard CPP traits
       
   101 ifeq ($(OPEN_ENVIRONMENT),1)
       
   102   STDCPP_BUILD:=1
       
   103 endif
       
   104 
       
   105 ifeq ($(SUPPORTS_STDCPP_NEWLIB),1)
       
   106   ifeq ($(NOSTDCPP),1)
       
   107     STDCPP_BUILD:=
       
   108   else
       
   109     ifeq ($(STDCPP),1)
       
   110       STDCPP_BUILD:=1
       
   111     endif
       
   112   endif
       
   113 
       
   114   ifneq ($(NEWLIB),)
       
   115     NEWLIBFILE:=$(STATLIBDIR)/$(NEWLIB)
       
   116   else
       
   117     ifeq ($(SYSTEM_TARGET),1)
       
   118       NEWLIBFILE:=$(STATLIBDIR)/$(DEFAULT_SYSTEM_NEWLIB)
       
   119     else
       
   120       NEWLIBFILE:=$(STATLIBDIR)/$(DEFAULT_NORMAL_NEWLIB)
       
   121     endif
       
   122   endif
       
   123 endif
       
   124 
       
   125 ifeq ($(STDCPP_BUILD),1)
       
   126   CDEFS:=$(CDEFS) $(STDCPP_DEF)
       
   127   SYSTEMINCLUDE:=$(SYSTEMINCLUDE) $(STDCPP_INCLUDE)
       
   128   CFLAGS:=$(CFLAGS) $(OPT.WCHAR) on
       
   129   CHECKLIB_TYPE:=$(OPT.CHECKLIB.STDCPP)
       
   130   STDCPPTAGFILE:=$(OPT.LIBPATH)$(EPOCROOT)/epoc32/tools/tag $(OPT.SEARCH) tag_coff
       
   131 else
       
   132   CFLAGS:=$(CFLAGS) $(OPT.WCHAR) off
       
   133   CHECKLIB_TYPE:=$(OPT.CHECKLIB.SYMCPP)
       
   134 endif
       
   135 
       
   136 ifeq ($(WIN32_HEADERS),1)
       
   137   CDEFS:=$(CDEFS) WIN32
       
   138   CDEFS:=$(CDEFS) _WINDOWS
       
   139   CFLAGS:=$(CFLAGS) $(OPT.STDINC)
       
   140 else
       
   141   CFLAGS:=$(CFLAGS) $(OPT.NOSTDINC)
       
   142 endif
       
   143 
       
   144 # get the compiler to generate dependencies for us?
       
   145 ifeq ($(DEPEND_SKIP),)
       
   146   CFLAGS:=$(CFLAGS) $(OPT.DEPEND)
       
   147 endif
       
   148 
       
   149 # specifics relating to the base type of the target being processed
       
   150 ifeq ($(BASE_TYPE),dll)
       
   151   # Special case, although this should be dealt with in the wrapper FLM in a better way
       
   152   ifeq ($(TARGETTYPE),exexp)
       
   153     CDEFS:=$(CDEFS) __EXE__
       
   154     ENTRYSYMBOL:=__E32Startup
       
   155     LFLAGS:=$(LFLAGS) $(OPT.NOENTRY)
       
   156     UID1:=1000007a
       
   157   else
       
   158     CDEFS:=$(CDEFS) __DLL__
       
   159     ENTRYSYMBOL:=__E32Dll
       
   160     LFLAGS:=$(LFLAGS) $(OPT.MAINENTRYPOINT)__Win32DllMain@12
       
   161     UID1:=10000079
       
   162   endif
       
   163   LFLAGS:=$(LFLAGS) $(OPT.SHARED)
       
   164 
       
   165   ifneq ($(BASEADDRESS),)
       
   166     LFLAGS:=$(LFLAGS) $(OPT.IMAGEBASE)$(BASEADDRESS)
       
   167   endif
       
   168 
       
   169   ifeq ($(FIRST_STATLIB),)
       
   170     BASE_TYPE_STATLIB:=edll.lib
       
   171   else
       
   172     BASE_TYPE_STATLIB:=$(FIRST_STATLIB)
       
   173   endif
       
   174 endif
       
   175 ifeq ($(BASE_TYPE),exe)
       
   176   CDEFS:=$(CDEFS) __EXE__
       
   177   ENTRYSYMBOL:=?_E32Bootstrap@@YGXXZ
       
   178   UID1:=1000007a
       
   179 
       
   180   ifeq ($(FIRST_STATLIB),)
       
   181     BASE_TYPE_STATLIB:=eexe.lib
       
   182   else
       
   183     BASE_TYPE_STATLIB:=$(FIRST_STATLIB)
       
   184   endif
       
   185 endif
       
   186 
       
   187 ifeq ($(FIRSTLIB),)
       
   188   LINKER_FIRSTSTATLIB:=$(BASE_TYPE_STATLIB)
       
   189 else
       
   190   LINKER_FIRSTSTATLIB:=$(FIRSTLIB)
       
   191 endif
       
   192 
       
   193 
       
   194 BINTARGET:=$(BINDIR)/$(TARGET).$(if $(REQUESTEDTARGETEXT),$(REQUESTEDTARGETEXT),$(TARGETTYPE))
       
   195 
       
   196 
       
   197 # Run trace compiler #####################################
       
   198 TRACE_MARKER_PATH:=$(OUTPUTPATH)
       
   199 
       
   200 ifeq ($(UID3),)
       
   201   ifeq ($(UID2),)
       
   202     USE_TRACE_COMPILER:=
       
   203   else
       
   204     UID_TC:=$(UID2)
       
   205   endif
       
   206 else
       
   207   UID_TC:=$(UID3)
       
   208 endif
       
   209 
       
   210 # USE_TRACE_COMPILER defaults to blank in Raptor config.
       
   211 # Users can turn TC on by setting it to 1 in user config.
       
   212 ifneq ($(USE_TRACE_COMPILER),) 
       
   213   include $(FLMHOME)/tracecompiler.mk
       
   214 endif
       
   215 
       
   216 
       
   217 ####################
       
   218 ## IMPORT LIBRARY ##
       
   219 ####################
       
   220 
       
   221 IMPORTLIBLINKAS:=$(TARGET).$(if $(REQUESTEDTARGETEXT),$(REQUESTEDTARGETEXT),$(TARGETTYPE))
       
   222 # LINKAS, if supplied, only applies to IMPLIB TARGETTYPEs
       
   223 ifeq ($(BASE_TYPE),importlib)
       
   224   ifneq ($(LINKAS),)
       
   225     IMPORTLIBLINKAS:=$(LINKAS)
       
   226   else
       
   227     IMPORTLIBLINKAS:=$(TARGET).dll
       
   228   endif
       
   229 endif
       
   230 
       
   231 ifneq ($(EXPORTLIBRARY),)
       
   232   IMPORTLIBTARGET:=$(LIBDIR)/$(EXPORTLIBRARY).lib
       
   233 else
       
   234   IMPORTLIBTARGET:=$(LIBDIR)/$(TARGET).lib
       
   235 endif
       
   236 
       
   237 # Regardless of whether a TARGETTYPE normally supports an import library, always attempt
       
   238 # to generate one if an explicit DEFFILE keyword was listed
       
   239 ifeq ($(DEFFILEKEYWORD),1)
       
   240   SUPPORTS_IMPORT_LIBRARY:=1
       
   241 endif
       
   242 
       
   243 ifeq ($(SUPPORTS_IMPORT_LIBRARY),1)
       
   244   ifneq ($(NOEXPORTLIBRARY),1)
       
   245     ifneq ($(TARGET_$(call sanitise,$(IMPORTLIBTARGET))),1)
       
   246       CLEANTARGETS:=$(CLEANTARGETS) $(if $(or $(EXPORTUNFROZEN),$(DEFFILE)),$(IMPORTLIBTARGET))
       
   247       RELEASABLES:=$(RELEASABLES) $(if $(or $(EXPORTUNFROZEN),$(DEFFILE)),$(IMPORTLIBTARGET))
       
   248 
       
   249       # import libraries are generated to the UDEB release directory
       
   250       ifneq ($(VARIANTTYPE),udeb)
       
   251         CREATABLEPATHS:=$(CREATABLEPATHS) $(if $(or $(EXPORTUNFROZEN),$(DEFFILE)),$(LIBDIR))
       
   252       endif
       
   253 
       
   254       ifneq ($(EXPORTUNFROZEN),)
       
   255         # EXPORTUNFROZEN amounts to doing the stage-two link with the makedef generated temporary .def file but creating a .lib
       
   256         # file as a side-effect of linking.  The import library is therefore dependent on the final binary in this instance.
       
   257         $(info <warning project='$(PROJECT_META)' component='$(COMPONENT_META)'>EXPORTUNFROZEN present in $(PROJECT_META) - unfrozen exports will be represented in import library.</warning> )
       
   258         $(IMPORTLIBTARGET): $(BINTARGET)
       
   259         $(eval TARGET_$(call sanitise,$(IMPORTLIBTARGET)):=1)
       
   260       else
       
   261         ifneq ($(DEFFILE),)
       
   262           # If a .def file physically exists (either explicitly via DEFFILE or implicitly in the correct place) then we
       
   263           # generate an import library with reference to it
       
   264           PREPPEDDEFFILE:=$(BLDDIR)/$(TARGET).prep.def
       
   265           CLEANTARGETS:=$(CLEANTARGETS) $(PREPPEDDEFFILE)
       
   266 
       
   267           define win32def2lib
       
   268             $(IMPORTLIBTARGET): $(DEFFILE)
       
   269 	          $(call startrule,win32def2lib) \
       
   270 	          $(PREPDEF) "$(DEFFILE)" "$(PREPPEDDEFFILE)" && \
       
   271 	          $(LD) $(PREPPEDDEFFILE) $(OPT.IMPORTLIB) -o "$$@" $(OPT.ADDCOMMAND) "out:$(IMPORTLIBLINKAS)" $(OPT.WARNINGS) off \
       
   272 	          $(call endrule,win32def2lib)
       
   273           endef
       
   274           $(eval $(win32def2lib))
       
   275           $(eval TARGET_$(call sanitise,$(IMPORTLIBTARGET)):=1)
       
   276         endif
       
   277       endif
       
   278     endif
       
   279   endif
       
   280 endif
       
   281 
       
   282 
       
   283 ifneq ($(BASE_TYPE),importlib)
       
   284 
       
   285   #############
       
   286   ## COMPILE ##
       
   287   #############
       
   288 
       
   289   ifeq ($(COPY_FOR_STATIC_LINKAGE),1)
       
   290     BINTARGETSTATICLINK:=$(BINDIRSTATICLINK)/$(TARGET).$(if $(REQUESTEDTARGETEXT),$(REQUESTEDTARGETEXT),$(TARGETTYPE))
       
   291   endif
       
   292 
       
   293   CLEANTARGETS:=$(CLEANTARGETS) $(BINTARGET) $(BINTARGETSTATICLINK)
       
   294   RELEASABLES:=$(RELEASABLES) $(BINTARGET) $(BINTARGETSTATICLINK)
       
   295 
       
   296   # work on a local source files list
       
   297   SRCFILES:=$(SOURCE)
       
   298   # and there may be more source for stage 2 in OE builds
       
   299   SRCFILES_OE:=
       
   300 
       
   301   ifneq ($(BASE_TYPE),staticlib)
       
   302     # add the generated UID source file
       
   303     GENSOURCE:=$(BLDDIR)/$(TARGET).UID.CPP
       
   304     SRCFILES:=$(SRCFILES) $(GENSOURCE)
       
   305 
       
   306     # the generated symbol lookup source file for Open Environment.
       
   307     # this only gets linked in at stage 2
       
   308     SYMSOURCE:=$(if $(OPEN_ENVIRONMENT),$(BLDDIR)/$(TARGET)_SYM_.cpp,)
       
   309     SRCFILES_OE:=$(SYMSOURCE)
       
   310 
       
   311     CLEANTARGETS:=$(CLEANTARGETS) $(GENSOURCE) $(SYMSOURCE)
       
   312 
       
   313     ifeq ($(UID2),00000000)
       
   314       ifneq ($(UID2_DEFAULT),)
       
   315         UID2:=$(UID2_DEFAULT)
       
   316       endif
       
   317     endif
       
   318 
       
   319     ifeq ($(SECUREID),)
       
   320       SECUREID:=$(UID3)
       
   321     endif
       
   322 
       
   323     define win32generateUIDcpp
       
   324       $(GENSOURCE): $(PROJECT_META)
       
   325 	    $(call startrule,win32generateUIDcpp,,) \
       
   326 	    echo "// SBS-generated uid source file" > $$@ && \
       
   327 	    echo "#include <e32cmn.h>" >> $$@ && \
       
   328 	    echo "#pragma data_seg(\".SYMBIAN\")" >> $$@ && \
       
   329 	    echo "__EMULATOR_IMAGE_HEADER2(0x$(UID1),0x$(UID2),0x$(UID3),EPriority$(EPOCPROCESSPRIORITY),0x$(CAPABILITYFLAG1),0x$(CAPABILITYFLAG2),0x$(SECUREID),0x$(VENDORID),0x$(VERSIONHEX),$(EPOCALLOWDLLDATA))" >> $$@ && \
       
   330 	    echo "#pragma data_seg()" >> $$@ \
       
   331 	    $(call endrule,win32generateUIDcpp)
       
   332     endef
       
   333     $(eval $(win32generateUIDcpp))
       
   334   endif # neq $(BASE_TYPE),staticlib
       
   335 
       
   336   # object files
       
   337   OBJECTFILES:=$(patsubst %,$(BLDDIR)/%,$(addsuffix .o,$(basename $(notdir $(call allsuffixsubst,.cia .CIA .Cia,_.cia,$(SRCFILES))))))
       
   338   OBJECTFILES:=$(patsubst %.UID.o,%_UID_.o,$(OBJECTFILES))
       
   339 
       
   340   # object file extras for stage 2
       
   341   OBJECTFILES_OE:=$(patsubst %,$(BLDDIR)/%,$(addsuffix .o,$(basename $(notdir $(SRCFILES_OE)))))
       
   342 
       
   343   CLEANTARGETS:=$(CLEANTARGETS) $(OBJECTFILES) $(OBJECTFILES_OE)
       
   344 
       
   345   # include paths and preinclude file
       
   346   UINCLUDE:=$(patsubst %,$(OPT.USERINCLUDE)%,$(USERINCLUDE))
       
   347   SINCLUDE:=$(patsubst %,$(OPT.SYSINCLUDE)%,$(SYSTEMINCLUDE))
       
   348   PINCLUDE:=$(OPT.PREINCLUDE)$(notdir $(PRODUCT_INCLUDE))
       
   349 
       
   350   #INCLUDES:=$(UINCLUDE) $(OPT.SPLITINCLUDE) $(SINCLUDE) $(PINCLUDE)
       
   351   INCLUDES:=$(OPT.SPLITINCLUDE) $(UINCLUDE) $(SINCLUDE) $(PINCLUDE)
       
   352 
       
   353   # macro definitions
       
   354   DEFINES:=$(call makemacrodef,$(OPT.DEFINE),$(CDEFS) $(TARGET_MACRO))
       
   355 
       
   356 
       
   357   # $(1) is the name of the source file, $(2) is the extension to map it to e.g. .o
       
   358   # no space in front of function body
       
   359   define mapwin32file
       
   360     $(patsubst %.UID$(2),%_UID_$(2),$(BLDDIR)/$(addsuffix $2,$(basename $(notdir $(call allsuffixsubst,.cia .CIA .Cia,_.cia,$(1))))))
       
   361   endef
       
   362 
       
   363   # compile all source files, creating and including compiler generated dependency files along the way
       
   364   # SED is used to (a) remove relatively pathed "object_file: source_file" references that can appear
       
   365   # with some versions of mwccsym2 and (b) convert slashes
       
   366   define win32compile2object
       
   367 
       
   368     $(eval DEPENDFILENAME:=$(call mapwin32file,$(1),.o.d))
       
   369     $(eval DEPENDFILE:=$(wildcard $(DEPENDFILENAME)))
       
   370 
       
   371     $(call mapwin32file,$(1),.o): $(1) $(PROJECT_META) $(if $(DEPENDFILE),,RESOURCE BITMAP EXPORT) $(if $(USE_TRACE_COMPILER),$(TRACE_MARKER))
       
   372 	  $(call startrule,win32compile2object,,$(1)) \
       
   373 	  $(CC) $$(if $$(filter %.C,$(1)),-lang c) $(CFLAGS) $(OPTION_CW) \
       
   374 	  $(if $(STDCPP_BUILD),$$(if $$(filter %.c %.C,$(1)),,$$(call makemacrodef,$(OPT.DEFINE),$(STDCPP_WCHAR_DEF))),) \
       
   375 	  $(DEFINES) $(INCLUDES) $(OPT.OUT)"$$@" "$(1)" && \
       
   376 	  $(GNUSED) 's#\\\\\(.\)#/\1#g;s#/ #\\\ #g;s#\([A-Za-z]:\)\\\\#\1/#g;1,1s#.*: .* \(.\)\?$$$$#$(call mapwin32file,$(1),.o): $1 \1#' $(call mapwin32file,$(1),.dep) > $(call mapwin32file,$(1),.o.d) \
       
   377 	  $(call endrule,win32compile2object)
       
   378 
       
   379     CLEANTARGETS:=$$(CLEANTARGETS) $(call mapwin32file,$(1),.dep)
       
   380 
       
   381     CLEANTARGETS:=$$(CLEANTARGETS) $(DEPENDFILENAME)
       
   382     ifneq "$(DEPENDFILE)" ""
       
   383     ifeq ($(NO_DEPEND_INCLUDE),)
       
   384       ifeq "$(filter %CLEAN,$(call uppercase,$(MAKECMDGOALS)))" ""
       
   385         -include $(DEPENDFILE)
       
   386       endif
       
   387     endif
       
   388     endif
       
   389 
       
   390     # individual source file compilation
       
   391     SOURCETARGET_$(call sanitise,$(1)): $(call mapwin32file,$(1),.o)
       
   392 
       
   393   endef
       
   394 
       
   395   # List target, depends on object file
       
   396   define win32list
       
   397   LISTING:: $(OBJECTFILES) $(OBJECTFILES_OE)
       
   398 	$(call startrule,win32listing) \
       
   399 	$(CC) $(OPT.LISTING) $(patsubst %.UID.o,%_UID_.o,$(BLDDIR)/$(addsuffix .o,$(basename $(notdir $(1))))) -o $(basename $1).WINSCW.lst \
       
   400 	$(call endrule,win32listing)
       
   401   endef
       
   402 
       
   403   $(foreach SRCFILE,$(SRCFILES) $(SRCFILES_OE),$(eval $(call win32compile2object,$(SRCFILE))))
       
   404   $(foreach SRCFILE,$(SRCFILES) $(SRCFILES_OE),$(eval $(call win32list,$(SRCFILE))))
       
   405 
       
   406   ######################
       
   407   ## RESOURCE COMPILE ##
       
   408   ######################
       
   409 
       
   410   # If Python has been used to construct the environment on Windows then the standard MW include path environment
       
   411   # variable will have been munged to UPPERCASE.
       
   412   STDMWCINCLUDEPATHS:=$(if $(MWCSym2Includes),$(MWCSym2Includes),$(MWCSYM2INCLUDES))
       
   413 
       
   414   define win32resourcecompile
       
   415     # Note that two calls are made to the resource compiler here.  There seems to be no means to override the
       
   416     # default behaviour of dumping dependency files into the CWD when using -MD.  So - we compile once for real,
       
   417     # and then pipe dependency output through SED afterwards to create the dependency file where we want it
       
   418 
       
   419     $(eval DEPENDFILENAME:=$(call mapwin32file,$(1),.res.d))
       
   420     $(eval DEPENDFILE:=$(wildcard $(DEPENDFILENAME)))
       
   421 
       
   422     $(call mapwin32file,$(1),.res): $(1) $(PROJECT_META) $(if $(DEPENDFILE),,RESOURCE BITMAP EXPORT)
       
   423 	  $(call startrule,win32resourcecompile,,$(1)) \
       
   424 	  MWCIncludes='$(STDMWCINCLUDEPATHS)' $(RC) $(OPT.OUT)"$$@" "$(1)" && \
       
   425 	  MWCIncludes='$(STDMWCINCLUDEPATHS)' $(RC) -make $(OPT.OUT)"$$@" "$(1)" | \
       
   426 	  $(GNUSED) 's#\\\\\(.\)#/\1#g;s#/ #\\\ #g;s#\([A-Za-z]:\)\\\\#\1/#g;1,1s#.*: .* \(.\)\?$$$$#$(call mapwin32file,$(1),.res): $1 \1#' > $(call mapwin32file,$(1),.res.d) \
       
   427 	  $(call endrule,win32resourcecompile)
       
   428 
       
   429     CLEANTARGETS:=$$(CLEANTARGETS) $(DEPENDFILENAME)
       
   430     ifneq "$(DEPENDFILE)" ""
       
   431     ifeq ($(NO_DEPEND_INCLUDE),)
       
   432       ifeq "$(filter %CLEAN,$(call uppercase,$(MAKECMDGOALS)))" ""
       
   433         -include $(DEPENDFILE)
       
   434       endif
       
   435     endif
       
   436     endif
       
   437 
       
   438   endef
       
   439 
       
   440   $(foreach WIN32RESOURCEFILE,$(WIN32_RESOURCE),$(eval $(call win32resourcecompile,$(WIN32RESOURCEFILE))))
       
   441   OBJECTFILES:=$(OBJECTFILES) $(patsubst %,$(BLDDIR)/%,$(addsuffix .res,$(basename $(notdir $(WIN32_RESOURCE)))))
       
   442 
       
   443   ##################
       
   444   ## LINK/ARCHIVE ##
       
   445   ##################
       
   446 
       
   447   # libraries
       
   448   STATICLIBS:=$(patsubst %,%.lib,$(STATICLIBRARY))
       
   449   STATICLIBFILES:=$(patsubst %,$(STATLIBDIR)/%,$(STATICLIBS))
       
   450   LINKER_FIRSTSTATLIBFILE:=$(STATLIBDIR)/$(LINKER_FIRSTSTATLIB)
       
   451 
       
   452   ifeq ($(VARIANTTYPE),urel)
       
   453     LINKLIBS:=$(patsubst %.dso,%.lib,$(LIBRARY))
       
   454   else
       
   455     LINKLIBS:=$(patsubst %.dso,%.lib,$(LIBRARY_DEBUG))
       
   456   endif
       
   457 
       
   458   LINKLIBFILES:=$(patsubst %,$(LIBDIR)/%,$(LINKLIBS))
       
   459 
       
   460   MAP:=
       
   461   ifneq ($(BASE_TYPE),staticlib)
       
   462     ifneq ($(BASE_TYPE),importlib)
       
   463       # link map file (urel only)
       
   464       ifeq ($(VARIANTTYPE),urel)
       
   465         MAP:=$(OPT.MAP)$(BINTARGET).map
       
   466         CLEANTARGETS:=$(CLEANTARGETS) $(BINTARGET).map
       
   467         RELEASABLES:=$(RELEASABLES) $(BINTARGET).map
       
   468       endif
       
   469     endif
       
   470   endif
       
   471 
       
   472   # all object files are listed in a response file to minimise the length of linker calls
       
   473   OBJECTFILES_LRF:=$(BLDDIR)/$(TARGET)_$(VARIANTTYPE)_objects.lrf
       
   474   CLEANTARGET:=$(CLEANTARGETS) $(OBJECTFILES_LRF)
       
   475 
       
   476   define groupin10
       
   477 	$(if $1,@echo -e $(foreach L,$(wordlist 1,10,$1),"$(L)\\n") >> $(OBJECTFILES_LRF),)
       
   478 	$(if $1,$(call groupin10,$(wordlist 11,$(words $1),$1)),@true)
       
   479   endef
       
   480 
       
   481   #
       
   482   # Archive
       
   483   #
       
   484   ifeq ($(BASE_TYPE),staticlib)
       
   485     define win32archive
       
   486       $(BINTARGET): $(OBJECTFILES)
       
   487 	    @echo "" > $(OBJECTFILES_LRF);
       
   488 		$(call groupin10,$(notdir $(OBJECTFILES))) ;
       
   489 	    $(call startrule,win32archive) \
       
   490 	    $(LD) $(OPT.STATICLIBRARY) $(LFLAGS) $(OPT.NOIMPLIB) $(WIN32_LIBRARIES) $(OPT.OUT)"$$@" $(STDCPPTAGFILE) $(OPT.LIBPATH)$(BLDDIR) $(OPT.SEARCH) @$(OBJECTFILES_LRF) \
       
   491 	    $(if $(SAVESPACE),; $(GNURM) -rf $(BLDDIR); true,) \
       
   492 	    $(call endrule,win32archive)
       
   493     endef
       
   494     $(eval $(win32archive))
       
   495   endif
       
   496 
       
   497   ifneq ($(EPOCHEAPSIZEMIN_DEC_KB),)
       
   498     LFLAGS:=$(LFLAGS) $(OPT.HEAPRESERVE)$(EPOCHEAPSIZEMAX_DEC_KB) $(OPT.HEAPCOMMIT)$(EPOCHEAPSIZEMIN_DEC_KB)
       
   499   endif
       
   500 
       
   501   #
       
   502   # Simple link
       
   503   #
       
   504   ifeq ($(BASE_TYPE),exe)
       
   505     define win32simplelink
       
   506       $(BINTARGET).map: $(BINTARGET)
       
   507 
       
   508       $(BINTARGET): $(OBJECTFILES) $(LINKER_FIRSTSTATLIBFILE) $(NEWLIBFILE) $(STATICLIBFILES) $(LINKLIBFILES)
       
   509 	    @echo "" > $(OBJECTFILES_LRF);
       
   510 		$(call groupin10,$(notdir $(OBJECTFILES))) ;
       
   511 	    $(call startrule,win32simplelink) \
       
   512 	    $(if $(SUPPORTS_STDCPP_NEWLIB),$(if $(STATICLIBFILES),$(CHECKLIB) $(CHECKLIB_TYPE) $(OPT.CHECKLIB.WIN32) $(STATICLIBFILES) &&,),) \
       
   513 	    MWSym2LibraryFiles="$(MWSym2LibraryFiles)" $(LD) $(LFLAGS) $(OPT.MENTRYPOINT)$(ENTRYSYMBOL) $(MAP) $(LINKER_FIRSTSTATLIBFILE) $(NEWLIBFILE) $(WIN32_LIBRARIES) $(STATICLIBFILES) $(LINKLIBFILES) $(OPT.OUT)"$$@" $(OPT.NOIMPLIB) $(OPT.LIBPATH)$(BLDDIR) $(OPT.SEARCH) @$(OBJECTFILES_LRF) \
       
   514 	    $(if $(SAVESPACE),; $(GNURM) -rf $(BLDDIR); true,) \
       
   515 	    $(call endrule,win32simplelink)
       
   516     endef
       
   517     $(eval $(win32simplelink))
       
   518   endif
       
   519 
       
   520   #
       
   521   # Two stage link
       
   522   #
       
   523   ifeq ($(BASE_TYPE),dll)
       
   524     TMP_IMPLIB:=$(BLDDIR)/$(TARGET).lib
       
   525     TMP_INFFILE:=$(BLDDIR)/$(TARGET).inf
       
   526     TMP_SYMFILE:=$(if $(OPEN_ENVIRONMENT),$(BLDDIR)/$(TARGET).sym,)
       
   527     TMP_TARGET:=$(BLDDIR)/$(TARGET).$(if $(REQUESTEDTARGETEXT),$(REQUESTEDTARGETEXT),$(TARGETTYPE))
       
   528     TMP_DEFFILE:=$(BLDDIR)/$(TARGET).def
       
   529 
       
   530     CLEANTARGETS:=$(CLEANTARGETS) $(TMP_IMPLIB) $(TMP_INFFILE) $(TMP_TARGET) $(TMP_DEFFILE) $(TMP_SYMFILE)
       
   531 
       
   532     MAKEDEF_ARGS:=-absent $(ENTRYSYMBOL) -Inffile  $(call dblquote,$(TMP_INFFILE)) $(NAME_LOOKUP)
       
   533 
       
   534     ifeq ($(SYSTEM_TARGET),1)
       
   535         MAKEDEF_ARGS:=$(MAKEDEF_ARGS) -SystemTargetType
       
   536     endif
       
   537 
       
   538     ifneq ($(FIXED_EXPORT),)
       
   539       # Fixed export TARGETTYPE, but with possibility of a .def file if explicitly specified and available
       
   540       ifeq ($(DEFFILEKEYWORD),1)
       
   541         ifneq ($(DEFFILE),)
       
   542           MAKEDEF_ARGS:=$(MAKEDEF_ARGS) -Frzfile $(call dblquote,$(DEFFILE))
       
   543         endif
       
   544       endif
       
   545       MAKEDEF_ARGS:=$(MAKEDEF_ARGS) -1 $(FIXED_EXPORT)
       
   546     else
       
   547       # Variable export TARGETTYPE with either deduced or explicitly specified .def file (if available)
       
   548       ifneq ($(DEFFILE),)
       
   549         MAKEDEF_ARGS:=$(MAKEDEF_ARGS) -Frzfile $(call dblquote,$(DEFFILE))
       
   550       endif
       
   551     endif
       
   552 
       
   553 
       
   554     ifneq ($(EXPORTSUNFROZEN),)
       
   555     	LIBRARY: $(TMP_IMPLIB)
       
   556     endif
       
   557 
       
   558     define win32stageonelink
       
   559       # Stage One
       
   560       # Link by name, generating temporary main binary and import library.
       
   561       $(TMP_IMPLIB): $(TMP_TARGET)
       
   562 
       
   563       $(TMP_TARGET): $(OBJECTFILES) $(LINKER_FIRSTSTATLIBFILE) $(NEWLIBFILE) $(STATICLIBFILES) $(LINKLIBFILES)
       
   564 	    @echo "" > $(OBJECTFILES_LRF);
       
   565 		$(call groupin10,$(notdir $(OBJECTFILES))) ;
       
   566 	    $(call startrule,win32stageonelink) \
       
   567 	    $(if $(SUPPORTS_STDCPP_NEWLIB),$(if $(STATICLIBFILES),$(CHECKLIB) $(CHECKLIB_TYPE) $(OPT.CHECKLIB.WIN32) $(STATICLIBFILES) &&,),) \
       
   568 	    MWSym2LibraryFiles="$(MWSym2LibraryFiles)" $(LD) $(LFLAGS) $(OPT.MENTRYPOINT)$(ENTRYSYMBOL) $(OPT.EXPORT)$(EXPORT_TYPE) $(OPT.NOCOMPACTIMPORTLIB) $(OPT.ADDCOMMAND) "out:$(TARGET).$(if $(REQUESTEDTARGETEXT),$(REQUESTEDTARGETEXT),$(TARGETTYPE))" $(OPT.WARNINGS) off $(OPT.IMPLIB)"$(TMP_IMPLIB)" $(OPT.OUT)"$(TMP_TARGET)" $(LINKER_FIRSTSTATLIBFILE) $(NEWLIBFILE) $(WIN32_LIBRARIES) $(STATICLIBFILES) $(LINKLIBFILES) $(OPT.LIBPATH)$(BLDDIR) $(OPT.SEARCH) @$(OBJECTFILES_LRF) \
       
   569 	    $(call endrule,win32stageonelink)
       
   570     endef
       
   571     $(eval $(win32stageonelink))
       
   572 
       
   573     define win32processexports
       
   574       # Process exports
       
   575       # Generate a descriptive info file from the import library.
       
   576       # Push info file through MAKEDEF to generated a valid .def file for link by ordinal.
       
   577       $(TMP_DEFFILE): $(TMP_IMPLIB)
       
   578 	    $(call startrule,win32processexports) \
       
   579 	    $(LD) $(LFLAGS_INFGEN) $(OPT.OUT)"$(TMP_INFFILE)" "$(TMP_IMPLIB)" && \
       
   580 	    $(MAKEDEF) $(MAKEDEF_ARGS) "$$@" \
       
   581 	    $(call endrule,win32processexports)
       
   582     endef
       
   583     $(eval $(win32processexports))
       
   584 
       
   585     ifeq ($(OPEN_ENVIRONMENT),1)
       
   586       define win32processoeexports
       
   587    	    # Process additional exports for Open Environment
       
   588         # Generate a symbol file from the temporary DLL.
       
   589         # Generate a C++ source file from the symbol file
       
   590 
       
   591         $(TMP_SYMFILE): $(TMP_TARGET)
       
   592 	      $(call startrule,win32generatesymfile) \
       
   593 	      $(LD) $(LFLAGS_SYMGEN) $(OPT.OUT)"$(TMP_SYMFILE)" "$(TMP_TARGET)" \
       
   594 	      $(call endrule,win32generatesymfile)
       
   595 
       
   596         $(SYMSOURCE): $(TMP_SYMFILE)
       
   597 	      $(call startrule,win32generatesymcpp) \
       
   598 	      $(SYMLOOKUPUTIL) $(OPT.OUT)"$(SYMSOURCE)" $(OPT.SYM)"$(TMP_SYMFILE)" $(SYMLOOKUPARGS) \
       
   599 	      $(call endrule,win32generatesymcpp)
       
   600       endef
       
   601       $(eval $(win32processoeexports))
       
   602     endif
       
   603 
       
   604     define win32stagetwolink
       
   605       # Stage Two
       
   606       # Link by ordinal, based on a previously MAKEDEF-generated temporary .def file
       
   607       # Optionally create an import library if EXPORTUNFROZEN is specified
       
   608       #
       
   609       $(BINTARGET).map: $(BINTARGET)
       
   610 
       
   611       $(BINTARGET): $(OBJECTFILES) $(OBJECTFILES_OE) $(LINKER_FIRSTSTATLIBFILE) $(STATICLIBFILES) $(NEWLIBFILE) $(LINKLIBFILES) $(TMP_DEFFILE)
       
   612 	    @echo "" > $(OBJECTFILES_LRF);
       
   613 		$(call groupin10,$(notdir $(OBJECTFILES) $(OBJECTFILES_OE))) ;
       
   614 	    $(call startrule,win32stagetwolink) \
       
   615 	    MWSym2LibraryFiles="$(MWSym2LibraryFiles)" \
       
   616 	    $(LD) $(LFLAGS) $(OPT.DEFFILE)$(TMP_DEFFILE) $(MAP) $(LINKER_FIRSTSTATLIBFILE) $(NEWLIBFILE) $(WIN32_LIBRARIES) $(STATICLIBFILES) $(LINKLIBFILES) \
       
   617 	    $(OPT.OUT)"$$@" \
       
   618 	    $(if $(EXPORTUNFROZEN),$(OPT.IMPLIB)$(IMPORTLIBTARGET),$(OPT.NOIMPLIB)) \
       
   619 	    $(OPT.LIBPATH)$(BLDDIR) $(OPT.SEARCH) @$(OBJECTFILES_LRF) \
       
   620 	    $(if $(SAVESPACE),; $(GNURM) -rf $(BLDDIR); true,) \
       
   621 	    $(call endrule,win32stagetwolink)
       
   622     endef
       
   623     $(eval $(win32stagetwolink))
       
   624 
       
   625     define win32copyforstaticlink
       
   626       # Copy additonal binary to "traditional" output location (if required)
       
   627       $(BINTARGETSTATICLINK): $(BINTARGET)
       
   628 	    $(call startrule,win32copyforstaticlink) \
       
   629 	    $(GNUCP) $$< $$@ \
       
   630 	    $(call endrule,win32copyforstaticlink)
       
   631     endef
       
   632     ifeq ($(COPY_FOR_STATIC_LINKAGE),1)
       
   633       $(eval $(win32copyforstaticlink))
       
   634     endif
       
   635 
       
   636     define e32freeze
       
   637       # DLL-type targets that support import library generation support freezing of exports using EFREEZE
       
   638       FREEZE:: $(1)
       
   639 	    $(call startrule,freeze,,$(RESOLVED_DEFFILE)) \
       
   640 	    $(EFREEZE) $(EFREEZE_REMOVE_OPTION) "$(RESOLVED_DEFFILE)" $(FIVESPACES) "$(2)" \
       
   641 	    $(call endrule,freeze)
       
   642     endef
       
   643     # Create only one freeze target per urel/udeb variant as the interface won't differ between them
       
   644     # Only create a freeze target if the component supports import library generation
       
   645     ifneq ($(TARGET_$(call sanitise,$(IMPORTLIBTARGET))_FREEZE),1)
       
   646       ifeq ($(SUPPORTS_IMPORT_LIBRARY),1)
       
   647         $(eval $(call e32freeze,$(BINTARGET),$(TMP_DEFFILE)))
       
   648         $(eval TARGET_$(call sanitise,$(IMPORTLIBTARGET))_FREEZE:=1)
       
   649       endif
       
   650     endif
       
   651   endif
       
   652 endif # neq $(BASE_TYPE),importlib
       
   653 
       
   654 
       
   655 # Global targets
       
   656 .PHONY:: $(ALLTARGET)
       
   657 $(ALLTARGET):: $(RELEASABLES)
       
   658 TARGET:: $(RELEASABLES)
       
   659 
       
   660 ifeq ($(TARGET_$(call sanitise,$(IMPORTLIBTARGET))),1)
       
   661   LIBRARY:: $(IMPORTLIBTARGET)
       
   662 else
       
   663   ifeq ($(BASE_TYPE),staticlib)
       
   664     LIBRARY:: $(BINTARGET)
       
   665   endif
       
   666 endif
       
   667 
       
   668 
       
   669 # Deal with test code batch files generation.
       
   670 ifneq ($(TESTPATH),)
       
   671   EPOC_ROOT:=$(patsubst %/,%,$(EPOCROOT))
       
   672   TOBLDINF:=$(dir $(subst :,,$(subst $(EPOC_ROOT)/,,$(COMPONENT_META))))
       
   673 
       
   674 
       
   675   BATCHDIR:=$(EPOCROOT)/epoc32/release/$(VARIANTPLATFORM)/$(VARIANTTYPE)/z/test/
       
   676   $(eval $(call MakeTestBatchFiles,$(TARGET),$(BATCHDIR)$(MODULE)/$(VARIANTPLATFORM).$(TESTPATH)))
       
   677   BATCHFILE_CREATED_$(BATCHDIR)$(MODULE)/$(VARIANTPLATFORM).$(TESTPATH):=1
       
   678   TARGET_CREATED_$(EPOCROOT)/epoc32/release/$(VARIANTPLATFORM)/$(VARIANTTYPE)/z/test/$(MODULE)/$(VARIANTPLATFORM).$(TESTPATH)_$(TARGET):=1
       
   679   RELEASABLES:=$(RELEASABLES) $(EPOCROOT)/epoc32/release/$(VARIANTPLATFORM)/$(VARIANTTYPE)/z/test/$(MODULE)/$(VARIANTPLATFORM).$(TESTPATH)
       
   680   CLEANTARGETS:=$(CLEANTARGETS) $(EPOCROOT)/epoc32/release/$(VARIANTPLATFORM)/$(VARIANTTYPE)/z/test/$(MODULE)/$(VARIANTPLATFORM).$(TESTPATH)
       
   681 endif
       
   682 
       
   683 # clean up
       
   684 $(eval $(call GenerateStandardCleanTarget,$(CLEANTARGETS),$(CREATABLEPATHS),))
       
   685 # make the output directories while reading makefile - some build engines prefer this
       
   686 $(call makepath,$(CREATABLEPATHS))
       
   687 # for the abld -what target
       
   688 $(eval $(call whatmacro,$(RELEASABLES),WHATWINSCW))