From 453db5fa14e8c482ab9d3b4a6f8301eb80a6be03 Mon Sep 17 00:00:00 2001 From: Emmanuel Anne Date: Mon, 19 Dec 2016 03:06:02 +0100 Subject: [PATCH] allow to build the osx executable using frameworks ! FRAMEWORK=1 in the makefile or on the command line. Use the TOOLS/make_frameworks.pl script to convert the shared libs to frameworks ! --- TOOLS/make_framework.pl | 74 +++++++++++++++++++++++++---------------- makefile | 20 ++++++++++- 2 files changed, 65 insertions(+), 29 deletions(-) diff --git a/TOOLS/make_framework.pl b/TOOLS/make_framework.pl index f409f04d..0ea4d115 100644 --- a/TOOLS/make_framework.pl +++ b/TOOLS/make_framework.pl @@ -3,6 +3,22 @@ my $lib = shift @ARGV || die "pass lib in argument\n"; make_framework($lib); +sub get_name { + # extract the name of a shared lib + my $first = shift; + $first =~ s/^.+\///; # get rid of path + my ($res) = $first =~ /lib([_a-zA-Z0-9]+)/; + $res; +} + +sub mysys { + my $cmd = shift; + my $ret = system($cmd); + if ($ret) { + die "system $cmd failed, exit $ret\n"; + } +} + sub handle_otool($) { my $first = shift; $first =~ s/^.+name (\/.+) \(.+/$1/; @@ -12,7 +28,7 @@ ($) sub make_framework($) { my $lib = shift; - my ($name) = $lib =~ /lib([_a-zA-Z0-9]+)/; + my $name = get_name($lib); print "making $name framework...\n"; system("rm -rf $name.framework"); mkdir "$name.framework"; @@ -20,38 +36,40 @@ ($) mkdir "Versions"; mkdir "Versions/A"; symlink("A","Versions/Current"); - system("cp $lib Versions/A/$name"); + mysys("cp $lib Versions/A/$name && chmod +w Versions/A/$name"); symlink("Versions/Current/$name","$name"); chdir ".."; my $path = "$name.framework/$name"; my $f; - open($f,"otool -l $path|grep 'name /'|"); - my $first = handle_otool(<$f>); - system("install_name_tool -id \@executable_path/../$frameworks/$name.framework/Versions/A/$name $path"); - while (<$f>) { - $first = handle_otool($_); - if ($first =~ /local/) { - my ($file) = $first =~ /lib\/(.+)/; - if (!-e $first) { - if (-e "/usr/local/lib/$file") { - $first = "/usr/local/lib/$file"; - print "fixing lib path for $first\n"; - } elsif (! -e "/usr/lib/$file") { - die "pas trouvé $first ni /usr/local/lib/$file\n"; - } - } - print "handling $first\n"; - if (! -e "/usr/lib/$file" && -e "$first") { - ($name) = $first =~ /lib([_a-zA-Z0-9]+)/; - if (!-d "$name.framework") { - make_framework($first); + open($f,"otool -l $path|grep 'name /'|"); + my $first = handle_otool(<$f>); + mysys("install_name_tool -id \@executable_path/../$name.framework/Versions/A/$name $path"); + while (<$f>) { + $first = handle_otool($_); + if ($first =~ /local/) { + my ($file) = $first =~ /lib\/(.+)/; + if (!-e $first) { + if (-e "/usr/local/lib/$file") { + $first = "/usr/local/lib/$file"; + print "fixing lib path for $first\n"; + } elsif (! -e "/usr/lib/$file") { + die "pas trouvé $first ni /usr/local/lib/$file\n"; + } + } + print "handling $first\n"; + if (! -e "/usr/lib/$file" && -e "$first") { + $name = get_name($first); + if (!-d "$name.framework") { + make_framework($first); + } else { + print "$name framework already exists\n"; + } + mysys("install_name_tool -change $first \@executable_path/../$name.framework/Versions/A/$name $path"); + } else { + print "existe pas $first\n"; + } } - system("install_name_tool -change $first \@executable_path/../$frameworks/$name.framework/Versions/A/$name $path"); - } else { - print "existe pas $first\n"; - } } - } - close($f); + close($f); } diff --git a/makefile b/makefile index 955e31b9..c4bfb2bd 100644 --- a/makefile +++ b/makefile @@ -22,6 +22,12 @@ VERSION = "0.64.13" # Be verbose ? # VERBOSE = 1 +# For osx : use frameworks or brew shared libs ? +# Actually frameworks are a convenience for end users, to build them use +# the make_framework.pl script in TOOLS directory to convert the brew +# shared libs to frameworks and then define FRAMEWORK here +FRAMEWORK = 1 + # Disable all asm, if you do that you'd better remove the cpu cores which # currently exist only in asm. This will also disable the asm_video_core of # course @@ -865,7 +871,15 @@ CONSOLE = \ $(OBJDIR)/sdl/gui/tconsole.o \ $(OBJDIR)/sdl/console/exec.o +ifdef DARWIN +ifdef FRAMEWORK +LIBS += -framework muparser +else +LIBS += -lmuparser +endif +else # DARWIN LIBS += -lmuparser +endif LIBS_DEBUG += -lmuparser endif @@ -1067,9 +1081,13 @@ OBJS += $(OBJDIR)/sdl/sasound.o ifdef DARWIN # Official SDL1.2 frameworks (SDL / image / ttf) in /Library/Frameworks CFLAGS += -I/usr/local/include/SDL/ -DDARWIN +ifdef FRAMEWORK +LIBS += -framework SDL -framework SDL_ttf -framework SDL_image -framework Cocoa -framework OpenGL +LIBS += -framework SDL_sound -framework intl -liconv +else LIBS += -lSDL -lSDL_ttf -lSDL_image -framework Cocoa -framework OpenGL -# SDL_sound is statically linked from homebrew as gettext, libpng etc. LIBS += -lSDL_sound -lintl -liconv +endif AFLAGS = -f macho -O1 -D__RAINE__ -DRAINE_UNIX -DDARWIN SFLAGS += -DDARWIN CFLAGS_MCU += -DDARWIN