]> Shamusworld >> Repos - apple2/commitdiff
Added MXE cross compile script.
authorShamus Hammons <jlhamm@acm.org>
Fri, 11 Oct 2013 20:10:47 +0000 (15:10 -0500)
committerShamus Hammons <jlhamm@acm.org>
Fri, 11 Oct 2013 20:10:47 +0000 (15:10 -0500)
Makefile
cross-compile [new file with mode: 0755]
src/gui/gui.cpp
src/gui/gui.h

index 61658c57ec5b53516c200c8916edae43b830f984..0cbd42bfe2d86190c3789684b93f9e2ad5267661 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -7,10 +7,15 @@
 #
 
 FIND = find
+FINDSDL2 := $(shell which $(CROSS)sdl2-config 2> /dev/null)
 
 # Figure out which system we're compiling for, and set the appropriate variables
 
-ifeq "$(OSTYPE)" "msys"                                                        # Win32
+ifeq "$(CROSS)" ""
+OSTYPE   := $(shell uname -a)
+
+# Win32
+ifeq "$(findstring Msys,$(OSTYPE))" "Msys"
 
 SYSTYPE    = __GCCWIN32__
 EXESUFFIX  = .exe
@@ -18,9 +23,8 @@ ICON       = obj/icon.o
 SDLLIBTYPE = --libs
 MSG        = Win32 on MinGW
 
-else
-#ifeq "$(OSTYPE)" "darwin"
-ifeq "darwin" "$(findstring darwin,$(OSTYPE))" # Should catch both 'darwin' and 'darwin7.0'
+# Should catch both 'darwin' and 'darwin7.0'
+else ifeq "$(findstring Darwin,$(OSTYPE))" "Darwin"
 
 SYSTYPE    = __GCCUNIX__ -D_OSX_
 EXESUFFIX  =
@@ -28,7 +32,8 @@ ICON       =
 SDLLIBTYPE = --static-libs
 MSG        = Mac OS X
 
-else                                                                                   # *nix
+# *nix
+else ifeq "$(findstring Linux,$(OSTYPE))" "Linux"
 
 SYSTYPE    = __GCCUNIX__
 EXESUFFIX  =
@@ -36,13 +41,32 @@ ICON       =
 SDLLIBTYPE = --libs
 MSG        = generic Unix/Linux
 
+# Throw error, unknown OS
+else
+
+$(error OS TYPE UNDETECTED)
+
 endif
+# Cross compile using MXE under Linux host
+else
+
+SYSTYPE    = __GCCWIN32__
+EXESUFFIX  = .exe
+ICON       = obj/icon.o
+SDLLIBTYPE = --libs
+MSG        = Win32 under MXE (cross compile)
+
 endif
 
-CC         = gcc
-LD         = gcc
+CC         = $(CROSS)gcc
+LD         = $(CROSS)gcc
 TARGET     = apple2
 
+SDL_CFLAGS = `$(CROSS)sdl2-config --cflags`
+SDL_LIBS   = `$(CROSS)sdl2-config $(SDLLIBTYPE)`
+DEFINES    = -D$(SYSTYPE)
+GCC_DEPS   = -MMD
+
 # Note that we use optimization level 2 instead of 3--3 doesn't seem to gain much over 2
 #CFLAGS   = -MMD -Wall -Wno-switch -O2 -D$(SYSTYPE) -ffast-math -fomit-frame-pointer `sdl2-config --cflags`
 #CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -O2 -D$(SYSTYPE) \
@@ -52,12 +76,15 @@ TARGET     = apple2
 #CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -D$(SYSTYPE) \
 #              -ffast-math -fomit-frame-pointer `sdl2-config --cflags` -fprofile-arcs -ftest-coverage
 # No optimization for profiling with gprof...
-CFLAGS   = -MMD -Wall -Wno-switch -D$(SYSTYPE) \
-               -ffast-math `sdl2-config --cflags` -pg -g
-CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -D$(SYSTYPE) \
-               -ffast-math `sdl2-config --cflags` -pg -g
+#CFLAGS   = -MMD -Wall -Wno-switch -D$(SYSTYPE) \
+#              -ffast-math `sdl2-config --cflags` -pg -g
+#CPPFLAGS = -MMD -Wall -Wno-switch -Wno-non-virtual-dtor -D$(SYSTYPE) \
+#              -ffast-math `sdl2-config --cflags` -pg -g
 #              -fomit-frame-pointer `sdl2-config --cflags` -g
 #              -fomit-frame-pointer `sdl2-config --cflags` -DLOG_UNMAPPED_MEMORY_ACCESSES
+CFLAGS   = $(GCC_DEPS) -Wall -Wno-switch $(DEFINES) -ffast-math $(SDL_CFLAGS) -pg -g
+CPPFLAGS = $(GCC_DEPS) -Wall -Wno-switch -Wno-non-virtual-dtor $(DEFINES) \
+               -ffast-math $(SDL_CFLAGS) -pg -g
 
 LDFLAGS =
 
@@ -65,9 +92,11 @@ LDFLAGS =
 # Link in the gcov library (for profiling purposes)
 #LIBS = -L/usr/local/lib -L/usr/lib `sdl2-config $(SDLLIBTYPE)` -lstdc++ -lz $(GLLIB) -lgcov
 # Link in the gprof lib
-LIBS = -L/usr/local/lib -L/usr/lib `sdl2-config $(SDLLIBTYPE)` -lstdc++ -lz $(GLLIB) -pg
+#LIBS = -L/usr/local/lib -L/usr/lib `sdl2-config $(SDLLIBTYPE)` -lstdc++ -lz $(GLLIB) -pg
+LIBS = -L/usr/local/lib -L/usr/lib $(SDL_LIBS) -lstdc++ -lz $(GLLIB) -pg
 
-INCS = -I. -I./src -I/usr/local/include -I/usr/include
+#INCS = -I. -I./src -I/usr/local/include -I/usr/include
+INCS = -I. -I./src
 
 OBJS = \
        obj/button.o          \
@@ -107,15 +136,19 @@ all: checkenv message obj $(TARGET)$(EXESUFFIX)
 checkenv:
        @echo
        @echo -en "\033[01;33m***\033[00;32m Checking compilation environment... \033[00m"
-ifeq "" "$(shell which sdl2-config)"
+ifeq "$(FINDSDL2)" ""
        @echo
        @echo
-       @echo -e "\033[01;33mIt seems that you don't have the SDL 2 development libraries installed.
+       @echo -e "\033[01;33mIt seems that you don't have the SDL 2 development libraries installed. If you"
        @echo -e "have installed them, make sure that the sdl2-config file is somewhere in your"
        @echo -e "path and is executable.\033[00m"
        @echo
 #Is there a better way to break out of the makefile?
-       @break
+       @false;
+#      @break
+# YES! But ignores all the echo's above... :-/
+#$(error SDL2 MISSING)
+
 else
        @echo -e "\033[01;37mOK\033[00m"
 endif
@@ -139,7 +172,7 @@ obj:
 ifneq "" "$(ICON)"
 $(ICON): res/$(TARGET).rc res/$(TARGET).ico
        @echo -e "\033[01;33m***\033[00;32m Processing icon...\033[00m"
-       @windres -i res/$(TARGET).rc -o $(ICON) --include-dir=./res
+       @$(CROSS)windres -i res/$(TARGET).rc -o $(ICON) --include-dir=./res
 endif
 
 obj/%.o: src/%.c
diff --git a/cross-compile b/cross-compile
new file mode 100755 (executable)
index 0000000..517fc72
--- /dev/null
@@ -0,0 +1,21 @@
+#!/bin/bash
+#
+# Short script to do cross compilation with MXE on Linux
+#
+# by James Hammons
+# (C) 2012 Underground Software
+#
+export PATH=/opt/mxe/usr/bin:$PATH
+make CROSS=i686-pc-mingw32- clean  && make CROSS=i686-pc-mingw32-
+
+#TARGET = apple2
+#echo "Cross compiling $(TARGET) for Win32..."
+#export PATH=/opt/mxe/usr/bin:$PATH
+#rm Makefile
+#/opt/mxe/usr/i686-pc-mingw32/qt/bin/qmake
+#make clean && make
+#make CROSS=i686-pc-mingw32-
+#rel=`svn info | grep Revision | cut -f 2 -d ' '`
+#rel=`git log -1 --pretty=format:%ci | cut -d ' ' -f 1 | tr -d -`
+#cd release && upx -9v $(TARGET).exe && zip -9v $(TARGET)-$rel.zip $(TARGET).exe
+
index 12259c40555ca99fc5ae785886b973cbca7cbe6f..fb7176b7974bea181bd4f2070fa77e2462a0ca03 100644 (file)
@@ -538,8 +538,6 @@ GUI2::~GUI2(void)
 
 void GUI2::Init(SDL_Renderer * renderer)
 {
-//     overlay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
-//             SDL_TEXTUREACCESS_STREAMING, 128, 256);
        overlay = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
                SDL_TEXTUREACCESS_TARGET, 128, 380);
 
@@ -552,46 +550,21 @@ void GUI2::Init(SDL_Renderer * renderer)
        if (SDL_SetTextureBlendMode(overlay, SDL_BLENDMODE_BLEND) == -1)
                WriteLog("GUI: Could not set blend mode for overlay.\n");
 
-//     uint32_t * texturePointer = (uint32_t *)scrBuffer;
-
        for(uint32_t i=0; i<128*380; i++)
-               texturePointer[i] = 0xA0A000A0;
+               texturePointer[i] = 0xB0A000A0;
 
        SDL_UpdateTexture(overlay, NULL, texturePointer, 128 * sizeof(Uint32));
 
-//     olSrc.x = olSrc.y = 0;
-//     olSrc.w = 128;
-//     olSrc.h = 380;
        olDst.x = VIRTUAL_SCREEN_WIDTH;
        olDst.y = 2;
        olDst.w = 128;
        olDst.h = 380;
 
-       iconSelection = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
-               SDL_TEXTUREACCESS_STATIC, 54, 54);
-       disk1Icon = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
-               SDL_TEXTUREACCESS_STATIC, 40, 40);
-       disk2Icon = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
-               SDL_TEXTUREACCESS_STATIC, 40, 40);
-       powerOffIcon = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
-               SDL_TEXTUREACCESS_STATIC, 40, 40);
-       powerOnIcon = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
-               SDL_TEXTUREACCESS_STATIC, 40, 40);
-       SDL_SetTextureBlendMode(iconSelection, SDL_BLENDMODE_BLEND);
-       SDL_SetTextureBlendMode(disk1Icon, SDL_BLENDMODE_BLEND);
-       SDL_SetTextureBlendMode(disk2Icon, SDL_BLENDMODE_BLEND);
-       SDL_SetTextureBlendMode(powerOffIcon, SDL_BLENDMODE_BLEND);
-       SDL_SetTextureBlendMode(powerOnIcon, SDL_BLENDMODE_BLEND);
-       Bitmap * bm1 = (Bitmap *)((void *)&icon_selection);
-       SDL_UpdateTexture(iconSelection, NULL, (Uint32 *)bm1->pixelData, 54 * sizeof(Uint32));
-       bm1 = (Bitmap *)((void *)&disk_1);
-       SDL_UpdateTexture(disk1Icon, NULL, (Uint32 *)bm1->pixelData, 40 * sizeof(Uint32));
-       bm1 = (Bitmap *)((void *)&disk_2);
-       SDL_UpdateTexture(disk2Icon, NULL, (Uint32 *)bm1->pixelData, 40 * sizeof(Uint32));
-       bm1 = (Bitmap *)((void *)&power_off);
-       SDL_UpdateTexture(powerOffIcon, NULL, (Uint32 *)bm1->pixelData, 40 * sizeof(Uint32));
-       bm1 = (Bitmap *)((void *)&power_on);
-       SDL_UpdateTexture(powerOnIcon, NULL, (Uint32 *)bm1->pixelData, 40 * sizeof(Uint32));
+       iconSelection = CreateTexture(renderer, &icon_selection);
+       disk1Icon     = CreateTexture(renderer, &disk_1);
+       disk2Icon     = CreateTexture(renderer, &disk_2);
+       powerOffIcon  = CreateTexture(renderer, &power_off);
+       powerOnIcon   = CreateTexture(renderer, &power_on);
 
        if (SDL_SetRenderTarget(renderer, overlay) < 0)
        {
@@ -599,18 +572,7 @@ void GUI2::Init(SDL_Renderer * renderer)
        }
        else
        {
-               SDL_Texture * icons[7] = { powerOnIcon, disk1Icon, disk2Icon, powerOffIcon, powerOffIcon, powerOffIcon, powerOffIcon };
-               SDL_Rect dst;
-               dst.w = dst.h = 40;
-               dst.x = 24;
-               dst.y = 2 + 7;
-
-               for(int i=0; i<7; i++)
-               {
-                       SDL_RenderCopy(renderer, icons[i], NULL, &dst);
-                       dst.y += 54;
-               }
-
+               DrawSidebarIcons(renderer);
                // Set render target back to default
                SDL_SetRenderTarget(renderer, NULL);
        }
@@ -619,6 +581,19 @@ void GUI2::Init(SDL_Renderer * renderer)
 }
 
 
+SDL_Texture * GUI2::CreateTexture(SDL_Renderer * renderer, const void * source)
+{
+       Bitmap * bitmap = (Bitmap *)source;
+       SDL_Texture * texture = SDL_CreateTexture(renderer, SDL_PIXELFORMAT_ABGR8888,
+               SDL_TEXTUREACCESS_STATIC, bitmap->width, bitmap->height);
+       SDL_SetTextureBlendMode(texture, SDL_BLENDMODE_BLEND);
+       SDL_UpdateTexture(texture, NULL, (Uint32 *)bitmap->pixelData,
+               bitmap->width * sizeof(Uint32));
+
+       return texture;
+}
+
+
 void GUI2::MouseDown(int32_t x, int32_t y, uint32_t buttons)
 {
 }
@@ -652,11 +627,9 @@ void GUI2::MouseMove(int32_t x, int32_t y, uint32_t buttons)
        {
                if (x < (VIRTUAL_SCREEN_WIDTH - 100))
                {
-                       iconSelected = -1;
-                       lastIconSelected = -1;
+                       iconSelected = lastIconSelected = -1;
                        HandleIconSelection(sdlRenderer);
 //printf("GUI: sidebar hiding[2] (x = %i)...\n", x);
-//                     sidebarOut = false;
                        sidebarState = SBS_HIDING;
                        dx = 8;
                }
@@ -664,12 +637,12 @@ void GUI2::MouseMove(int32_t x, int32_t y, uint32_t buttons)
                // something!
                else
                {
-                       if (y < 3 || y > 382)
+                       if (y < 4 || y > 383)
                        {
                                iconSelected = -1;
                        }
                        else
-                               iconSelected = (y - 2) / 54;
+                               iconSelected = (y - 4) / 54;
 
                        if (iconSelected != lastIconSelected)
                        {
@@ -692,31 +665,18 @@ void GUI2::HandleIconSelection(SDL_Renderer * renderer)
                return;
        }
 
-       SDL_Rect dst;// = { 54, 54, 24 - 7, 2 };
-       dst.w = dst.h = 54;
-       dst.x = 24 - 7;
-       dst.y = 2;
-
+       // Draw the icon selector, if an icon is selected
        if (iconSelected >= 0)
        {
-               dst.y += iconSelected * 54;
+               SDL_Rect dst;// = { 54, 54, 24 - 7, 2 };
+               dst.w = dst.h = 54;
+               dst.x = 24 - 7;
+               dst.y = 2 + (iconSelected * 54);
+
                SDL_RenderCopy(renderer, iconSelection, NULL, &dst);
        }
 
-#if 1
        DrawSidebarIcons(renderer);
-#else
-       SDL_Texture * icons[7] = { powerOnIcon, disk1Icon, disk2Icon, powerOffIcon, powerOffIcon, powerOffIcon, powerOffIcon };
-       dst.w = dst.h = 40;
-       dst.x = 24;
-       dst.y = 2 + 7;
-
-       for(int i=0; i<7; i++)
-       {
-               SDL_RenderCopy(renderer, icons[i], NULL, &dst);
-               dst.y += 54;
-       }
-#endif
 
        // Set render target back to default
        SDL_SetRenderTarget(renderer, NULL);
index 8b8b9dfb565e78ef6b93117ac782612b0318984b..cfc3ec9485e4a99d18f6365fffe01dc22c24f3b8 100644 (file)
@@ -44,6 +44,7 @@ class GUI2
 
                // Everything else is a class method...
                static void Init(SDL_Renderer *);
+               static SDL_Texture * CreateTexture(SDL_Renderer *, const void *);
                static void MouseDown(int32_t, int32_t, uint32_t);
                static void MouseUp(int32_t, int32_t, uint32_t);
                static void MouseMove(int32_t, int32_t, uint32_t);