From e0550f02a1729f6b5021312a379b460e2abd538c Mon Sep 17 00:00:00 2001
From: Kubat <mael.martin31@gmail.com>
Date: Wed, 21 Oct 2020 15:46:46 +0200
Subject: [PATCH] [build] put config files in their folder

---
 .gitignore                          |  2 --
 config.guess => config/config.guess |  0
 config.sub => config/config.sub     |  0
 install-sh => config/install-sh     |  0
 configure.ac                        | 13 +++++++++++++
 header.mk                           |  4 ++++
 6 files changed, 17 insertions(+), 2 deletions(-)
 rename config.guess => config/config.guess (100%)
 rename config.sub => config/config.sub (100%)
 rename install-sh => config/install-sh (100%)

diff --git a/.gitignore b/.gitignore
index 87455408f..e8a873187 100644
--- a/.gitignore
+++ b/.gitignore
@@ -102,5 +102,3 @@ vendor/luajit/src/luajit
 *.tmp
 cscope.files
 tags
-config.guess
-config.sub
diff --git a/config.guess b/config/config.guess
similarity index 100%
rename from config.guess
rename to config/config.guess
diff --git a/config.sub b/config/config.sub
similarity index 100%
rename from config.sub
rename to config/config.sub
diff --git a/install-sh b/config/install-sh
similarity index 100%
rename from install-sh
rename to config/install-sh
diff --git a/configure.ac b/configure.ac
index 0fa61a364..f27177baf 100644
--- a/configure.ac
+++ b/configure.ac
@@ -7,12 +7,21 @@ AC_INIT([Aegisub], [aegisub_version],, [aegisub])
 : ${CFLAGS=""}
 : ${CXXFLAGS=""}
 AC_CONFIG_SRCDIR([src/main.cpp])
+AC_CONFIG_AUX_DIR([config])
 AC_CONFIG_HEADER([acconf.h])
 AC_CONFIG_MACRO_DIR([m4macros])
 AC_GNU_SOURCE
 AC_CANONICAL_HOST
 AM_SILENT_RULES([yes])
 
+##########################
+# Only run from source dir
+##########################
+AEGISUB_PATH_SOURCE="$(dirname $(readlink -f "$0"))"
+AEGISUB_PATH_BUILD="$(pwd)"
+AS_IF([! test "$AEGISUB_PATH_BUILD" = "$AEGISUB_PATH_BUILD"],
+      [AC_MSG_ERROR([The build directory must be the same as the source directory])])
+
 ###################
 # Required packages
 ###################
@@ -88,6 +97,10 @@ AS_IF([test "x$AEGISUB_APPIMAGE_ENABLED" = "xyes"], [
     AC_PATH_PROG([WGET], [wget])
     AC_PATH_PROG([CHMOD], [chmod])
 
+    AS_IF([test "$PATCHELF" = "notfound"],  [AC_MSG_ERROR([patchelf is required for AppImage generation])])
+    AS_IF([test "$WGET" = "notfound"],      [AC_MSG_ERROR([wget is required for AppImage generation])])
+    AS_IF([test "$CHMOD" = "notfound"],     [AC_MSG_ERROR([chmod is required for AppImage generation])])
+
     # Download the AppImage creation tool, transforms the AppDir into an AppImage
     AC_MSG_CHECKING([Downloading AppImage creation tool])
     $WGET https://github.com/probonopd/AppImageKit/releases/download/continuous/appimagetool-`arch`.AppImage -O tools/appimagetool.AppImage -o config.wget.log
diff --git a/header.mk b/header.mk
index faf35b736..e9c7721b2 100644
--- a/header.mk
+++ b/header.mk
@@ -33,6 +33,7 @@ DISTCLEANFILES += \
 	$(TOP)build/git_version.h \
 	$(TOP)Makefile.inc \
 	$(TOP)config.log \
+	$(TOP)config.wget.log \
 	$(TOP)acconf.h.in \
 	$(TOP)config.status \
 	$(TOP)autom4te.cache \
@@ -41,6 +42,9 @@ DISTCLEANFILES += \
 CLEANFILES += \
 	$(wildcard $(TOP)Aegisub/usr/lib/*) \
 	$(TOP)Aegisub-x86_64.AppImage \
+	$(TOP)cscope.files \
+	$(TOP)cscope.out \
+	$(TOP)tags \
 
 CLEANDIRS += \
 	$(TOP)Aegisub \
-- 
GitLab