From 7dada30465c6784daa249e4ee0b8cee99e9cfe92 Mon Sep 17 00:00:00 2001
From: erwan <erwan.jahier@univ-grenoble-alpes.fr>
Date: Tue, 6 Jul 2021 15:34:10 +0200
Subject: [PATCH] Chore: generate the lib/lutilsVersion.ml directly via dune
 (thanks kit-ty-kate)

---
 Makefile                |  3 +--
 Makefile.dev            | 18 +++---------------
 Makefile.version        |  9 ---------
 lib/dune                | 17 +++++++++++------
 lib/generate-version.sh |  8 ++++++++
 lutils.opam             |  9 +++++----
 6 files changed, 28 insertions(+), 36 deletions(-)
 create mode 100755 lib/generate-version.sh

diff --git a/Makefile b/Makefile
index 356e565..f816ffc 100644
--- a/Makefile
+++ b/Makefile
@@ -2,7 +2,7 @@
 all:build
 
 -include ./Makefile.version
-build:  lib/lutilsVersion.ml
+build: 
 	dune build @install
 
 install:
@@ -13,7 +13,6 @@ uninstall:
 
 clean:
 	dune clean
-	rm -f lib/lutilsVersion.ml
 
 odoc:
 	 dune build  @doc
diff --git a/Makefile.dev b/Makefile.dev
index e62ba31..1a5ecfd 100644
--- a/Makefile.dev
+++ b/Makefile.dev
@@ -40,20 +40,12 @@ test:
 test-batch:
 	cd test ; make test-batch
 
-#############################
-# tags
-
-OTAGS=otags
-# otags don't manage to parse gnuplotRif.ml
-NO_TAGS=gnuplotRif.ml
-tags:
-	$(OTAGS) -v $(shell ocamlc -where)/*.mli  $(shell ls src/*.ml | grep -v $(NO_TAGS))
 
 ###############################
 # opam-ing
 
 NAME=lutils
-SRC=lib bin emacs README.org LICENSE Makefile Makefile.version *.opam
+SRC=lib bin emacs README.org LICENSE Makefile Makefile.version *.opam dune-project 
 
 
 $(NAME).$(VERSION).tgz: $(SRC)
@@ -65,13 +57,9 @@ opam-rel : $(NAME).$(VERSION).tgz
 opam-test : $(NAME).$(VERSION).tgz
 	make-opam-pack $(NAME).$(VERSION) $(NAME) -test
 
-
 ###############################
 # pushing onto the official repo
-WWW="/import/www/DIST-TOOLS/SYNCHRONE"
-OPAM_FILE=$(shell find  $(WWW)/opam-repository/packages/$(NAME) -name opam -cnewer opam | head -1 | sed -e 's/^./\U&/')
-OPAM_DIR=`dirname $(OPAM_FILE)`
-
+TGZ=http://www-verimag.imag.fr/DIST-TOOLS/SYNCHRONE/pool/$(NAME).$(VERSION).tgz
 opam-pr:
-	cp -r $(OPAM_DIR) /home/jahier/local/opam-repository/packages/$(NAME)
+	echo "opam publish $(TGZ) ."
 
diff --git a/Makefile.version b/Makefile.version
index 5fdf1b1..1b07c68 100644
--- a/Makefile.version
+++ b/Makefile.version
@@ -3,12 +3,3 @@
 SHA:=$(shell git log -1 --pretty=format:"%h" || echo "opam")
 BRANCH:=$(shell git branch | grep "*" | cut -d ' ' -f 2 || basename `pwd` | echo "opam")
 VERSION=$(shell git describe --tags || basename `pwd` | cut -d '.' -f2-4)
-
-del_version:
-	rm -f lib/lutilsVersion.ml
-
-gen_version: del_version src/lutilsVersion.ml 
-
-lib/lutilsVersion.ml:
-	echo "let str=\"$(VERSION)\"" > lib/lutilsVersion.ml ; \
-	echo "let sha=\"$(SHA)\"" >> lib/lutilsVersion.ml 
diff --git a/lib/dune b/lib/dune
index dcc4034..40a5ffa 100644
--- a/lib/dune
+++ b/lib/dune
@@ -1,7 +1,12 @@
 (library
-  (name lutils)
-  (public_name lutils)
-  (libraries unix str num)
-  (wrapped false)
-  (synopsis "A lib shared by Verimag/synchronous tools (lustre-v6, lutin, rdbg).")
-)
+ (name lutils)
+ (public_name lutils)
+ (libraries unix str num)
+ (wrapped false)
+ (synopsis "A lib shared by Verimag/synchronous tools (lustre-v6, lutin, rdbg).")
+ )
+
+(rule
+ (targets lutilsVersion.ml)
+ (deps generate-version.sh)
+ (action (run ./generate-version.sh)))
diff --git a/lib/generate-version.sh b/lib/generate-version.sh
new file mode 100755
index 0000000..f8913bd
--- /dev/null
+++ b/lib/generate-version.sh
@@ -0,0 +1,8 @@
+#!/bin/sh
+
+set -e
+
+SHA=$(git log -1 --pretty=format:"%h" || echo "opam")
+VERSION=$(git describe --tags || echo "${1}")
+echo "let str=\"${VERSION}\"" > lutilsVersion.ml
+echo "let sha=\"${SHA}\"" >> lutilsVersion.ml 
\ No newline at end of file
diff --git a/lutils.opam b/lutils.opam
index e2accaf..21d91ca 100644
--- a/lutils.opam
+++ b/lutils.opam
@@ -1,7 +1,7 @@
 opam-version: "2.0"
 maintainer: "erwan.jahier@imag.fr"
 authors: "Erwan Jahier"
-license: "CeCILL"
+license: "CeCILL-2.1"
 homepage:
   "https://gricad-gitlab.univ-grenoble-alpes.fr/verimag/synchrone/lutils/"
 bug-reports:
@@ -16,14 +16,15 @@ depends: [
   "num"
 ]
 build: [
-  [make "build"]
-]
+  [make "lib/lutilsVersion.ml"]
+  ["dune" "build" "-p" name "-j" jobs]
+  ]
 install: [make "install"]
 post-messages:
   "The last version can be obtained via (opam repo add) http://www-verimag.imag.fr/DIST-TOOLS/SYNCHRONE/opam-repository/"
 dev-repo:
   "git+https://gricad-gitlab.univ-grenoble-alpes.fr/verimag/synchrone/lutils.git"
-synopsis: "Tools and libs shared by Verimag/synchronous tools (lustre, lutin, rdbg)."
+synopsis: "Tools and libs shared by Verimag/synchronous tools (lustre, lutin, rdbg)"
 description: """
 The lutils library contains various modules shared between tools developped at
 Verimag in the synchronous group. Those modules deal with:
-- 
GitLab