From 9579486fadb5af77ecfc8df9dd1e9e814d958bef Mon Sep 17 00:00:00 2001 From: Lars Wirzenius Date: Fri, 30 Mar 2012 14:18:59 +0100 Subject: Add autodetection for autotools, and a factory function --- morphlib/buildsystem.py | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'morphlib/buildsystem.py') diff --git a/morphlib/buildsystem.py b/morphlib/buildsystem.py index 7ac56cf4..3969bddc 100644 --- a/morphlib/buildsystem.py +++ b/morphlib/buildsystem.py @@ -14,6 +14,9 @@ # 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. +import os + + class BuildSystem(object): '''An abstraction of an upstream build system. @@ -40,7 +43,37 @@ class ManualBuildSystem(BuildSystem): def used_by_project(self, srcdir): return False + class AutotoolsBuildSystem(BuildSystem): '''The automake/autoconf/libtool holy trinity.''' + + def used_by_project(self, srcdir): + indicators = [ + 'autogen.sh', + 'configure.ac', + 'configure.in', + 'configure.in.in', + ] + + return any(os.path.exists(os.path.join(srcdir, x)) + for x in indicators) + + +def detect_build_system(srcdir): + '''Automatically detect the build system, if possible. + + If the build system cannot be detected automatically, then the manual + build system is used instead. + + ''' + + build_systems = [ + AutotoolsBuildSystem(), + ] + + for bs in build_systems: + if bs.used_by_project(srcdir): + return bs + return ManualBuildSystem() -- cgit v1.2.1