From c3dffc8c419540eca8edc059f12ad582aab4cfad Mon Sep 17 00:00:00 2001
From: bauen1 <j2468h@gmail.com>
Date: Wed, 5 Jul 2017 21:13:35 +0200
Subject: [PATCH] Fixed links

---
 src/minimal_overlay/bundles/links/01_get.sh   | 11 ++---
 src/minimal_overlay/bundles/links/02_build.sh | 45 +++++++------------
 2 files changed, 19 insertions(+), 37 deletions(-)

diff --git a/src/minimal_overlay/bundles/links/01_get.sh b/src/minimal_overlay/bundles/links/01_get.sh
index e2a9f4da6..f245643c5 100755
--- a/src/minimal_overlay/bundles/links/01_get.sh
+++ b/src/minimal_overlay/bundles/links/01_get.sh
@@ -2,10 +2,7 @@
 
 SRC_DIR=$(pwd)
 
-# Find the main source directory
-cd ../../..
-MAIN_SRC_DIR=$(pwd)
-cd $SRC_DIR
+. ../../common.sh
 
 # Grab everything after the '=' character.
 DOWNLOAD_URL=$(grep -i LINKS_SOURCE_URL $MAIN_SRC_DIR/.config | cut -f2 -d'=')
@@ -33,12 +30,12 @@ fi
 
 # Delete folder with previously extracted Links.
 echo "Removing Links work area. This may take a while..."
-rm -rf ../../work/overlay/links
-mkdir ../../work/overlay/links
+rm -rf $WORK_DIR/overlay/links
+mkdir $WORK_DIR/overlay/links
 
 # Extract Links to folder 'work/overlay/links'.
 # Full path will be something like 'work/overlay/links/links-2.12'.
-tar -xvf $ARCHIVE_FILE -C ../../work/overlay/links
+tar -xvf $ARCHIVE_FILE -C $WORK_DIR/overlay/links
 
 cd $SRC_DIR
 
diff --git a/src/minimal_overlay/bundles/links/02_build.sh b/src/minimal_overlay/bundles/links/02_build.sh
index 7a23f778f..646e94334 100755
--- a/src/minimal_overlay/bundles/links/02_build.sh
+++ b/src/minimal_overlay/bundles/links/02_build.sh
@@ -2,57 +2,42 @@
 
 SRC_DIR=$(pwd)
 
-# Find the main source directory
-cd ../../..
-MAIN_SRC_DIR=$(pwd)
-cd $SRC_DIR
+. ../../common.sh
 
-# Read the 'JOB_FACTOR' property from '.config'
-JOB_FACTOR="$(grep -i ^JOB_FACTOR $MAIN_SRC_DIR/.config | cut -f2 -d'=')"
+cd $WORK_DIR/overlay/links
 
-# Read the 'CFLAGS' property from '.config'
-CFLAGS="$(grep -i ^CFLAGS $MAIN_SRC_DIR/.config | cut -f2 -d'=')"
-
-# Find the number of available CPU cores.
-NUM_CORES=$(grep ^processor /proc/cpuinfo | wc -l)
-
-# Calculate the number of 'make' jobs to be used later.
-NUM_JOBS=$((NUM_CORES * JOB_FACTOR))
-
-cd $MAIN_SRC_DIR/work/overlay/links
+DESTDIR="$PWD/links_installed"
 
 # Change to the Links source directory which ls finds, e.g. 'links-2.12'.
 cd $(ls -d links-*)
 
 echo "Preparing Links work area. This may take a while..."
-make clean -j $NUM_JOBS 2>/dev/null
+# distclean to also clear configure files
+make -j $NUM_JOBS distclean
 
-rm -rf ../links_installed
+rm -rf $DESTDIR
 
 echo "Configuring Links..."
-./configure \
-  --prefix=../links_installed \
+CC="$CC" CFLAGS="$CFLAGS" CPPFLAGS="$CPPFLAGS" LDFLAGS="$LDFLAGS" ./configure \
+  --prefix=/usr \
   --disable-graphics \
   --disable-utf8 \
   --without-ipv6 \
-  --without-ssl \
-  --without-zlib \
-  --without-x
-
-# Set CFLAGS directly in Makefile.
-sed -i "s/^CFLAGS = .*/CFLAGS = $CFLAGS/" Makefile
+  --without-ssl
 
 echo "Building Links..."
 make -j $NUM_JOBS
 
 echo "Installing Links..."
-make install -j $NUM_JOBS
+make -j $NUM_JOBS install DESTDIR=$DESTDIR
 
 echo "Reducing Links size..."
-strip -g ../links_installed/bin/* 2>/dev/null
+strip -g $DESTDIR/usr/bin/*
 
-cp -r ../links_installed/bin \
-  $MAIN_SRC_DIR/work/src/minimal_overlay/rootfs
+ROOTFS="$WORK_DIR/src/minimal_overlay/rootfs"
+
+mkdir -p "$ROOTFS/usr/bin"
+cp -r $DESTDIR/usr/bin/* $ROOTFS/usr/bin/
 
 echo "Links has been installed."