Make.defaults revision 1.1.1.1.36.1       1           1.1  jakllsch # -*- makefile -*-
      2           1.1  jakllsch # Copyright (c) 1999-2007 Hewlett-Packard Development Company, L.P.
      3           1.1  jakllsch #	Contributed by David Mosberger <davidm (a] hpl.hp.com>
      4           1.1  jakllsch #	Contributed by Stephane Eranian <eranian (a] hpl.hp.com>
      5           1.1  jakllsch #
      6           1.1  jakllsch #    All rights reserved.
      7           1.1  jakllsch #
      8           1.1  jakllsch #    Redistribution and use in source and binary forms, with or without
      9           1.1  jakllsch #    modification, are permitted provided that the following conditions
     10           1.1  jakllsch #    are met:
     11           1.1  jakllsch #
     12           1.1  jakllsch #    * Redistributions of source code must retain the above copyright
     13           1.1  jakllsch #      notice, this list of conditions and the following disclaimer.
     14           1.1  jakllsch #    * Redistributions in binary form must reproduce the above
     15           1.1  jakllsch #      copyright notice, this list of conditions and the following
     16           1.1  jakllsch #      disclaimer in the documentation and/or other materials
     17           1.1  jakllsch #      provided with the distribution.
     18           1.1  jakllsch #    * Neither the name of Hewlett-Packard Co. nor the names of its
     19           1.1  jakllsch #      contributors may be used to endorse or promote products derived
     20           1.1  jakllsch #      from this software without specific prior written permission.
     21           1.1  jakllsch #
     22           1.1  jakllsch #    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
     23           1.1  jakllsch #    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
     24           1.1  jakllsch #    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
     25           1.1  jakllsch #    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
     26           1.1  jakllsch #    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
     27           1.1  jakllsch #    BE LIABLE FOR ANYDIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY,
     28           1.1  jakllsch #    OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
     29           1.1  jakllsch #    PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
     30           1.1  jakllsch #    PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
     31           1.1  jakllsch #    THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR
     32           1.1  jakllsch #    TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF
     33           1.1  jakllsch #    THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     34           1.1  jakllsch #    SUCH DAMAGE.
     35           1.1  jakllsch #
     36           1.1  jakllsch 
     37           1.1  jakllsch TOPDIR := $(shell if [ "$$PWD" != "" ]; then echo $$PWD; else pwd; fi)
     38           1.1  jakllsch 
     39           1.1  jakllsch #
     40           1.1  jakllsch # Variables below overridable from command-line:
     41           1.1  jakllsch #   make VARNAME=value ...
     42           1.1  jakllsch #
     43           1.1  jakllsch 
     44           1.1  jakllsch #
     45           1.1  jakllsch # Where to install the package. GNU-EFI will create and access
     46           1.1  jakllsch # lib and include under the root
     47           1.1  jakllsch #
     48           1.1  jakllsch INSTALLROOT  := /
     49           1.1  jakllsch PREFIX       := /usr/local
     50           1.1  jakllsch LIBDIR 	     := $(PREFIX)/lib
     51           1.1  jakllsch INSTALL	     := install
     52           1.1  jakllsch 
     53  1.1.1.1.36.1  christos # Compilation tools
     54  1.1.1.1.36.1  christos HOSTCC       := $(prefix)gcc
     55  1.1.1.1.36.1  christos CC           := $(prefix)$(CROSS_COMPILE)gcc
     56  1.1.1.1.36.1  christos AS           := $(prefix)$(CROSS_COMPILE)as
     57  1.1.1.1.36.1  christos LD           := $(prefix)$(CROSS_COMPILE)ld
     58  1.1.1.1.36.1  christos AR           := $(prefix)$(CROSS_COMPILE)ar
     59  1.1.1.1.36.1  christos RANLIB       := $(prefix)$(CROSS_COMPILE)ranlib
     60  1.1.1.1.36.1  christos OBJCOPY      := $(prefix)$(CROSS_COMPILE)objcopy
     61  1.1.1.1.36.1  christos 
     62  1.1.1.1.36.1  christos 
     63           1.1  jakllsch # Host/target identification
     64  1.1.1.1.36.1  christos OS           := $(shell uname -s)
     65  1.1.1.1.36.1  christos HOSTARCH     ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv7.*,arm,' )
     66  1.1.1.1.36.1  christos ARCH         ?= $(shell $(HOSTCC) -dumpmachine | cut -f1 -d- | sed -e s,i[3456789]86,ia32, -e 's,armv7.*,arm,' )
     67  1.1.1.1.36.1  christos 
     68  1.1.1.1.36.1  christos # Get ARCH from the compiler if cross compiling 
     69  1.1.1.1.36.1  christos ifneq ($(CROSS_COMPILE),)
     70  1.1.1.1.36.1  christos   override ARCH := $(shell $(CC) -dumpmachine | cut -f1 -d-| sed -e s,i[3456789]86,ia32, -e 's,armv7.*,arm,' )
     71  1.1.1.1.36.1  christos endif
     72           1.1  jakllsch 
     73           1.1  jakllsch # FreeBSD (and possibly others) reports amd64 instead of x86_64
     74           1.1  jakllsch ifeq ($(ARCH),amd64)
     75           1.1  jakllsch   override ARCH := x86_64
     76           1.1  jakllsch endif
     77           1.1  jakllsch 
     78  1.1.1.1.36.1  christos #
     79  1.1.1.1.36.1  christos # Where to build the package
     80  1.1.1.1.36.1  christos #
     81  1.1.1.1.36.1  christos OBJDIR       := $(TOPDIR)/$(ARCH)
     82           1.1  jakllsch 
     83           1.1  jakllsch #
     84           1.1  jakllsch # Variables below derived from variables above
     85           1.1  jakllsch #
     86           1.1  jakllsch 
     87           1.1  jakllsch # Arch-specific compilation flags
     88           1.1  jakllsch CPPFLAGS += -DCONFIG_$(ARCH)
     89           1.1  jakllsch 
     90  1.1.1.1.36.1  christos CFLAGS += -Wno-error=pragmas
     91  1.1.1.1.36.1  christos 
     92           1.1  jakllsch ifeq ($(ARCH),ia64)
     93           1.1  jakllsch   CFLAGS += -mfixed-range=f32-f127
     94           1.1  jakllsch endif
     95           1.1  jakllsch 
     96           1.1  jakllsch ifeq ($(ARCH),ia32)
     97           1.1  jakllsch   CFLAGS += -mno-mmx -mno-sse
     98           1.1  jakllsch   ifeq ($(HOSTARCH),x86_64)
     99           1.1  jakllsch     ARCH3264 = -m32
    100           1.1  jakllsch   endif
    101           1.1  jakllsch endif
    102           1.1  jakllsch 
    103           1.1  jakllsch ifeq ($(ARCH),x86_64)
    104  1.1.1.1.36.1  christos   GCCVERSION   := $(shell $(CC) -dumpversion | cut -f1 -d.)
    105  1.1.1.1.36.1  christos   GCCMINOR     := $(shell $(CC) -dumpversion | cut -f2 -d.)
    106  1.1.1.1.36.1  christos   USING_CLANG  := $(shell $(CC) -v 2>&1 | grep -q 'clang version' && echo clang)
    107  1.1.1.1.36.1  christos 
    108  1.1.1.1.36.1  christos   # Rely on GCC MS ABI support?
    109  1.1.1.1.36.1  christos   GCCNEWENOUGH := $(shell ( [ $(GCCVERSION) -gt "4" ]           \
    110  1.1.1.1.36.1  christos                             || ( [ $(GCCVERSION) -eq "4" ]      \
    111  1.1.1.1.36.1  christos                                  && [ $(GCCMINOR) -ge "7" ] ) ) \
    112  1.1.1.1.36.1  christos                           && echo 1)
    113  1.1.1.1.36.1  christos   ifeq ($(GCCNEWENOUGH),1)
    114  1.1.1.1.36.1  christos     CPPFLAGS += -DGNU_EFI_USE_MS_ABI -maccumulate-outgoing-args --std=c11
    115  1.1.1.1.36.1  christos   else ifeq ($(USING_CLANG),clang)
    116  1.1.1.1.36.1  christos     CPPFLAGS += -DGNU_EFI_USE_MS_ABI --std=c11
    117  1.1.1.1.36.1  christos   endif
    118  1.1.1.1.36.1  christos 
    119  1.1.1.1.36.1  christos   CFLAGS += -mno-red-zone
    120           1.1  jakllsch   ifeq ($(HOSTARCH),ia32)
    121           1.1  jakllsch     ARCH3264 = -m64
    122           1.1  jakllsch   endif
    123           1.1  jakllsch endif
    124           1.1  jakllsch 
    125  1.1.1.1.36.1  christos ifneq (,$(filter $(ARCH),ia32 x86_64))
    126  1.1.1.1.36.1  christos   # Disable AVX, if the compiler supports that.
    127  1.1.1.1.36.1  christos   CC_CAN_DISABLE_AVX=$(shell $(CC) -Werror -c -o /dev/null -xc -mno-avx - </dev/null >/dev/null 2>&1 && echo 1)
    128  1.1.1.1.36.1  christos   ifeq ($(CC_CAN_DISABLE_AVX), 1)
    129  1.1.1.1.36.1  christos     CFLAGS += -mno-avx
    130  1.1.1.1.36.1  christos   endif
    131  1.1.1.1.36.1  christos endif
    132  1.1.1.1.36.1  christos 
    133  1.1.1.1.36.1  christos ifeq ($(ARCH),mips64el)
    134  1.1.1.1.36.1  christos   CFLAGS += -march=mips64r2
    135  1.1.1.1.36.1  christos   ARCH3264 = -mabi=64
    136  1.1.1.1.36.1  christos endif
    137  1.1.1.1.36.1  christos 
    138  1.1.1.1.36.1  christos #
    139  1.1.1.1.36.1  christos # Set HAVE_EFI_OBJCOPY if objcopy understands --target efi-[app|bsdrv|rtdrv],
    140  1.1.1.1.36.1  christos # otherwise we need to compose the PE/COFF header using the assembler
    141  1.1.1.1.36.1  christos #
    142  1.1.1.1.36.1  christos ifneq ($(ARCH),aarch64)
    143  1.1.1.1.36.1  christos ifneq ($(ARCH),arm)
    144  1.1.1.1.36.1  christos ifneq ($(ARCH),mips64el)
    145  1.1.1.1.36.1  christos export HAVE_EFI_OBJCOPY=y
    146  1.1.1.1.36.1  christos endif
    147  1.1.1.1.36.1  christos endif
    148  1.1.1.1.36.1  christos endif
    149  1.1.1.1.36.1  christos 
    150  1.1.1.1.36.1  christos ifneq ($(ARCH),arm)
    151  1.1.1.1.36.1  christos export LIBGCC=$(shell $(CC) $(ARCH3264) -print-libgcc-file-name)
    152  1.1.1.1.36.1  christos endif
    153  1.1.1.1.36.1  christos 
    154  1.1.1.1.36.1  christos ifeq ($(ARCH),arm)
    155  1.1.1.1.36.1  christos CFLAGS += -marm
    156  1.1.1.1.36.1  christos endif
    157  1.1.1.1.36.1  christos 
    158           1.1  jakllsch # Generic compilation flags
    159           1.1  jakllsch INCDIR  += -I$(SRCDIR) -I$(TOPDIR)/inc -I$(TOPDIR)/inc/$(ARCH) \
    160           1.1  jakllsch            -I$(TOPDIR)/inc/protocol
    161  1.1.1.1.36.1  christos 
    162  1.1.1.1.36.1  christos # Only enable -fpic for non MinGW compilers (unneeded on MinGW)
    163  1.1.1.1.36.1  christos GCCMACHINE := $(shell $(CC) -dumpmachine)
    164  1.1.1.1.36.1  christos ifneq (mingw32,$(findstring mingw32, $(GCCMACHINE)))
    165  1.1.1.1.36.1  christos   CFLAGS += -fpic
    166  1.1.1.1.36.1  christos endif
    167  1.1.1.1.36.1  christos 
    168  1.1.1.1.36.1  christos ifeq (FreeBSD, $(findstring FreeBSD, $(OS)))
    169  1.1.1.1.36.1  christos CFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
    170  1.1.1.1.36.1  christos            -fshort-wchar -fno-strict-aliasing \
    171  1.1.1.1.36.1  christos            -ffreestanding -fno-stack-protector
    172  1.1.1.1.36.1  christos else
    173  1.1.1.1.36.1  christos CFLAGS  += $(ARCH3264) -g -O2 -Wall -Wextra -Werror \
    174  1.1.1.1.36.1  christos            -fshort-wchar -fno-strict-aliasing \
    175  1.1.1.1.36.1  christos 	   -ffreestanding -fno-stack-protector -fno-stack-check \
    176  1.1.1.1.36.1  christos            -fno-stack-check \
    177  1.1.1.1.36.1  christos            $(if $(findstring gcc,$(CC)),-fno-merge-all-constants,)
    178  1.1.1.1.36.1  christos endif
    179  1.1.1.1.36.1  christos 
    180  1.1.1.1.36.1  christos ARFLAGS := rDv
    181           1.1  jakllsch ASFLAGS += $(ARCH3264)
    182  1.1.1.1.36.1  christos LDFLAGS	+= -nostdlib --warn-common --no-undefined --fatal-warnings \
    183  1.1.1.1.36.1  christos 	   --build-id=sha1
    184