From cb4fe3ad9eec25f745c5fd19666961304feac96f Mon Sep 17 00:00:00 2001
From: Giovanni Bussi <giovanni.bussi@gmail.com>
Date: Thu, 2 Jan 2014 18:18:07 +0100
Subject: [PATCH] Support for explicit include files

Instead of using links to other source directories
we now use explicit include files. The approach is more
robust.

Closes #69
---
 src/maketools/cleanlinks.sh |  9 +++++++++
 src/maketools/make.module   |  4 ++--
 src/maketools/makelinks.sh  | 32 ++++++++++++++++++++++++++++++++
 3 files changed, 43 insertions(+), 2 deletions(-)
 create mode 100755 src/maketools/cleanlinks.sh
 create mode 100755 src/maketools/makelinks.sh

diff --git a/src/maketools/cleanlinks.sh b/src/maketools/cleanlinks.sh
new file mode 100755
index 000000000..856de79e9
--- /dev/null
+++ b/src/maketools/cleanlinks.sh
@@ -0,0 +1,9 @@
+#! /bin/bash
+
+for file in *
+do
+  test -d $file && test -e $file/.tmpdir && rm -fr $file/
+  test -L $file && rm -fr $file
+done
+# this echo is to avoid triggering errors when last test fails
+echo links removed
diff --git a/src/maketools/make.module b/src/maketools/make.module
index 8957c52f5..45a4e44d6 100644
--- a/src/maketools/make.module
+++ b/src/maketools/make.module
@@ -33,7 +33,7 @@ all:
 
 links: Makefile
 	@echo Create links to modules used in $(CURDIR) to simplify header inclusion:
-	@for dir in $(USE) ; do test -L $$dir || ln -fs ../$$dir . && echo "   " $$dir ;  done
+	@for dir in $(USE) ; do ../maketools/makelinks.sh $$dir ;  done
 	@echo Touching a file used to track links update
 	touch links
 	@echo Acting recursively
@@ -62,7 +62,7 @@ endif
 
 .PHONY: clean
 clean:
-	-for file in * ; do test -L $$file && rm -f $$file ; done
+	../maketools/cleanlinks.sh
 	rm -fr deps links
 	rm -f $(CLEANLIST)
 
diff --git a/src/maketools/makelinks.sh b/src/maketools/makelinks.sh
new file mode 100755
index 000000000..3a79bb640
--- /dev/null
+++ b/src/maketools/makelinks.sh
@@ -0,0 +1,32 @@
+#! /bin/bash
+
+dir=$1
+
+# this is old style behavior, i.e. generate symbolic links
+# rm -fr $dir
+# ln -s ../$dir $dir
+# exit
+
+# the new implementation follows
+
+# remove links (possibly remaining from compilation with old makefiles):
+test -L $dir && rm $dir
+
+mkdir -p $dir
+
+echo "This file indicates this is a temporary directory" >  $dir/.tmpdir
+
+for file in ../$dir/*.h
+do
+  name="${file##*/}"
+  text="#include \"../../$dir/$name\""
+# files are replaces only if changed
+  cmp -s <(echo "$text") $dir/$name > /dev/null  2> /dev/null || echo "$text" > $dir/$name
+done
+
+# then erase not existent files
+for file in $dir/*.h
+do
+  name="${file##*/}"
+  test -f "../$dir/$name" || rm $file
+done
-- 
GitLab