
# Makefile.config
#
# Common configuration and setup file to generate the ACPICA tools and
# utilities: the acpidump.
#
# This file is included by the individual makefiles for each tool.
#

#
# Note: This makefile is intended to be used from within the native
# ACPICA directory structure, from under generate/efi. It specifically
# places all object files in a generate/efi subdirectory, not within
# the various ACPICA source directories. This prevents collisions
# between different compilations of the same source file with different
# compile options, and prevents pollution of the source code.
#

#
# Configuration
#
# TARGET     Build target platform can be overridden on the make command
#            line by adding the following to the invocation:
#            TARGET="..."
#            Possible target (ia32, x86_64, etc.) can be used to initiate
#            a possible cross build.
# OPT_CFLAGS Optimization CFLAGS can be overridden on the make command
#            line by adding the following to the invocation:
#            OPT_CFLAGS="..."
#
# Notes:
#   gcc should be version 4 or greater, otherwise some of the options
#     used will not be recognized.
#

.SUFFIXES :

#
# Common defines
#
PROGS =  acpidump efihello
ACPI_HOST =   $(shell uname -m | sed s,i[3456789]86,ia32,)
TARGET = $(shell uname -m | sed s,i[3456789]86,ia32,)
OBJDIR = obj
BINDIR = bin

#
# Main ACPICA source directories
#
ACPICA_SRC =            ../../../source
ACPICA_COMMON =         $(ACPICA_SRC)/common
ACPICA_TOOLS =          $(ACPICA_SRC)/tools
ACPICA_OSL =            $(ACPICA_SRC)/os_specific/service_layers
ACPICA_EFI =            $(ACPICA_SRC)/os_specific/efi
ACPICA_CORE =           $(ACPICA_SRC)/components
ACPICA_INCLUDE =        $(ACPICA_SRC)/include
ACPICA_DEBUGGER =       $(ACPICA_CORE)/debugger
ACPICA_DISASSEMBLER =   $(ACPICA_CORE)/disassembler
ACPICA_DISPATCHER =     $(ACPICA_CORE)/dispatcher
ACPICA_EVENTS =         $(ACPICA_CORE)/events
ACPICA_EXECUTER =       $(ACPICA_CORE)/executer
ACPICA_HARDWARE =       $(ACPICA_CORE)/hardware
ACPICA_NAMESPACE =      $(ACPICA_CORE)/namespace
ACPICA_PARSER =         $(ACPICA_CORE)/parser
ACPICA_RESOURCES =      $(ACPICA_CORE)/resources
ACPICA_TABLES =         $(ACPICA_CORE)/tables
ACPICA_UTILITIES =      $(ACPICA_CORE)/utilities

#
# ACPICA tool and utility source directories
#
ACPIDUMP =              $(ACPICA_TOOLS)/acpidump
EFIHELLO =              $(ACPICA_TOOLS)/efihello

#
# Common ACPICA header files
#
ACPICA_HEADERS = \
	$(wildcard $(ACPICA_INCLUDE)/*.h) \
	$(wildcard $(ACPICA_INCLUDE)/platform/*.h)

#
# GCC configuration
#
CC =        gcc
LD =        ld
OBJCOPY =   objcopy

CFLAGS  = \
	--save-temps\
	-nostdinc\
	-nostdlib\
	-std=c99\
	-U__linux__\
	-U_LINUX\
	-D_GNU_EFI\
	-D_GNU_SOURCE\
	-fno-builtin\
	-iwithprefix include\
	-fno-stack-protector\
	-fno-strict-aliasing\
	-fpic\
	-fshort-wchar\
	-I$(ACPICA_INCLUDE)
LDFLAGS	= \
	-nostdinc\
	-nostdlib\
	-znocombreloc\
	-Bsymbolic\
	-shared\
	-no-undefined
OBJCOPYFLAGS = \
	-j .text\
	-j .sdata\
	-j .data\
	-j .dynamic\
	-j .dynsym\
	-j .rel\
	-j .rela\
	-j .reloc\
	--target=efi-app-$(TARGET)

#
# Common compiler flags
# The _GNU_SOURCE symbol is required for many hosts.
#
OPT_CFLAGS ?= $(CWARNINGFLAGS)

#
# Optionally disable optimizations. Optimization causes problems on
# some compilers such as gcc 4.4
#
ifneq ($(NOOPT),TRUE)
OPT_CFLAGS += -O2
endif

#
# Optionally disable fortify source. This option can cause
# compile errors in toolchains where it is already defined.
#
ifneq ($(NOFORTIFY),TRUE)
OPT_CFLAGS += -D_FORTIFY_SOURCE=2
endif


# Common compiler warning flags. The warning flags in addition
# to -Wall are not automatically included in -Wall.
#
CWARNINGFLAGS = \
	-Wall\
	-Wbad-function-cast\
	-Wdeclaration-after-statement\
	-Wformat=2\
	-Wmissing-declarations\
	-Wmissing-prototypes\
	-Wstrict-aliasing=0\
	-Wswitch-default\
	-Wpointer-arith\
	-Wempty-body\
	-Wlogical-op\
	-Wmissing-parameter-type\
	-Wold-style-declaration\
	-Wtype-limits

ifneq ($(NOWERROR),TRUE)
CWARNINGFLAGS += -Werror
endif

#
# Extra warning flags (for possible future use)
#
#CWARNINGFLAGS += \
#	-Wcast-qual\
#	-Wconversion\
#	-Wshadow\
#	-Wstrict-prototypes\
#	-Wundef\

CFLAGS += $(OPT_CFLAGS)

#
# EFI environment definitions
#
EFIINC =    /usr/include/efi

ifeq ($(TARGET),ia32)

CFLAGS +=   -DACPI_MACHINE_WIDTH=32
ifeq ($(ACPI_HOST),x86_64)
EFILIB =    /usr/lib32
CFLAGS +=   -m32
LDFLAGS	+=  -melf_i386
else # ACPI_HOST eq ia32
EFILIB =    /usr/lib
endif

else # TARGET eq x86_64

CFLAGS += \
	-DEFI_FUNCTION_WRAPPER\
	-DACPI_MACHINE_WIDTH=64
ifeq ($(ACPI_HOST),ia32)
EFILIB =    /usr/lib64
CFLAGS +=   -m64
LDFLAGS	+=  -melf_x86_64
else # ACPI_HOST eq x86_64
EFILIB =    /usr/lib
endif

endif

CFLAGS += \
	-I$(EFIINC)\
	-I$(EFIINC)/$(TARGET)\
	-I$(EFIINC)/protocol
LDFLAGS	+= \
	-T $(EFILIB)/elf_$(TARGET)_efi.lds\
	-L$(EFILIB)\
	$(EFILIB)/crt0-efi-$(TARGET).o
LIBS = \
	-lefi\
	-lgnuefi\
	$(shell $(CC) -print-libgcc-file-name)

#
# Bison/Flex configuration
#
# -y: act like yacc
#
# -i: generate case insensitive scanner
# -s: suppress default rule, abort on unknown input
#
# Optional for Bison/yacc:
# -v: verbose, produces a .output file
# -d: produces the defines header file
#
YACC=       bison
YFLAGS +=   -y

LEX=        flex
LFLAGS +=   -i -s

#
# Command definitions
#
COMPILEOBJ =    $(CC) -c $(CFLAGS) -o $@ $<
LINKPROG =      $(LD) $(LDFLAGS) $(OBJECTS) -o $@ $(LIBS)
OBJCOPYPROG =   $(OBJCOPY) $(OBJCOPYFLAGS) $< $@
COPYPROG = \
	@mkdir -p ../$(BINDIR); \
	cp -f $< ../$(BINDIR); \
	echo "Copied $< to $@";
