Makefile.kmk revision 61629542b22048ae51d3152ea3babb52a9075f19
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# The Recompiler Makefile.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# There are a few of complicating factors here, esp. on AMD64 systems:
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# * op.c doesn't compile work correctly with gcc 4. For this we've
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# checked in op.S, which is the reason why we don't compile op.c
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# directly but always compile via the assembly file.s
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# * On 64-bit Windows we lack a compiler and have to resort to a
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# linux cross compiler building an ELF relocatable module which
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# we then load using a wrapper module. Thus the REM_MOD mess.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# * On platforms using the 64-bit GCC ABI, we're not allowed to
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# generate non-PIC shared objects, and op.c requires the code
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# to be non-PIC. We apply the same trick as we developed for
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# 64-bit windows.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# Copyright (C) 2006 InnoTek Systemberatung GmbH
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# This file is part of VirtualBox Open Source Edition (OSE), as
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# available from http://www.virtualbox.org. This file is free software;
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# you can redistribute it and/or modify it under the terms of the GNU
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# General Public License as published by the Free Software Foundation,
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# in version 2 as it comes in the "COPYING" file of the VirtualBox OSE
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# distribution. VirtualBox OSE is distributed in the hope that it will
21dcdac963f79c098a5ea1a2c5c5e109429c9786Brendan Miller# be useful, but WITHOUT ANY WARRANTY of any kind.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# If you received this file as part of a commercial VirtualBox
21dcdac963f79c098a5ea1a2c5c5e109429c9786Brendan Miller# distribution, then only the terms of your commercial VirtualBox
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# license agreement apply instead of the previous paragraph.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan MmillerDEPTH = ../../..
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerinclude $(PATH_KBUILD)/header.kmk
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# todo this is a BUILD_PLATFORM binary, to a target binary!
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan MmillerBLDPROGS = dyngen
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerifeq ($(BUILD_TARGET_ARCH),amd64)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller SYSMODS = VBoxREM2
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller REM_MOD = VBoxREM2
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller REM_MOD = VBoxREM
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan MmillerDLLS = VBoxREM
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan MmillerIMPORT_LIBS = VBoxREMImp
47191265a0ac73f0ac0db0330969ce6920adaa1fBrendan MillerOTHER_CLEAN = \
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller $(PATH_$(REM_MOD))/op.h \
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller $(PATH_$(REM_MOD))/opc.h \
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller $(PATH_$(REM_MOD))/gen-op.h \
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller $(PATH_$(REM_MOD))/opc.h
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# A private hack for gcc 4.1 - no longer required. gcc 4.1.1 works fine for everything.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller#ifeq ($(USERNAME).$(BUILD_TARGET),bird.linux)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# TOOL_GCC3_CC = gcc-3.4.6
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# TOOL_GCC3_CXX = gcc-3.4.6
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# TOOL_GCC3_LD = g++-3.4.6
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# override VBOX_GCC_Wno-variadic-macros=
641b861c668fdb84b7ed44966216b36863ffb608Brendan Mmiller# override VBOX_USING_GCC4=
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# L4 must use the no-crt path because it's lacking math stuff it seems...
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# Darwin must use the non-crt path because it can't compile op.c nativly.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# All the AMD64 target must use the no-crt path because ELF doesn't like op.c
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# when stuffed into a shared library and windows doesn't have 64-bit gcc (yet).
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerifeq ($(filter-out l4 darwin freebsd,$(BUILD_TARGET)),)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller REM_USE_NOCRT := 1
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerifeq ($(BUILD_TARGET_ARCH),amd64)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller REM_USE_NOCRT := 1
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# The dyngen build tool.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerifeq ($(BUILD_PLATFORM),win)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller dyngen_TOOL = MINGW32
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller dyngen_SDKS = W32API
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller # On 64-bit Windows we pretend to be 32-bit.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller dyngen_BLD_TRG_ARCH = x86
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller dyngen_BLD_TRG_CPU = i386
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller dyngen_CFLAGS = -Wall -g -fno-strict-aliasing
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller ifeq ($(BUILD_TARGET_ARCH),amd64)
0c3f79f75f596c8d6700b2de830000f754bb28a9Phill Cunnington dyngen_DEFS += HOST_X86_64=1
21dcdac963f79c098a5ea1a2c5c5e109429c9786Brendan Miller dyngen_TEMPLATE = VBOXBLDPROG
21dcdac963f79c098a5ea1a2c5c5e109429c9786Brendan Millerdyngen_INCS = \
0c3f79f75f596c8d6700b2de830000f754bb28a9Phill Cunnington target-i386 \
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerdyngen_SOURCES = dyngen.c
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller# The VBoxREM.[dll|so|..] or VBoxREM2.rel.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller$(REM_MOD)_DEFS = IN_REM_R3 REM_INCLUDE_CPU_H
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller#$(REM_MOD)_DEFS += DEBUG_ALL_LOGGING DEBUG_DISAS DEBUG_PCALL DEBUG_EXEC DEBUG_FLUSH DEBUG_IOPORT DEBUG_SIGNAL DEBUG_TLB_CHECK DEBUG_TB_INVALIDATE DEBUG_TLB # Enables huge amounts of debug logging.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller$(REM_MOD)_INCS = \
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller target-i386 \
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller $(PATH_$(REM_MOD)) \
47191265a0ac73f0ac0db0330969ce6920adaa1fBrendan Miller$(REM_MOD)_SOURCES = \
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerifeq ($(filter-out win os2,$(BUILD_TARGET)),)
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller $(REM_MOD)_SOURCES += target-i386/op.c
641b861c668fdb84b7ed44966216b36863ffb608Brendan Mmiller FILE_OP_OBJ = $(PATH_$(REM_MOD)_target-i386/op.c)/op.o
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmillerelse # The remaining targets can be using gcc-4 and needs checking.
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller $(REM_MOD)_SOURCES += $(PATH_$(REM_MOD))/op.S
932eacec6c157231777c9b1d1326c8ed1f0a8d99Brendan Mmiller FILE_OP_OBJ = $(PATH_$(REM_MOD)_$(PATH_$(REM_MOD))/op.S)/op.o
$(REM_MOD)_CLEAN = $(FILE_OP_OBJ) $(PATH_$(REM_MOD))/op.S.dep
$(REM_MOD)_SOURCES.os2 = $(REM_MOD).def
$(REM_MOD)_SOURCES.win.x86 = $(REM_MOD).def
$(REM_MOD)_CFLAGS.amd64 = -O2
$(REM_MOD)_CFLAGS.debug = -O0
$(REM_MOD)_CFLAGS.darwin = -fno-common -mdynamic-no-pic
$(REM_MOD)_CFLAGS.release+= -fomit-frame-pointer -fno-gcse
InnoTek/e_powl-$(BUILD_TARGET_ARCH).S
$(REM_MOD)_LIBS.darwin = \
# $(PATH_BIN)/VBoxREMImp.dylib
$(REM_MOD)_LDFLAGS.darwin = -read_only_relocs suppress -multiply_defined warning #-install_name @executable_path/$(REM_MOD).dylib#
$(REM_MOD)_TOOL.win.x86 = MINGW32
$(REM_MOD)_TOOL.win.amd64 = XGCCAMD64LINUX
$(REM_MOD)_SDKS.win.x86 = W32API ## @todo do we really need this now?
$(REM_MOD)_CFLAGS.debug = -O0
$(REM_MOD)_CFLAGS.release += -fomit-frame-pointer -fno-gcse
$(REM_MOD)_CFLAGS.l4 = -nostdinc
#$(REM_MOD)_DEFS += DEBUG_DISAS DEBUG_PCALL DEBUG_EXEC DEBUG_FLUSH DEBUG_IOPORT DEBUG_SIGNAL DEBUG_TLB_CHECK DEBUG_TB_INVALIDATE DEBUG_TLB # Enables huge amounts of debug logging.
$(REM_MOD)_LDFLAGS.darwin = -read_only_relocs suppress -install_name @executable_path/$(REM_MOD).dylib -multiple_defined warning
$(REM_MOD)_LIBS.win.x86 = \
$(REM_MOD)_LIBS.linux = \
$(REM_MOD)_LIBS.l4 = \
$(L4_LIBDIR)/libvboxserver.s.so \
$(L4_LIBDIR)/libdl.s.so \
$(L4_LIBDIR)/libuc.0.s.so
target-i386/op.c_CFLAGS = -O2 -fno-strict-aliasing -fomit-frame-pointer -falign-functions=0 -fno-reorder-blocks -fno-optimize-sibling-calls
target-i386/op.c_CFLAGS.x86 = -fno-gcse -fno-instrument-functions -mpreferred-stack-boundary=2
target-i386/op.c_CFLAGS.darwin.x86 = -m128bit-long-double -mpreferred-stack-boundary=4 ## @todo This means we can't use staged/op-elf-x86.s...
target-i386/helper.c_CFLAGS.x86 = -O2 -fomit-frame-pointer -fno-strict-aliasing -fno-gcse
cpu-exec.c_CFLAGS.x86 = -O2 -fomit-frame-pointer -fno-strict-aliasing -fno-gcse
testmath_TOOL.win.x86 = MINGW32
testmath_SDKS.win.x86 = W32API
ifeq ($(BUILD_PLATFORM).$(BUILD_PLATFORM_ARCH),win.amd64)
testmath_ASFLAGS.amd64 = -m amd64
testmath_CFLAGS.release = -O3
testmath_SOURCES = InnoTek/testmath.c
VBoxREMImp_SOURCES = $(PATH_TARGET)/VBoxREMImp.c
VBoxREMImp_CLEAN = $(PATH_TARGET)/VBoxREMImp.c
VBoxREM.def > $@.tmp
include $(PATH_KBUILD)/footer.kmk
# Generate the op.S file somehow...
# Add something like VBOX_RECOMPILER_OP_GCC = gcc-3.4.6 to LocalConfig.kmk
# to be 100% sure that you get a working op.S. My gcc 4.1.1 seems to work
# The op-undefined.lst is generated by finding all the undefined symbols
# in one (or more) ELF op.o files using nm.
ifeq ($(USERNAME).$(BUILD_TARGET),bird.linux)
ifeq ($(BUILD_TARGET).$(BUILD_TARGET_ARCH),darwin.x86)
VBOX_RECOMPILER_OP_GCC_INCS ?= $(abspath $(dir $(shell LC_ALL=C $(VBOX_RECOMPILER_OP_GCC) -print-libgcc-file-name)))/include
# The command sans -o op.S.tmp.
$($(REM_MOD)_CFLAGS) $($(REM_MOD)_CFLAGS.$(BUILD_TYPE)) $($(REM_MOD)_CFLAGS.$(BUILD_TARGET)) $($(REM_MOD)_CFLAGS.$(BUILD_TARGET_ARCH)) $($(REM_MOD)_CFLAGS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
$(target-i386/op.c_CFLAGS) $(target-i386/op.c_CFLAGS.$(BUILD_TARGET)) $(target-i386/op.c_CFLAGS.$(BUILD_TARGET_ARCH)) $(target-i386/op.c_CFLAGS.$(BUILD_TARGET).$(BUILD_TARGET_ARCH)) \
$($(REM_MOD)_CINCS.$(BUILD_TARGET_ARCH)) $($(REM_MOD)_CINCS.$(BUILD_TARGET)) $($(REM_MOD)_CINCS) $(CINCS) \
$($(REM_MOD)_INCS.$(BUILD_TARGET_ARCH)) $($(REM_MOD)_INCS.$(BUILD_TARGET)) $($(REM_MOD)_INCS) $(INCS) \
$($(REM_MOD)_CDEFS.$(BUILD_TARGET_ARCH)) $($(REM_MOD)_CDEFS.$(BUILD_TARGET)) $($(REM_MOD)_CDEFS) $(CDEFS.$(BUILD_TARGET)) $(CDEFS.$(BUILD_TYPE)) $(CDEFS) \
$($(REM_MOD)_DEFS.$(BUILD_TARGET_ARCH)) $($(REM_MOD)_DEFS.$(BUILD_TARGET)) $($(REM_MOD)_DEFS) $(DEFS.$(BUILD_TARGET)) $(DEFS.$(BUILD_TYPE)) $(DEFS) \
-Wp,-MD,$(PATH_$(REM_MOD))/op.S.dep \
-Wp,-MT,$(PATH_$(REM_MOD))/op.S \
-include $(PATH_$(REM_MOD))/op.S.dep
$(PATH_$(REM_MOD))/op.S: \
staged/op-elf-$(BUILD_TARGET_ARCH).S \
major_ver=`$(VBOX_RECOMPILER_OP_GCC) --version | $(SED) -e '/GCC/!d' -e 's/^.* (GCC) \([2-9]\)\..*$$/\1/'`; \
$(ECHO_EXT) "Using staged op.S (gcc major ver $$major_ver)" && \
$(CP_EXT) -f staged/op-elf-$(BUILD_TARGET_ARCH).S $@.tmp; \
$(CP) staged/op-elf-$(BUILD_TARGET_ARCH).S $@.tmp
$(SED) -f op-validate.sed $@.tmp
$(SED) -f op-darwin.sed $@.tmp > $@.tmp2
$(SED) -e 's/^\(.*\)$$/#define \1 _\1/' op-undefined.lst > $@.tmp
DYNGEN = $(PATH_dyngen)/dyngen.exe
$(PATH_$(REM_MOD))/op.h: $(FILE_OP_OBJ) $(DYNGEN)
$(PATH_$(REM_MOD))/opc.h: $(FILE_OP_OBJ) $(DYNGEN)
$(PATH_$(REM_MOD))/gen-op.h: $(FILE_OP_OBJ) $(DYNGEN)