Accéder au contenu.
Menu Sympa

starpu-devel - [Starpu-devel] doc/Makefile.am: replace stat(1) by something portable.

Objet : Developers list for StarPU

Archives de la liste

[Starpu-devel] doc/Makefile.am: replace stat(1) by something portable.


Chronologique Discussions 
  • From: Cyril Roelandt <cyril.roelandt@inria.fr>
  • To: "starpu-devel@lists.gforge.inria.fr" <starpu-devel@lists.gforge.inria.fr>
  • Subject: [Starpu-devel] doc/Makefile.am: replace stat(1) by something portable.
  • Date: Thu, 12 Jul 2012 17:42:56 +0200
  • List-archive: <http://lists.gforge.inria.fr/pipermail/starpu-devel>
  • List-id: "Developers list. For discussion of new features, code changes, etc." <starpu-devel.lists.gforge.inria.fr>

Hey !

Here is an excerpt from doc/Makefile.am:


#TODO: when stat is not available on the machine, insert "unknown date"
chapters/version.texi:
@for f in $(starpu_TEXINFOS) ; do \
if test -f $(top_srcdir)/doc/$$f ; then stat --format=%Y
$(top_srcdir)/doc/$$f ; fi \
done | sort -r | head -1 > timestamp
@LC_ALL=C date --date=@`cat timestamp` +"%d %B %Y" >
timestamp_updated
@LC_ALL=C date --date=@`cat timestamp` +"%B %Y" >
timestamp_updated_month


A few things to notice:
* the TODO: stat(1) may not be available on all platforms.
* stat(1) does not seem to be a POSIX utility (I could not find it in
the "Shell & Utilities" section)
* date(1) only has only one option specified by POSIX (-u). Here, we use
date --date, but on NetBSD, one would use date -r, and on other Unices,
well, there might be another option...

Basically, we need a portable way of generating the latest time at which
a .texi file was modified. We cannot write a one-liner in a very nice
language such as Perl, Python or Scheme, becasue that would add a new
dependency.

The attached patch adds a starpu_stat.c program, that uses the following
calls:

- stat(2)
- difftime(3)
- localtime(3)
- strftime(3)

All these functions are POSIX-compliant. Should one of them be missing
on a platform, it would be easy to just use an #ifdef HAVE_FUNCTION to
fix it.

So far, I have only tested the patch on Linux and NetBSD, but I think it
should work on FreeBSD, Hurd and Mac OS.

What do you think ?


Cyril.
Index: doc/Makefile.am
===================================================================
--- doc/Makefile.am	(revision 6918)
+++ doc/Makefile.am	(working copy)
@@ -46,18 +46,17 @@
 uninstall-local:
 	$(RM) $(DESTDIR)$(infodir)/dir
 
-#TODO: when stat is not available on the machine, insert "unknown date"
-chapters/version.texi:
-	@for f in $(starpu_TEXINFOS) ; do \
-                if test -f $(top_srcdir)/doc/$$f ; then stat --format=%Y $(top_srcdir)/doc/$$f ; fi \
-        done | sort -r | head -1 > timestamp
-	@LC_ALL=C date --date=@`cat timestamp` +"%d %B %Y" > timestamp_updated
-	@LC_ALL=C date --date=@`cat timestamp` +"%B %Y" > timestamp_updated_month
-	@echo "@set UPDATED " `cat timestamp_updated` > $(top_srcdir)/doc/chapters/version.texi
-	@echo "@set UPDATED-MONTH" `cat timestamp_updated_month` >> $(top_srcdir)/doc/chapters/version.texi
+starpu_stat: starpu_stat.c
+	$(CC) -o starpu_stat starpu_stat.c
+
+chapters/version.texi: starpu_stat
+	./starpu_stat $(starpu_TEXINFOS) > $(top_srcdir)/doc/chapters/version.texi
+	@if [ $$? -ne 0 ]; then \
+		@echo "@set UPDATED unknown date" > $(top_srcdir)/doc/chapters/version.texi; \
+		@echo "@set UPDATED-MONTH unknown date" >> $(top_srcdir)/doc/chapters/version.texi; \
+	fi
 	@echo "@set EDITION $(VERSION)" >> $(top_srcdir)/doc/chapters/version.texi
 	@echo "@set VERSION $(VERSION)" >> $(top_srcdir)/doc/chapters/version.texi
-	@$(RM) timestamp timestamp_updated timestamp_updated_month
 
 #$(top_srcdir)/doc/starpu.texi: vector_scal_c.texi vector_scal_cuda.texi vector_scal_opencl.texi vector_scal_opencl_codelet.texi
 #vector_scal_c.texi: $(top_srcdir)/examples/basic_examples/vector_scal.c
Index: doc/starpu_stat.c
===================================================================
--- doc/starpu_stat.c	(revision 0)
+++ doc/starpu_stat.c	(revision 0)
@@ -0,0 +1,51 @@
+#include <sys/stat.h>
+#include <sys/types.h>
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+static int
+find_most_recent(time_t *t, int argc, char *argv[])
+{
+	int i;
+	for (i = 0; i < argc; i++)
+	{
+		struct stat buf;
+		if (stat(argv[i], &buf) != 0)
+			return 1;
+		if (difftime(buf.st_mtime, *t) > 0)
+			*t = buf.st_mtime;
+	}
+	return 0;
+}
+
+static void
+print(time_t t, FILE *f)
+{
+	char day[3];
+	char month[32];
+	char year[5];
+	struct tm *mtime = localtime(&t);
+
+	strftime(day, sizeof(day), "%d", mtime);
+	strftime(month, sizeof(month), "%B", mtime);
+	strftime(year, sizeof(year), "%Y", mtime);
+
+	fprintf(f, "@set UPDATED %s %s %s\n", day, month, year);
+	fprintf(f, "@set UPDATED-MONTH %s %s\n", month, year);
+}
+
+int
+main(int argc, char *argv[])
+{
+	FILE *out = stdout;
+	time_t most_recent = 0;
+
+	if (find_most_recent(&most_recent, --argc, ++argv) != 0)
+		return EXIT_FAILURE;
+	print(most_recent, out);
+
+	return EXIT_SUCCESS;
+}



Archives gérées par MHonArc 2.6.19+.

Haut de le page