From ba806c8e43929dcc395fb20d194abb779f7bd7c2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ole=20Sch=C3=BCtt?= Date: Wed, 12 Nov 2014 13:20:18 +0000 Subject: [PATCH] Makefile: Check archives for left-behind objects svn-origin-rev: 14615 --- makefiles/Makefile | 4 ++ tools/build_utils/check_archives.py | 58 +++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100755 tools/build_utils/check_archives.py diff --git a/makefiles/Makefile b/makefiles/Makefile index a7ea39cd34..c08c99aed8 100644 --- a/makefiles/Makefile +++ b/makefiles/Makefile @@ -288,6 +288,10 @@ endif # this happens on stage 3 makedep: $(ALL_SRC_FILES) $(ALL_PKG_FILES) +ifeq ($(LD_SHARED),) + @echo "Removing stale archives for $(ONEVERSION) ... " + @$(TOOLSRC)/build_utils/check_archives.py $(firstword $(AR)) $(SRCDIR) $(LIBDIR) +endif @echo "Resolving dependencies for $(ONEVERSION) ... " @$(TOOLSRC)/build_utils/makedep.py $(OBJDIR)/all.dep $(MODDEPS) $(MAKEDEPMODE) $(ARCHIVE_EXT) $(OBJ_SRC_FILES) diff --git a/tools/build_utils/check_archives.py b/tools/build_utils/check_archives.py new file mode 100755 index 0000000000..384b4dec95 --- /dev/null +++ b/tools/build_utils/check_archives.py @@ -0,0 +1,58 @@ +#!/usr/bin/env python +# -*- coding: utf-8 -*- + +# author: Ole Schuett + +import sys, os +import subprocess +from os import path +from glob import glob + +KNOWN_EXTENSIONS = ("F", "c", "cu",) + +#============================================================================= +def main(): + if(len(sys.argv) != 4): + print("Usage: check_archives.py ") + sys.exit(1) + + ar_exe = sys.argv[1] + src_dir = sys.argv[2] + lib_dir = sys.argv[3] + + for root, dirs, files in os.walk(src_dir): + if("PACKAGE" in files): + content = open(path.join(root,"PACKAGE")).read() + package = eval(content) + + archive = "libcp2k" + path.basename(root) + if(package.has_key("archive")): + archive = package["archive"] + + archive_fn = path.join(lib_dir, archive+".a") + if(not path.exists(archive_fn)): + continue + + file_parts = [fn.rsplit(".", 1) for fn in files] + src_basenames = [parts[0] for parts in file_parts if parts[-1] in KNOWN_EXTENSIONS] + + output = check_output([ar_exe, "t", archive_fn]) + for obj in output.strip().split("\n"): + assert(obj.endswith(".o")) + if(obj[:-2] not in src_basenames): + print "Could not find source for object %s in archive %s , removing archive."%(obj, archive_fn) + os.remove(archive_fn) + break + +#============================================================================= +def check_output(*popenargs, **kwargs): + """ backport for Python 2.4 """ + p = subprocess.Popen(stdout=subprocess.PIPE, *popenargs, **kwargs) + output = p.communicate()[0] + assert(p.wait() == 0) + return output + +#============================================================================= +main() + +#EOF