From 0efc524b5c1e3deb0e612bf501a487e5ba6c77f3 Mon Sep 17 00:00:00 2001
From: Erik Kooistra <kooistra@astron.nl>
Date: Fri, 26 Sep 2014 13:47:27 +0000
Subject: [PATCH] If there are compile scripts for IP files then first compile
 those into the work library.

---
 tools/modelsim/commands.do | 25 +++++++++++++++++++++++++
 1 file changed, 25 insertions(+)

diff --git a/tools/modelsim/commands.do b/tools/modelsim/commands.do
index 1141f2e4aa..475dc5b48f 100644
--- a/tools/modelsim/commands.do
+++ b/tools/modelsim/commands.do
@@ -216,6 +216,14 @@ proc mk_compile {arg_lib} {
         vdel -lib $sim/work -all
     }
     vlib work
+    # if there are compile scripts for IP files then first compile those into this work
+    global env   ;# Make global env() variable known locally. This is necessary for $env(*) in compile IP tcl script, alternatively use $::env(*) in compile IP tcl scrip
+    set compile_ip [read_lib_compile_ip_file $arg_lib]
+    foreach ip $compile_ip {
+        echo "do $ip"
+        do $ip
+    }
+    # and then compile the HDL
     project compileall
 }
 
@@ -312,6 +320,23 @@ proc read_lib_compile_order_file {arg_lib} {
     return $lib_names
 }
 
+proc read_lib_compile_ip_file {arg_lib} {
+    set sim [simdir $arg_lib]
+    set file_name $arg_lib
+    append file_name "_lib_compile_ip.txt"
+    if {[file exists "$sim/$file_name"]} then {
+        set fp [open $sim/$file_name]
+        set data [read $fp]
+        set data [string trim $data]  ;# trim any trailing white space
+        close $fp
+        set compile_ip [split $data]
+        echo $compile_ip
+        return $compile_ip
+    } else {
+        return
+    }
+}
+
 # Compute simulation directory where the mpf is located
 proc simdir {arg_lib} {
     set project_libs [read_modelsim_project_files_file]
-- 
GitLab