-
Notifications
You must be signed in to change notification settings - Fork 1
/
install.sh
executable file
·157 lines (132 loc) · 4.03 KB
/
install.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
#!/bin/bash
set -e
## Variables
SDKVER=4.2.3
GNUSTEP_MAKE_GIT=a964f87bdecab5156ed24f224548680aa2555676 # svn-39575, probably close to what hopper was built with
GNUSTEP_BASE_GIT=03952f1e961931828a3eba62784c02205e8c0a65 # svn-39569, hopper ships libgnustep-base 1.24.9
LIBDISPATCH_REV=e63c3c130c5115b653beca04b7f245e20ba84a08 # hopper ships libdispatch 0.1.3.1
JOBS=$(nproc)
DEST="${HOME}/GNUstep/Library/ApplicationSupport/Hopper"
SDKDIR="${DEST}/HopperSDK-${SDKVER}"
GS_DIR="${DEST}/gnustep-$(arch)"
LAYOUT=fhs
CC=clang
CXX=clang++
## Cleanup
mkdir -p "${DEST}"
echo "Cleaning"
rm -rf sources # comment this out to not remove downloaded sources (saves dowloads) while developing this script
rm -rf "${DEST}/HopperSDK" "${SDKDIR}" "${GS_DIR}"
mkdir -p "${SDKDIR}" "${GS_DIR}" sources
## Download latest Hopper SDK
echo "Downloading sources"
echo " Hopper SDK"
SDK_ZIP="HopperSDK-${SDKVER}.zip"
test -f sources/$SDK_ZIP || curl -A SDK -L --progress-bar -o sources/$SDK_ZIP "https://d2ap6ypl1xbe4k.cloudfront.net/${SDK_ZIP}"
unzip -qq -d "${SDKDIR}" sources/$SDK_ZIP >/dev/null 2>&1
ln -s "${SDKDIR}" "${DEST}/HopperSDK"
## Download sources
cd sources
echo " libobjc2..."
D=gnustep-libobjc2
test -d $D || git clone -q https://github.com/gnustep/libobjc2 $D
echo " gnustep-make..."
D=gnustep-make
test -d $D || git clone -q https://github.com/gnustep/make $D
git -C $D checkout -qf $GNUSTEP_MAKE_GIT
echo " gnustep-base..."
D=gnustep-base
test -d $D || git clone -q https://github.com/gnustep/base $D
git -C $D checkout -qf $GNUSTEP_BASE_GIT
echo " libdispatch..."
D=libdispatch
test -d $D || git clone -q https://github.com/nickhutchinson/libdispatch $D
git -C $D checkout -qf $LIBDISPATCH_REV
## Compilation
echo "Compilation"
SRC=$(pwd)
## Compile gnustep-make
echo " gnustep-make..."
cd gnustep-make
./configure CC=$CC CXX=$CXX --with-layout=$LAYOUT --prefix="${GS_DIR}"
make
make install
cd $SRC
. "${GS_DIR}/share/GNUstep/Makefiles/GNUstep.sh"
## Compile the Objective-C 2 runtime
echo " libobjc2..."
cd gnustep-libobjc2
rm -rf build ; mkdir build ; cd build
cmake .. -DCMAKE_INSTALL_PREFIX="${GS_DIR}" -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX
make -j$JOBS
make install
cd $SRC
cd gnustep-make
./configure CC=$CC CXX=$CXX --enable-objc-nonfragile-abi --with-layout=$LAYOUT --prefix="${GS_DIR}"
make
make install
cd $SRC
. "${GS_DIR}/share/GNUstep/Makefiles/GNUstep.sh"
## Compile GNUstep base
# On recent Ubuntu (17.04...) you may need to do 'sudo apt install libxml2-dev libgnutls28-dev libxslt1-dev libgcrypt20-dev'
echo " gnustep-base..."
cd gnustep-base
patch -p0 <../../patches/gnustep-base.patch
./configure CC=$CC CXX=$CXX --prefix="${GS_DIR}"
make -j$JOBS 2>/dev/null
make install
cd $SRC
## Compile libdispatch
echo " libdispatch..."
cd libdispatch
patch -p1 <../../patches/libdispatch.patch
sed -i"" "s/add_subdirectory(testing)/#add_subdirectory(testing)/" CMakeLists.txt
mkdir build
cd build
cmake .. -DCMAKE_C_COMPILER=$CC -DCMAKE_CXX_COMPILER=$CXX -DCMAKE_INSTALL_PREFIX="${GS_DIR}" -DCMAKE_BUILD_TYPE=Release
make
make install
cd $SRC
## Let's test that all is fine by compiling a small Objective-C program
echo "Testing"
cat >test.m<<_EOF
#include <Foundation/Foundation.h>
#import <dispatch/dispatch.h>
@interface A : NSObject
@end
@implementation A
- (id)init {
if (self = [super init]) {
NSLog(@"in init");
}
return self;
}
- (void)fct {
NSLog(@"in fct");
@autoreleasepool {
NSMutableArray *array = [NSMutableArray array];
for (int i=0; i<4; i++) {
[array addObject:[[A alloc] init]];
}
}
}
- (void)dealloc {
NSLog(@"in dealloc");
}
@end
int main(int argc, char **argv) {
//@autoreleasepool {
static dispatch_once_t predicate;
dispatch_once(&predicate, ^ {
A *a = [[A alloc] init];
[a fct];
});
//}
return 0;
}
_EOF
clang test.m -o test $(gnustep-config --objc-flags) $(gnustep-config --base-libs) -fobjc-arc -fobjc-nonfragile-abi -O0 -g -ldispatch
./test
echo "GNUstep for Hopper SDK ready."
echo "source '${HOME}/hopper-gnustep.sh' to use it"
ln -fs "${GS_DIR}/share/GNUstep/Makefiles/GNUstep.sh" "${HOME}/hopper-gnustep.sh"