Skip to content

Instantly share code, notes, and snippets.

@andyarvanitis
Last active June 10, 2018 18:54
Show Gist options
  • Select an option

  • Save andyarvanitis/d3b26cafb71e0028f9a36fd646762310 to your computer and use it in GitHub Desktop.

Select an option

Save andyarvanitis/d3b26cafb71e0028f9a36fd646762310 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
# Ensure any prebuilt GNUstep packages are uninstalled before running this script
# Adapted from
# http://wiki.gnustep.org/index.php/GNUstep_under_Ubuntu_Linux
# and https://stackoverflow.com/questions/40698870/compiling-objective-c-on-debian-8-gnu-linux-with-clang-and-gnustep-make
# Show prompt function
function showPrompt()
{
if [ "$PROMPT" = true ] ; then
echo -e "\n\n"
read -p "${GREEN}Press enter to continue...${NC}"
fi
}
# Set colors
GREEN=`tput setaf 2`
NC=`tput sgr0` # No Color
# Set to true to pause after each build to verify successful build and installation
PROMPT=false
CLANG_LLVM_VERSION=-3.9 # llvm/clang versions between 3.9 and 5.0 (inclusive) appear to work
# Install Requirements
sudo apt update
echo -e "\n\n${GREEN}Installing dependencies...${NC}"
sudo apt -y install clang${CLANG_LLVM_VERSION} cmake libffi-dev libxml2-dev \
libgnutls28-dev libicu-dev libblocksruntime-dev libpthread-workqueue-dev autoconf libtool \
llvm${CLANG_LLVM_VERSION}-dev # libkqueue-dev libdispatch-dev
sudo update-alternatives --install /usr/bin/clang clang /usr/bin/clang${CLANG_LLVM_VERSION} 100
sudo update-alternatives --install /usr/bin/clang++ clang++ /usr/bin/clang++${CLANG_LLVM_VERSION} 100
sudo update-alternatives --install /usr/bin/llvm-config llvm-config /usr/bin/llvm-config${CLANG_LLVM_VERSION} 100
# Create build directory
mkdir GNUstep-build
cd GNUstep-build
# Set clang as compiler
export CC=clang
export CXX=clang++
# Checkout sources
echo -e "\n\n${GREEN}Downloading sources...${NC}"
mkdir -p libobjc2 && wget -qO- https://github.com/gnustep/libobjc2/archive/v1.8.1.tar.gz | tar xz -C libobjc2 --strip-components=1
mkdir -p libkqueue && wget -qO- https://github.com/mheily/libkqueue/archive/v2.2.0.tar.gz | tar xz -C libkqueue --strip-components=1
mkdir -p libdispatch && wget -qO- https://github.com/nickhutchinson/libdispatch/archive/v0.1.3.1.tar.gz | tar xz -C libdispatch --strip-components=1
mkdir -p make && wget -qO- ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-make-2.6.8.tar.gz | tar xz -C make --strip-components=1
mkdir -p base && wget -qO- ftp://ftp.gnustep.org/pub/gnustep/core/gnustep-base-1.25.1.tar.gz | tar xz -C base --strip-components=1
showPrompt
# Build libobjc2
echo -e "\n\n"
echo -e "${GREEN}Building libobjc2...${NC}"
cd libobjc2
rm -Rf build
mkdir build && cd build
cmake ../ -DCMAKE_C_COMPILER=clang -DCMAKE_CXX_COMPILER=clang -DCMAKE_ASM_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/usr/local -DTESTS=OFF
cmake --build .
sudo -E make install
sudo ldconfig
showPrompt
# Build libkqueue
echo -e "\n\n"
echo -e "${GREEN}Building libkqueue...${NC}"
cd ../../libkqueue
rm -Rf build
mkdir build && cd build
cmake ../ -DCMAKE_C_COMPILER=clang -DCMAKE_INSTALL_PREFIX=/usr
cmake --build .
sudo -E make install
sudo ldconfig
showPrompt
# Build libdispatch
echo -e "\n\n"
echo -e "${GREEN}Building libdispatch...${NC}"
cd ../../libdispatch
rm -Rf build
mkdir build && cd build
../configure --prefix=/usr
make
sudo make install
sudo ldconfig
export LDFLAGS="${LDFLAGS} -ldispatch"
showPrompt
OBJCFLAGS="-fblocks -fobjc-runtime=gnustep"
# Build GNUstep make
echo -e "\n\n"
echo -e "${GREEN}Building GNUstep-make...${NC}"
cd ../../make
./configure --enable-debug-by-default --with-layout=fhs --enable-objc-nonfragile-abi
make -j8
sudo -E make install
. /usr/local/share/GNUstep/Makefiles/GNUstep.sh
echo ". /usr/local/share/GNUstep/Makefiles/GNUstep.sh" >> ~/.bashrc
showPrompt
# Build GNUstep base
echo -e "\n\n"
echo -e "${GREEN}Building GNUstep-base...${NC}"
cd ../base/
./configure --disable-mixedabi
make -j8
sudo -E make install
showPrompt
# Example files
echo -e "\n\n"
echo -e "${GREEN}Creating sample source and build files...${NC}"
cd ../../
cat > GNUmakefile << EOF
include \$(GNUSTEP_MAKEFILES)/common.make
TOOL_NAME = Main
Main_OBJC_FILES = main.m
include \$(GNUSTEP_MAKEFILES)/tool.make
EOF
cat > main.m << EOF
#import <Foundation/Foundation.h>
int main() {
@autoreleasepool {
id array = @[ @1, @YES, @"foo" ];
NSLog(@"Array is %@", array);
}
return 0;
}
EOF
echo -e "\n\n"
echo -e "${GREEN}Install is done. Open a new terminal to start using.${NC}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment