Skip to content

Commit

Permalink
allow to build the osx executable using frameworks !
Browse files Browse the repository at this point in the history
FRAMEWORK=1 in the makefile or on the command line.
Use the TOOLS/make_frameworks.pl script to convert the shared libs to
frameworks !
  • Loading branch information
zelurker committed Dec 19, 2016
1 parent 34db751 commit 453db5f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 29 deletions.
74 changes: 46 additions & 28 deletions TOOLS/make_framework.pl
Expand Up @@ -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/;
Expand All @@ -12,46 +28,48 @@ ($)

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";
chdir "$name.framework";
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);
}

20 changes: 19 additions & 1 deletion makefile
Expand Up @@ -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
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 453db5f

Please sign in to comment.