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     ifneq ($(host_toolchain_header),)
     76         MY_CFLAGS += -isystem $(host_toolchain_header)
     77     endif
     78     MY_CFLAGS += -isysroot $(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version) -DMACOSX_DEPLOYMENT_TARGET=$(mac_sdk_version)
     79     MY_LDLIBS += -isysroot $(mac_sdk_root) -Wl,-syslibroot,$(mac_sdk_root) -mmacosx-version-min=$(mac_sdk_version)
     80 
     81 endif
     82 
     83 # Some CFLAGS below use -Wno-missing-field-initializers but this is not
     84 # supported on GCC 3.x which is still present under Cygwin.
     85 # Find out by probing GCC for support of this flag. Note that the test
     86 # itself only works on GCC 4.x anyway.
     87 GCC_W_NO_MISSING_FIELD_INITIALIZERS := -Wno-missing-field-initializers
     88 ifeq ($(HOST_OS),windows)
     89     ifeq (,$(shell gcc -Q --help=warnings 2>/dev/null | grep missing-field-initializers))
     90         $(info emulator: Ignoring unsupported GCC flag $(GCC_W_NO_MISSING_FIELD_INITIALIZERS))
     91         GCC_W_NO_MISSING_FIELD_INITIALIZERS :=
     92     endif
     93 endif
     94 
     95 # BUILD_STANDALONE_EMULATOR is only defined when building with
     96 # the android-rebuild.sh script. The script will also provide
     97 # adequate values for HOST_CC
     98 #
     99 ifneq ($(BUILD_STANDALONE_EMULATOR),true)
    100   # On Linux, use our custom 32-bit host toolchain (unless BUILD_HOST_64bit=1)
    101   # which contains the relevant headers and 32-bit libraries for audio (The host 64-bit
    102   # Lucid doesn't provide these anymore, only their 64-bit versions).
    103   ifeq ($(HOST_OS),linux)
    104     HOST_SDK_TOOLCHAIN_PREFIX := prebuilts/tools/gcc-sdk
    105     # Don't do anything if the toolchain is not there
    106     ifneq (,$(strip $(wildcard $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc)))
    107       MY_CC  := $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc
    108       MY_CXX := $(HOST_SDK_TOOLCHAIN_PREFIX)/g++
    109       MY_AR  := $(HOST_SDK_TOOLCHAIN_PREFIX)/ar
    110     endif # $(HOST_SDK_TOOLCHAIN_PREFIX)/gcc exists
    111   endif # HOST_OS == linux
    112 
    113   ifneq ($(USE_CCACHE),)
    114     ccache := prebuilts/misc/$(HOST_PREBUILT_TAG)/ccache/ccache
    115     ccache := $(strip $(wildcard $(ccache)))
    116     ifneq ($(ccache),$(firstword $(MY_CC)))
    117       MY_CC := $(ccache) $(MY_CC)
    118       MY_CXX := $(ccache) $(MY_CXX)
    119     endif
    120     ccache :=
    121   endif
    122 
    123   QEMU_OPENGLES_INCLUDE := sdk/emulator/opengl/host/include
    124   QEMU_OPENGLES_LIBS := $(HOST_OUT)
    125 endif
    126 
    127 
    128 ifneq ($(combo_target)$(TARGET_SIMULATOR),HOST_true)
    129   ifneq ($(BUILD_HOST_64bit),)
    130     MY_CFLAGS += -m64
    131     MY_LDLIBS += -m64
    132   else
    133     ifneq ($(HOST_ARCH),x86_64)
    134       MY_CFLAGS += -m32
    135       MY_LDLIBS += -m32
    136     endif
    137   endif
    138 
    139   ifneq ($(BUILD_HOST_static),)
    140     MY_LDLIBS += -static
    141   endif
    142 endif
    143 
    144 # Enable warning, except those related to missing field initializers
    145 # (the QEMU coding style loves using these).
    146 #
    147 MY_CFLAGS += -Wall $(GCC_W_NO_MISSING_FIELD_INITIALIZERS)
    148 
    149 # Needed to build fpu/softfloat-native.h properly
    150 MY_CFLAGS += -D_GNU_SOURCE=1
    151 
    152 # A useful function that can be used to start the declaration of a host
    153 # module. Avoids repeating the same stuff again and again.
    154 # Usage:
    155 #
    156 #  $(call start-emulator-library, <module-name>)
    157 #
    158 #  ... declarations
    159 #
    160 #  $(call end-emulator-library)
    161 #
    162 start-emulator-library = \
    163     $(eval include $(CLEAR_VARS)) \
    164     $(eval LOCAL_NO_DEFAULT_COMPILER_FLAGS := true) \
    165     $(eval LOCAL_CC := $(MY_CC)) \
    166     $(eval LOCAL_CXX := $(MY_CXX)) \
    167     $(eval LOCAL_CFLAGS := $(MY_CFLAGS)) \
    168     $(eval LOCAL_AR := $(MY_AR)) \
    169     $(eval LOCAL_LDLIBS := $(MY_LDLIBS)) \
    170     $(eval LOCAL_MODULE := $1) \
    171     $(eval LOCAL_MODULE_CLASS := STATIC_LIBRARIES)
    172 
    173 # Used with start-emulator-library
    174 end-emulator-library = \
    175     $(eval include $(BUILD_HOST_STATIC_LIBRARY))
    176 
    177 # A variant of start-emulator-library to start the definition of a host
    178 # program instead. Use with end-emulator-program
    179 start-emulator-program = \
    180     $(call start-emulator-library,$1) \
    181     $(eval LOCAL_MODULE_CLASS := EXECUTABLES)
    182 
    183 # A varient of end-emulator-library for host programs instead
    184 end-emulator-program = \
    185     $(eval LOCAL_LDLIBS += $(QEMU_SYSTEM_LDLIBS)) \
    186     $(eval include $(BUILD_HOST_EXECUTABLE))
    187 
    188 
    189 # The common libraries
    190 #
    191 QEMU_SYSTEM_LDLIBS := -lm
    192 ifeq ($(HOST_OS),windows)
    193   QEMU_SYSTEM_LDLIBS += -mno-cygwin -mwindows -mconsole
    194 endif
    195 
    196 ifeq ($(HOST_OS),freebsd)
    197     QEMU_SYSTEM_LDLIBS += -L/usr/local/lib -lpthread -lX11 -lutil
    198 endif
    199 
    200 ifeq ($(HOST_OS),linux)
    201   QEMU_SYSTEM_LDLIBS += -lutil -lrt
    202 endif
    203 
    204 ifeq ($(HOST_OS),windows)
    205   # amd64-mingw32msvc- toolchain still name it ws2_32.  May change it once amd64-mingw32msvc-
    206   # is stabilized
    207   QEMU_SYSTEM_LDLIBS += -lwinmm -lws2_32 -liphlpapi
    208 else
    209   QEMU_SYSTEM_LDLIBS += -lpthread
    210 endif
    211 
    212 ifeq ($(HOST_OS),darwin)
    213   QEMU_SYSTEM_LDLIBS += -Wl,-framework,Cocoa,-framework,QTKit,-framework,CoreVideo
    214 
    215   # SDK 10.6+ doesn't have __dyld_func_lookup anymore. Dynamic library lookup symbols
    216   # are instead resolved at runtime
    217   OSX_VERSION_MAJOR := $(shell echo $(mac_sdk_version) | cut -d . -f 2)
    218   OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6 := $(shell [ $(OSX_VERSION_MAJOR) -ge 6 ] && echo true)
    219   ifeq ($(OSX_VERSION_MAJOR_GREATER_THAN_OR_EQUAL_TO_6),true)
    220     QEMU_SYSTEM_LDLIBS += -undefined dynamic_lookup
    221   endif
    222 endif
    223 
    224 include $(LOCAL_PATH)/Makefile.common
    225 
    226 ifeq ($(HOST_OS),windows)
    227   # on Windows, link the icon file as well into the executable
    228   # unfortunately, our build system doesn't help us much, so we need
    229   # to use some weird pathnames to make this work...
    230 
    231   # Locate windres executable
    232   WINDRES := windres
    233   ifneq ($(USE_MINGW),)
    234     # When building the Windows emulator under Linux, use the MinGW one
    235     WINDRES := i586-mingw32msvc-windres
    236   endif
    237 
    238   # Usage: $(eval $(call insert-windows-icon))
    239   define insert-windows-icon
    240     LOCAL_PREBUILT_OBJ_FILES += images/emulator_icon.o
    241   endef
    242 
    243 # This seems to be the only way to add an object file that was not generated from
    244 # a C/C++/Java source file to our build system. and very unfortunately,
    245 # $(TOPDIR)/$(LOCALPATH) will always be prepended to this value, which forces
    246 # us to put the object file in the source directory.
    247 $(LOCAL_PATH)/images/emulator_icon.o: $(LOCAL_PATH)/images/android_icon.rc
    248 	$(WINDRES) $< -I $(LOCAL_PATH)/images -o $@
    249 endif
    250 
    251 # We want to build all variants of the emulator binaries. This makes
    252 # it easier to catch target-specific regressions during emulator development.
    253 EMULATOR_TARGET_ARCH := arm
    254 include $(LOCAL_PATH)/Makefile.target
    255 
    256 EMULATOR_TARGET_ARCH := x86
    257 include $(LOCAL_PATH)/Makefile.target
    258 
    259 EMULATOR_TARGET_ARCH := mips
    260 include $(LOCAL_PATH)/Makefile.target
    261 
    262 ##############################################################################
    263 ##############################################################################
    264 ###
    265 ###  emulator: LAUNCHER FOR TARGET-SPECIFIC EMULATOR
    266 ###
    267 ###
    268 $(call start-emulator-program, emulator)
    269 
    270 LOCAL_SRC_FILES := android/main-emulator.c
    271 LOCAL_STATIC_LIBRARIES := emulator-common
    272 
    273 ifeq ($(HOST_OS),windows)
    274 $(eval $(call insert-windows-icon))
    275 endif
    276 
    277 $(call end-emulator-program)
    278 
    279 ##############################################################################
    280 ##############################################################################
    281 ###
    282 ###  emulator-ui: UI FRONT-END PROGRAM
    283 ###
    284 ###
    285 $(call start-emulator-program, emulator-ui)
    286 
    287 LOCAL_STATIC_LIBRARIES := \
    288     emulator-common \
    289     emulator-libui \
    290     emulator-common \
    291 
    292 LOCAL_CFLAGS += -DCONFIG_STANDALONE_UI=1
    293 
    294 LOCAL_CFLAGS += $(EMULATOR_COMMON_CFLAGS) $(EMULATOR_LIBUI_CFLAGS)
    295 LOCAL_LDLIBS += $(EMULATOR_COMMON_LDLIBS) $(EMULATOR_LIBUI_LDLIBS)
    296 
    297 LOCAL_SRC_FILES := \
    298     android/cmdline-option.c \
    299     android/config.c \
    300     android/help.c \
    301     android/looper-generic.c \
    302     android/snapshot.c \
    303     android/main-common.c \
    304     android/main.c \
    305     android/opengles.c \
    306     android/utils/setenv.c \
    307     vl-android-ui.c \
    308     android/protocol/core-connection.c \
    309     android/protocol/attach-ui-impl.c \
    310     android/protocol/fb-updates-impl.c \
    311     android/protocol/ui-commands-impl.c \
    312     android/protocol/core-commands-proxy.c \
    313     android/protocol/user-events-proxy.c \
    314 
    315 $(call gen-hw-config-defs,android/main-common.c)
    316 
    317 LOCAL_SRC_FILES += $(SDLMAIN_SOURCES)
    318 
    319 LOCAL_STATIC_LIBRARIES += $(SDL_STATIC_LIBRARIES)
    320 
    321 $(call end-emulator-program)
    322 
    323 ## VOILA!!
    324 
    325 endif  # TARGET_ARCH == arm || TARGET_ARCH == x86 || TARGET_ARCH == mips
    326 endif  # BUILD_EMULATOR == true || BUILD_STANDALONE_EMULATOR == true
    327