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# 17HOST_CC ?= cl.exe /nologo 18HOST_CXX ?= cl.exe /nologo /EHsc 19HOST_LINK ?= link.exe /nologo 20HOST_LIB ?= lib.exe /nologo 21 22ifeq (,$(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) 26endif 27 28 29ifeq ($(CONFIG),Release) 30WIN_OPT_FLAGS ?= /O2 /MT /Z7 -DNDEBUG 31else 32WIN_OPT_FLAGS ?= /Od /MTd /Z7 -DNACL_SDK_DEBUG 33endif 34 35WIN_FLAGS ?= -DWIN32 -D_WIN32 -DPTW32_STATIC_LIB 36 37 38# 39# Individual Macros 40# 41# $1 = Source Name 42# $2 = Compile Flags 43# 44define 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)) 47endef 48 49define 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)) 52endef 53 54 55# $1 = Source Name 56# $2 = POSIX Compile Flags (unused) 57# $3 = VC Compile Flags 58# 59define COMPILE_RULE 60ifeq ($(suffix $(1)),.c) 61$(call C_COMPILER_RULE,$(1),$(3) $(foreach inc,$(INC_PATHS),/I$(inc))) 62else 63$(call CXX_COMPILER_RULE,$(1),$(3) $(foreach inc,$(INC_PATHS),/I$(inc))) 64endif 65endef 66 67 68# 69# LIB Macro 70# 71# $1 = Target Name 72# $2 = List of Sources 73# 74# 75define LIB_RULE 76$(STAMPDIR)/$(1).stamp: $(LIBDIR)/$(OSNAME)_x86_32_host/$(CONFIG)/$(1).lib 77 @echo "TOUCHED $$@" > $(STAMPDIR)/$(1).stamp 78 79all:$(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)) 83endef 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# 96define LINKER_RULE 97all: $(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)) 100endef 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# 113define LINK_RULE 114$(call LINKER_RULE,$(OUTDIR)/$(1)$(HOST_EXT),$(foreach src,$(2),$(OUTDIR)/$(basename $(src)).o),$(3),$(4),$(LIB_PATHS),$(6)) 115endef 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# 126define STRIP_RULE 127all: $(OUTDIR)/$(1)$(HOST_EXT) 128$(OUTDIR)/$(1)$(HOST_EXT): $(OUTDIR)/$(2)$(HOST_EXT) 129 $(call LOG,COPY,$$@,$(CP) $$^ $$@) 130endef 131 132all: $(LIB_LIST) $(DEPS_LIST) 133