only copy generated interfaces to source tree when needed
authorSven Verdoolaege <sven.verdoolaege@gmail.com>
Sat, 31 Aug 2024 14:48:48 +0000 (31 16:48 +0200)
committerSven Verdoolaege <sven.verdoolaege@gmail.com>
Sun, 1 Sep 2024 10:46:57 +0000 (1 12:46 +0200)
Since isl-0.26-13-g55d9c2394e (generate interfaces in source tree,
Sat Mar 18 17:45:40 2023 +0100), the generated interfaces
are stored in the source tree so that they can also be stored
in the git repository.

In general, it is not a good idea to modify the source tree
when building out of the source tree.
In particular, the source tree may be read-only.
Therefore, only copy the interfaces to the source tree
when it is actually needed for updating the git repository,
i.e., when the generated interfaces are different from
the ones currently in the source tree.

This means the timestamps of the files in the source tree
will not be updated and so the rule for making these files
will trigger every time the files are needed.
The files are therefore first generated in the build tree and
then copied to the source tree when needed.
This compare-and-copy should be fairly quick and is therefore
made completely silent by default.

Note that if it is only the files themselves that are read-only
then it may still be possible to use "mv -f" or to touch the files,
but the current solution is more general.

Signed-off-by: Sven Verdoolaege <sven.verdoolaege@gmail.com>
.gitignore
Makefile.am
cp_if_different.sh [new file with mode: 0755]

index e39f5c3..0326282 100644 (file)
@@ -4,6 +4,7 @@
 *.la
 
 .deps/
+.gen/
 .libs/
 Makefile
 Makefile.in
index 1b8af62..29371d9 100644 (file)
@@ -365,56 +365,67 @@ libdep_a_SOURCES = dep.c
 
 if HAVE_CLANG
 if HAVE_CXX11
-$(srcdir)/interface/isl.py.core: interface/extract_interface$(BUILD_EXEEXT) \
-               libdep.a
-       $(AM_V_GEN)interface/extract_interface$(BUILD_EXEEXT) \
+CP_IF_DIFFERENT = "$(srcdir)/cp_if_different.sh"
+.gen/isl.py.core: interface/extract_interface$(BUILD_EXEEXT) libdep.a
+       $(AM_V_GEN)$(MKDIR_P) ".gen" && \
+       interface/extract_interface$(BUILD_EXEEXT) \
                --language=python $(includes) $(srcdir)/all.h \
-               > interface/isl.py.Tcore && mv interface/isl.py.Tcore $@
+               > .gen/isl.py.Tcore && mv .gen/isl.py.Tcore $@
+$(srcdir)/interface/isl.py.core: .gen/isl.py.core
+       $(AM_V_at)$(CP_IF_DIFFERENT) .gen/isl.py.core $@
 
-$(srcdir)/include/isl/cpp.h: interface/extract_interface$(BUILD_EXEEXT) \
+.gen/cpp.h: interface/extract_interface$(BUILD_EXEEXT) \
                libdep.a cpp/cpp.h.top cpp/cpp.h.bot
-       $(AM_V_GEN)$(MKDIR_P) "include/isl" && \
+       $(AM_V_GEN)$(MKDIR_P) ".gen" && \
        (cat $(srcdir)/cpp/cpp.h.top $(srcdir)/all.h && \
                interface/extract_interface$(BUILD_EXEEXT) --language=cpp \
                        $(includes) $(srcdir)/all.h && \
                cat $(srcdir)/cpp/cpp.h.bot) \
-                       > interface/cpp.Th && mv interface/cpp.Th $@
+                       > .gen/cpp.Th && mv .gen/cpp.Th $@
+$(srcdir)/include/isl/cpp.h: .gen/cpp.h
+       $(AM_V_at)$(CP_IF_DIFFERENT) .gen/cpp.h $@
 
-$(srcdir)/include/isl/cpp-checked.h: \
+.gen/cpp-checked.h: \
                interface/extract_interface$(BUILD_EXEEXT) libdep.a \
                cpp/cpp-checked.h.top cpp/cpp-checked.h.bot
-       $(AM_V_GEN)$(MKDIR_P) "include/isl" && \
+       $(AM_V_GEN)$(MKDIR_P) ".gen" && \
        (cat $(srcdir)/cpp/cpp-checked.h.top $(srcdir)/all.h && \
                interface/extract_interface$(BUILD_EXEEXT) \
                        --language=cpp-checked \
                        $(includes) $(srcdir)/all.h && \
                cat $(srcdir)/cpp/cpp-checked.h.bot) \
-                       > interface/cpp-checked.Th && \
-                       mv interface/cpp-checked.Th $@
+                       > .gen/cpp-checked.Th && \
+                       mv .gen/cpp-checked.Th $@
+$(srcdir)/include/isl/cpp-checked.h: .gen/cpp-checked.h
+       $(AM_V_at)$(CP_IF_DIFFERENT) .gen/cpp-checked.h $@
 
-$(srcdir)/include/isl/cpp-checked-conversion.h: \
+.gen/cpp-checked-conversion.h: \
                interface/extract_interface$(BUILD_EXEEXT) \
                libdep.a \
                cpp/cpp-checked-conversion.h.top \
                cpp/cpp-checked-conversion.h.bot
-       $(AM_V_GEN)$(MKDIR_P) "include/isl" && \
+       $(AM_V_GEN)$(MKDIR_P) ".gen" && \
        (cat $(srcdir)/cpp/cpp-checked-conversion.h.top && \
                interface/extract_interface$(BUILD_EXEEXT) \
                        --language=cpp-checked-conversion \
                        $(includes) $(srcdir)/all.h && \
                cat $(srcdir)/cpp/cpp-checked-conversion.h.bot) \
-                       > interface/cpp-checked-conversion.Th && \
-                       mv interface/cpp-checked-conversion.Th $@
+                       > .gen/cpp-checked-conversion.Th && \
+                       mv .gen/cpp-checked-conversion.Th $@
+$(srcdir)/include/isl/cpp-checked-conversion.h: .gen/cpp-checked-conversion.h
+       $(AM_V_at)$(CP_IF_DIFFERENT) .gen/cpp-checked-conversion.h $@
 
-$(srcdir)/include/isl/typed_cpp.h: interface/extract_interface$(BUILD_EXEEXT) \
+.gen/typed_cpp.h: interface/extract_interface$(BUILD_EXEEXT) \
                libdep.a cpp/typed_cpp.h.top cpp/typed_cpp.h.bot
-       $(AM_V_GEN)$(MKDIR_P) "include/isl" && \
+       $(AM_V_GEN)$(MKDIR_P) ".gen" && \
        (cat $(srcdir)/cpp/typed_cpp.h.top && \
                interface/extract_interface$(BUILD_EXEEXT) \
                        --language=template-cpp \
                        $(includes) $(srcdir)/all.h && \
                cat $(srcdir)/cpp/typed_cpp.h.bot) \
-                       > interface/typed_cpp.Th && mv interface/typed_cpp.Th $@
+                       > .gen/typed_cpp.Th && mv .gen/typed_cpp.Th $@
+$(srcdir)/include/isl/typed_cpp.h: .gen/typed_cpp.h
+       $(AM_V_at)$(CP_IF_DIFFERENT) .gen/typed_cpp.h $@
 endif
 endif
 
@@ -511,6 +522,11 @@ CLEANFILES = \
        interface/__pycache__/*.pyc
 
 DISTCLEANFILES = \
+       .gen/cpp.h \
+       .gen/cpp-checked-conversion.h \
+       .gen/cpp-checked.h \
+       .gen/isl.py.core \
+       .gen/typed_cpp.h \
        isl-uninstalled.sh \
        isl-uninstalled.pc \
        isl.pc \
@@ -694,6 +710,7 @@ EXTRA_DIST = \
        isl_test_cpp_failed.sh \
        isl_test_cpp17-generic.cc \
        isl_test_python.py \
+       cp_if_different.sh \
        test_inputs
 
 dist-hook:
diff --git a/cp_if_different.sh b/cp_if_different.sh
new file mode 100755 (executable)
index 0000000..f321a8d
--- /dev/null
@@ -0,0 +1,10 @@
+#/bin/sh
+# Copy $SRC to $DST unless $DST already exists and has the same contents.
+SRC="$1"
+DST="$2"
+
+if cmp -s "$SRC" "$DST" 2>/dev/null; then
+    :
+else
+    cp "$SRC" "$DST"
+fi