1 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Use of this source code is governed by a BSD-style license that can be 3 # found in the LICENSE file. 4 5 # 6 # GNU Make based build file. For details on GNU Make see: 7 # http://www.gnu.org/software/make/manual/make.html 8 # 9 10 11 # 12 # Macros for TOOLS 13 # 14 # We use the C++ compiler for everything and then use the -Wl,-as-needed flag 15 # in the linker to drop libc++ unless it's actually needed. 16 # 17 HOST_CC ?= cl.exe /nologo 18 HOST_CXX ?= cl.exe /nologo /EHsc 19 HOST_LINK ?= link.exe /nologo 20 HOST_LIB ?= lib.exe /nologo 21 22 ifeq (,$(findstring cl.exe,$(shell $(WHICH) cl.exe))) 23 $(warning To skip the host build use:) 24 $(warning "make NO_HOST_BUILDS=1") 25 $(error Unable to find cl.exe in PATH while building Windows host build) 26 endif 27 28 29 ifeq ($(CONFIG),Release) 30 WIN_OPT_FLAGS ?= /O2 /MT /Z7 -DNDEBUG 31 else 32 WIN_OPT_FLAGS ?= /Od /MTd /Z7 -DNACL_SDK_DEBUG 33 endif 34 35 WIN_FLAGS ?= -DWIN32 -D_WIN32 -DPTW32_STATIC_LIB 36 37 38 # 39 # Individual Macros 40 # 41 # $1 = Source Name 42 # $2 = Compile Flags 43 # 44 define C_COMPILER_RULE 45 $(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 46 $(call LOG,CC,$$@,$(HOST_CC) /Fo$$@ /c $$< $(WIN_OPT_FLAGS) $(2) $(WIN_FLAGS)) 47 endef 48 49 define CXX_COMPILER_RULE 50 $(call SRC_TO_OBJ,$(1)): $(1) $(TOP_MAKE) | $(dir $(call SRC_TO_OBJ,$(1)))dir.stamp 51 $(call LOG,CXX,$$@,$(HOST_CXX) /Fo$$@ -c $$< $(WIN_OPT_FLAGS) $(2) $(WIN_FLAGS)) 52 endef 53 54 55 # $1 = Source Name 56 # $2 = POSIX Compile Flags (unused) 57 # $3 = VC Compile Flags 58 # 59 define COMPILE_RULE 60 ifeq ($(suffix $(1)),.c) 61 $(call C_COMPILER_RULE,$(1),$(3) $(foreach inc,$(INC_PATHS),/I$(inc))) 62 else 63 $(call CXX_COMPILER_RULE,$(1),$(3) $(foreach inc,$(INC_PATHS),/I$(inc))) 64 endif 65 endef 66 67 68 # 69 # LIB Macro 70 # 71 # $1 = Target Name 72 # $2 = List of Sources 73 # 74 # 75 define LIB_RULE 76 $(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(OSNAME)_x86_32_host/$(CONFIG)/$(1).lib 77 @echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp 78 79 all:$(LIBDIR)/$(OSNAME)_x86_32_host/$(CONFIG)/$(1).lib 80 $(LIBDIR)/$(OSNAME)_x86_32_host/$(CONFIG)/$(1).lib: $(foreach src,$(2),$(OUTDIR)/$(basename $(src)).o) 81 $(MKDIR) -p $$(dir $$@) 82 $(call LOG,LIB,$$@,$(HOST_LIB) /OUT:$$@ $$^ $(WIN_LDFLAGS)) 83 endef 84 85 86 # 87 # Link Macro 88 # 89 # $1 = Target Name 90 # $2 = List of inputs 91 # $3 = List of libs 92 # $4 = List of deps 93 # $5 = List of lib dirs 94 # $6 = Other Linker Args 95 # 96 define LINKER_RULE 97 all: $(1) 98 $(1): $(2) $(foreach dep,$(4),$(STAMPDIR)/$(dep).stamp) 99 $(call LOG,LINK,$$@,$(HOST_LINK) /DLL /OUT:$(1) /PDB:$(1).pdb $(2) /DEBUG $(foreach path,$(5),/LIBPATH:$(path)/$(OSNAME)_x86_32_host/$(CONFIG)) $(foreach lib,$(3),$(lib).lib) $(6)) 100 endef 101 102 103 # 104 # Link Macro 105 # 106 # $1 = Target Name 107 # $2 = List of Sources 108 # $3 = List of LIBS 109 # $4 = List of DEPS 110 # $5 = POSIX Linker Switches 111 # $6 = VC Linker Switches 112 # 113 define LINK_RULE 114 $(call LINKER_RULE,$(OUTDIR)/$(1)$(HOST_EXT),$(foreach src,$(2),$(OUTDIR)/$(basename $(src)).o),$(3),$(4),$(LIB_PATHS),$(6)) 115 endef 116 117 118 # 119 # Strip Macro 120 # This is a nop (copy) since visual studio already keeps debug info 121 # separate from the binaries 122 # 123 # $1 = Target Name 124 # $2 = Input Name 125 # 126 define STRIP_RULE 127 all: $(OUTDIR)/$(1)$(HOST_EXT) 128 $(OUTDIR)/$(1)$(HOST_EXT): $(OUTDIR)/$(2)$(HOST_EXT) 129 $(call LOG,COPY,$$@,$(CP) $$^ $$@) 130 endef 131 132 all: $(LIB_LIST) $(DEPS_LIST) 133