Ticket #52: macosx_build.patch

File macosx_build.patch, 4.8 KB (added by Thomas Bernard, 7 years ago)

patch to fix OS X build issues. detect libpng and lua

  • src/Makefile

     
    105105    BIN = ../bin/grafx2
    106106    SVN_REVISION = $(shell svnversion | cut -f2 -d ":" - | tr -d "M")
    107107
     108    SDLCONFIG := $(shell which sdl-config)
     109ifneq ($(SDLCONFIG), )
    108110    # these are for use with macports
    109     #SDLCOPT = $(shell sdl-config --cflags)
    110     #SDLLOPT = $(shell sdl-config --libs) $(shell pkg-config --libs SDL_image)
    111     #LUACOPT = $(shell pkg-config lua --cflags --silence-errors ||pkg-config lua5.1 --cflags --silence-errors ||pkg-config lua-5.1 --cflags)
    112     #LUALOPT = $(shell pkg-config lua --libs --silence-errors ||pkg-config lua5.1 --libs --silence-errors ||pkg-config lua-5.1 --libs)
    113 
     111    SDLCOPT = $(shell sdl-config --cflags)
     112    SDLLOPT = $(shell sdl-config --libs) $(shell pkg-config --libs SDL_image)
     113else
    114114    # these are for use with Mac OS X native frameworks
    115115    #-framework SDL_ttf
    116116    SDLLOPT = -isysroot $(MACOSX_SYSROOT) $(MACOSX_ARCH) -L/usr/lib -framework SDL -framework SDL_image -framework Cocoa -framework Carbon -framework OpenGL
    117117    SDLCOPT = $(MACOSX_ARCH) -I$(FWDIR)/SDL.framework/Headers -I$(FWDIR)/SDL_image.framework/Headers -I$(FWDIR)/SDL_ttf.framework/Headers -D_THREAD_SAFE
     118endif
     119
     120    # these are for use with macports
     121    LUAPKG := $(shell for p in lua5.1 lua-5.1 lua51 lua ; do pkg-config --exists $$p && echo $$p && break ; done)
     122ifneq ($(LUAPKG), )
     123    LUACOPT = $(shell pkg-config $(LUAPKG) --cflags)
     124    LUALOPT = $(shell pkg-config $(LUAPKG) --libs)
     125else
     126    # these are for use with Mac OS X native frameworks
    118127    LUACOPT = -I$(FWDIR)/Lua.framework/Headers
    119128ifdef MACOSX_LION
    120129    LUALOPT = -framework lua
    121130else
    122131    LUALOPT = -llua
    123132endif
     133endif
    124134
    125135    # these are for everyone
    126136    COPT = -D_DARWIN_C_SOURCE -D__macosx__ -D__linux__ -W -Wall -Wdeclaration-after-statement -O$(OPTIM) -std=c99 -c -g $(LUACOPT) $(SDLCOPT) $(TTFCOPT) -I/usr/include
    127137ifdef MACOSX_LION
    128138    LOPT = $(SDLLOPT) $(LUALOPT) -framework libpng14 -lz
    129139else
    130     LOPT = $(SDLLOPT) $(LUALOPT) -lpng -lz
     140    LOPT = $(SDLLOPT) $(LUALOPT)
     141    LIBPNGCONFIG := $(shell libpng-config)
     142ifneq ($(LIBPNGCONFIG), )
     143    COPT += $(shell libpng-config --cflags)
     144    LOPT += $(shell libpng-config --ldflags)
     145else
     146    LOPT += -lpng
    131147endif
     148    LOPT += -lz
     149endif
    132150    # Use gcc for compiling. Use ncc to build a callgraph and analyze the code.
    133151    CC = gcc
    134152    #CC = nccgen -ncgcc -ncld -ncfabs
     
    288306        LUACOPT =
    289307        LUALOPT =
    290308      else
    291         LUACOPT = $(shell pkg-config lua --cflags --silence-errors ||pkg-config lua5.1 --cflags --silence-errors ||pkg-config lua-5.1 --cflags)
    292         LUALOPT = $(shell pkg-config lua --libs --silence-errors ||pkg-config lua5.1 --libs --silence-errors ||pkg-config lua-5.1 --libs)
     309        LUAPKG := $(shell for p in lua5.1 lua-5.1 lua51 lua ; do pkg-config --exists $$p && echo $$p && break ; done)
     310        LUACOPT = $(shell pkg-config $(LUAPKG) --cflags)
     311        LUALOPT = $(shell pkg-config $(LUAPKG) --libs)
    293312      endif
    294313    endif
    295314   
     
    484503        cp -r ../share/grafx2/scripts/samples_2.4/picture Grafx2.app/Contents/Resources/scripts/samples_2.4
    485504ifdef MACOSX_LION
    486505        mkdir -p Grafx2.app/Contents/Frameworks/Lua.framework/Versions
     506        cp -Rp $(FWDIR)/Lua.framework/Versions/A Grafx2.app/Contents/Frameworks/Lua.framework/Versions
    487507        mkdir -p Grafx2.app/Contents/Frameworks/libpng14.framework/Versions
     508        cp -Rp $(FWDIR)/libpng14.framework/Versions/1.4.8 Grafx2.app/Contents/Frameworks/libpng14.framework/Versions
    488509endif
    489         mkdir -p Grafx2.app/Contents/Frameworks/SDL.framework/Versions
    490         mkdir -p Grafx2.app/Contents/Frameworks/SDL_image.framework/Versions
     510        if [ -d $(FWDIR)/SDL.framework/Versions ] ; then \
     511                mkdir -p Grafx2.app/Contents/Frameworks/SDL.framework/Versions ;\
     512                cp -Rp $(FWDIR)/SDL.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL.framework/Versions ;\
     513        fi
     514        if [ -d $(FWDIR)/SDL_image.framework/Versions ] ; then \
     515                mkdir -p Grafx2.app/Contents/Frameworks/SDL_image.framework/Versions ;\
     516                cp -Rp $(FWDIR)/SDL_image.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL_image.framework/Versions ;\
     517        fi
    491518#       mkdir -p Grafx2.app/Contents/Frameworks/SDL_ttf.framework/Versions
    492 ifdef MACOSX_LION
    493         cp -Rp $(FWDIR)/Lua.framework/Versions/A Grafx2.app/Contents/Frameworks/Lua.framework/Versions
    494         cp -Rp $(FWDIR)/libpng14.framework/Versions/1.4.8 Grafx2.app/Contents/Frameworks/libpng14.framework/Versions
    495 endif
    496         cp -Rp $(FWDIR)/SDL.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL.framework/Versions
    497         cp -Rp $(FWDIR)/SDL_image.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL_image.framework/Versions
    498519#       cp -Rp $(FWDIR)/SDL_ttf.framework/Versions/A Grafx2.app/Contents/Frameworks/SDL_ttf.framework/Versions
    499520    # remove those
    500521        rm -fr Grafx2.app/Contents/Frameworks/SDL.framework/Versions/A/Headers