Home | History | Annotate | Download | only in qemu
      1 ifneq ($(filter true% %true,$(BUILD_EMULATOR)$(BUILD_STANDALONE_EMULATOR)),)
      2 
      3 ifneq (,$(filter $(TARGET_ARCH),arm x86 mips))
      4 LOCAL_PATH:= $(call my-dir)
      5 
      6 # determine the target cpu
      7 ifeq ($(TARGET_ARCH),arm)
      8 EMULATOR_TARGET_CPU := target-arm
      9 endif
     10 ifeq ($(TARGET_ARCH),x86)
     11 EMULATOR_TARGET_CPU := target-i386
     12 endif
     13 ifeq ($(TARGET_ARCH),mips)
     14 EMULATOR_TARGET_CPU := target-mips
     15 endif
     16 
     17 # determine the host tag to use
     18 QEMU_HOST_TAG := $(HOST_PREBUILT_TAG)
     19 ifneq ($(USE_MINGW),)
     20     QEMU_HOST_TAG := windows
     21 endif
     22 
     23 # determine the location of platform-specific directories
     24 #
     25 CONFIG_DIRS     := \
     26     $(LOCAL_PATH)/android/config/$(QEMU_HOST_TAG)
     27 
     28 ifeq ($(BUILD_STANDALONE_EMULATOR),true)
     29     CONFIG_DIRS := $(LOCAL_PATH)/objs $(CONFIG_DIRS)
     30 endif
     31 
     32 CONFIG_INCLUDES := $(CONFIG_DIRS:%=-I%)
     33 
     34 MY_CC  := $(HOST_CC)
     35 MY_CXX := $(HOST_CXX)
     36 MY_AR  := $(HOST_AR)
     37 
     38 MY_CFLAGS := $(CONFIG_INCLUDES) -O2 -g -fno-PIC -falign-functions=0 -fomit-frame-pointer
     39 
     40 # Overwrite configuration for debug builds.
     41 #
     42 ifeq ($(BUILD_DEBUG_EMULATOR),true)
     43     MY_CFLAGS := $(CONFIG_INCLUDES)
     44     MY_CFLAGS += -O0 -g
     45     MY_CFLAGS += -fno-PIC -falign-functions=0
     46 endif
     47 
     48 MY_LDLIBS :=
     49 
     50 ifeq ($(HOST_OS),freebsd)
     51   MY_CFLAGS += -I /usr/local/include
     52 endif
     53 
     54 ifeq ($(HOST_OS),windows)
     55   # we need Win32 features that are available since Windows 2000 Professional/Server (NT 5.0)
     56   MY_CFLAGS += -DWINVER=0x501
     57   MY_CFLAGS += -D_WIN32
     58   ifneq ($(BUILD_HOST_64bit),)
     59     # Microsoft 64-bit compiler define both _WIN32 and _WIN64
     60     MY_CFLAGS += -D_WIN64
     61     # amd64-mingw32msvc- toolchain still name it vfw32.  May change it once amd64-mingw32msvc-
     62     # is stabilized
     63     MY_LDLIBS += -lvfw32
     64   else
     65     MY_LDLIBS += -lvfw32
     66   endif
     67 endif
     68 
     69 ifeq ($(HOST_ARCH),ppc)
     70     MY_CFLAGS += -D__powerpc__
     71 endif
     72 
     73 ifeq ($(HOST_OS),darwin)
     74     MY_CFLAGS += -mdynamic-no-pic -D_DARWIN_C_SOURCE=1
     75 
     76     MY_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version)
     77     MY_LDLIBS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
     78 
     79 endif
     80 
     81 # BUILD_STANDALONE_EMULATOR is only defined when building with
     82 # the android-rebuild.sh script. The script will also provide
     83 # adequate values for HOST_CC
     84 #
     85 ifneq ($(BUILD_STANDALONE_EMULATOR),true)
     86   # On Linux, use our custom 32-bit host toolchain (unless BUILD_HOST_64bit=1)
     87   # which contains the relevant headers and 32-bit libraries for audio (The host 64-bit
     88   # Lucid doesn't provide these anymore, only their 64-bit versions).
     89   ifeq ($(HOST_OS),linux)
     90     HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk
     91     # Don't do anything if the toolchain is not there
     92     ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc)))
     93       MY_CC  := $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc
     94       MY_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)/g++
     95       MY_AR  := $(HOST_SDK_TOOLCHAIN_PREFIX)/ar
     96     endif # $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc exists
     97   endif # HOST_OS == linux
     98 
     99   ifneq ($(USE_CCACHE),)
    100     ccache := prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
    101     ccache := $(strip $(wildcard $(ccache)))
    102     ifneq ($(ccache),$(firstword $(MY_CC)))
    103       MY_CC := $(ccache) $(MY_CC)
    104       MY_CXX := $(ccache) $(MY_CXX)
    105     endif
    106     ccache :=
    107   endif
    108 
    109   QEMU_OPENGLES_INCLUDE := sdk/emulator/opengl/host/include
    110   QEMU_OPENGLES_LIBS := $(HOST_OUT)
    111 endif
    112 
    113 
    114 ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true)
    115   ifneq ($(BUILD_HOST_64bit),)
    116     MY_CFLAGS += -m64
    117     MY_LDLIBS += -m64
    118   else
    119     ifneq ($(HOST_ARCH),x86_64)
    120       MY_CFLAGS += -m32
    121       MY_LDLIBS += -m32
    122     endif
    123   endif
    124 
    125   ifneq ($(BUILD_HOST_static),)
    126     MY_LDLIBS += -static
    127   endif
    128 endif
    129 
    130 # Enable warning, except those related to missing field initializers
    131 # (the QEMU coding style loves using these).
    132 #
    133 MY_CFLAGS += -Wall -Wno-missing-field-initializers
    134 
    135 # Needed to build fpu/softfloat-native.h properly
    136 MY_CFLAGS += -D_GNU_SOURCE=1
    137 
    138 # A useful function that can be used to start the declaration of a host
    139 # module. Avoids repeating the same stuff again and again.
    140 # Usage:
    141 #
    142 #  $(call start-emulator-library, <module-name>)
    143 #
    144 #  ... declarations
    145 #
    146 #  $(call end-emulator-library)
    147 #
    148 start-emulator-library = \
    149     $(eval include $(CLEAR_VARS)) \
    150     $(eval LOCAL_NO_DEFAULT_COMPILER_FLAGS := true) \
    151     $(eval LOCAL_CC := $(MY_CC)) \
    152     $(eval LOCAL_CXX := $(MY_CXX)) \
    153     $(eval LOCAL_CFLAGS := $(MY_CFLAGS)) \
    154     $(eval LOCAL_AR := $(MY_AR)) \
    155     $(eval LOCAL_LDLIBS := $(MY_LDLIBS)) \
    156     $(eval LOCAL_MODULE := $1) \
    157     $(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES)
    158 
    159 # Used with start-emulator-library
    160 end-emulator-library = \
    161     $(eval include $(BUILD_HOST_STATIC_LIBRARY))
    162 
    163 # A variant of start-emulator-library to start the definition of a host
    164 # program instead. Use with end-emulator-program
    165 start-emulator-program = \
    166     $(call start-emulator-library,$1) \
    167     $(eval LOCAL_MODULE_CLASS := EXECUTABLES)
    168 
    169 # A varient of end-emulator-library for host programs instead
    170 end-emulator-program = \
    171     $(eval LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)) \
    172     $(eval include $(BUILD_HOST_EXECUTABLE))
    173 
    174 
    175 # The common libraries
    176 #
    177 QEMU_SYSTEM_LDLIBS := -lm
    178 ifeq ($(HOST_OS),windows)
    179   QEMU_SYSTEM_LDLIBS += -mno-cygwin -mwindows -mconsole
    180 endif
    181 
    182 ifeq ($(HOST_OS),freebsd)
    183     QEMU_SYSTEM_LDLIBS += -L/usr/local/lib -lpthread -lX11 -lutil
    184 endif
    185 
    186 ifeq ($(HOST_OS),linux)
    187   QEMU_SYSTEM_LDLIBS += -lutil -lrt
    188 endif
    189 
    190 ifeq ($(HOST_OS),windows)
    191   # amd64-mingw32msvc- toolchain still name it ws2_32.  May change it once amd64-mingw32msvc-
    192   # is stabilized
    193   QEMU_SYSTEM_LDLIBS += -lwinmm -lws2_32 -liphlpapi
    194 else
    195   QEMU_SYSTEM_LDLIBS += -lpthread
    196 endif
    197 
    198 ifeq ($(HOST_OS),darwin)
    199   QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo
    200 
    201   # SDK 10.6+ doesn't have __dyld_func_lookup anymore. Dynamic library lookup symbols
    202   # are instead resolved at runtime
    203   OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2)
    204   OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true)
    205   ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true)
    206     QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup
    207   endif
    208 endif
    209 
    210 include $(LOCAL_PATH)/Makefile.common
    211 
    212 ifeq ($(HOST_OS),windows)
    213   # on Windows, link the icon file as well into the executable
    214   # unfortunately, our build system doesn't help us much, so we need
    215   # to use some weird pathnames to make this work...
    216 
    217   # Locate windres executable
    218   WINDRES := windres
    219   ifneq ($(USE_MINGW),)
    220     # When building the Windows emulator under Linux, use the MinGW one
    221     WINDRES := i586-mingw32msvc-windres
    222   endif
    223 
    224   # Usage: $(eval $(call insert-windows-icon))
    225   define insert-windows-icon
    226     LOCAL_PREBUILT_OBJ_FILES += images/emulator_icon.o
    227   endef
    228 
    229 # This seems to be the only way to add an object file that was not generated from
    230 # a C/C++/Java source file to our build system. and very unfortunately,
    231 # $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces
    232 # us to put the object file in the source directory.
    233 $(LOCAL_PATH)/images/emulator_icon.o: $(LOCAL_PATH)/images/android_icon.rc
    234 	$(WINDRES) $< -I $(LOCAL_PATH)/images -o $@
    235 endif
    236 
    237 # We want to build all variants of the emulator binaries. This makes
    238 # it easier to catch target-specific regressions during emulator development.
    239 EMULATOR_TARGET_ARCH := arm
    240 include $(LOCAL_PATH)/Makefile.target
    241 
    242 EMULATOR_TARGET_ARCH := x86
    243 include $(LOCAL_PATH)/Makefile.target
    244 
    245 EMULATOR_TARGET_ARCH := mips
    246 include $(LOCAL_PATH)/Makefile.target
    247 
    248 ##############################################################################
    249 ##############################################################################
    250 ###
    251 ###  emulator: LAUNCHER FOR TARGET-SPECIFIC EMULATOR
    252 ###
    253 ###
    254 $(call start-emulator-program, emulator)
    255 
    256 LOCAL_SRC_FILES := android/main-emulator.c
    257 LOCAL_STATIC_LIBRARIES := emulator-common
    258 
    259 ifeq ($(HOST_OS),windows)
    260 $(eval $(call insert-windows-icon))
    261 endif
    262 
    263 $(call end-emulator-program)
    264 
    265 ##############################################################################
    266 ##############################################################################
    267 ###
    268 ###  emulator-ui: UI FRONT-END PROGRAM
    269 ###
    270 ###
    271 $(call start-emulator-program, emulator-ui)
    272 
    273 LOCAL_STATIC_LIBRARIES := \
    274     emulator-common \
    275     emulator-libui \
    276     emulator-common \
    277 
    278 LOCAL_CFLAGS += -DCONFIG_STANDALONE_UI=1
    279 
    280 LOCAL_CFLAGS += $(EMULATOR_COMMON_CFLAGS) $(EMULATOR_LIBUI_CFLAGS)
    281 LOCAL_LDLIBS += $(EMULATOR_COMMON_LDLIBS) $(EMULATOR_LIBUI_LDLIBS)
    282 
    283 LOCAL_SRC_FILES := \
    284     android/cmdline-option.c \
    285     android/config.c \
    286     android/help.c \
    287     android/looper-generic.c \
    288     android/snapshot.c \
    289     android/main-common.c \
    290     android/main.c \
    291     android/opengles.c \
    292     android/utils/setenv.c \
    293     vl-android-ui.c \
    294     android/protocol/core-connection.c \
    295     android/protocol/attach-ui-impl.c \
    296     android/protocol/fb-updates-impl.c \
    297     android/protocol/ui-commands-impl.c \
    298     android/protocol/core-commands-proxy.c \
    299     android/protocol/user-events-proxy.c \
    300 
    301 $(call gen-hw-config-defs,android/main-common.c)
    302 
    303 LOCAL_SRC_FILES += $(SDLMAIN_SOURCES)
    304 
    305 LOCAL_STATIC_LIBRARIES += $(SDL_STATIC_LIBRARIES)
    306 
    307 $(call end-emulator-program)
    308 
    309 ## VOILA!!
    310 
    311 endif  # TARGET_ARCH == arm || TARGET_ARCH == x86 || TARGET_ARCH == mips
    312 endif  # BUILD_EMULATOR == true || BUILD_STANDALONE_EMULATOR == true
    313