File size: 3,523 Bytes
caddd62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
#!/usr/bin/env bash
# Copyright (c) 2026 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0

set -euo pipefail

repo_root="$(cd "$(dirname "${BASH_SOURCE[0]}")/.." && pwd)"
technology="${repo_root}/technology"
public_pdk="${repo_root}/ihp13/pdk"
quiet=0

usage() {
    cat <<'EOF'
Usage: scripts/setup_technology.sh [--quiet]

Create technology -> ihp13/pdk if no active technology view exists.
If technology/ already exists, leave it unchanged. Cockpit may link missing
files from ihp13/pdk into its active technology view.
EOF
}

while [[ $# -gt 0 ]]; do
    case "$1" in
        --quiet)
            quiet=1
            shift
            ;;
        -h|--help)
            usage
            exit 0
            ;;
        *)
            echo "[ERROR] Unknown argument: $1" >&2
            usage >&2
            exit 1
            ;;
    esac
done

log() {
    if [[ "$quiet" -eq 0 ]]; then
        echo "$@"
    fi
}

link_cmos5l_klayout_dependencies() {
    local shared_pdk="$repo_root/ihp13/sg13g2/ihp-sg13g2"
    local upstream_layout="$repo_root/ihp13/ihp-sg13g2"

    [[ ! -d "$shared_pdk" || -e "$upstream_layout" || -L "$upstream_layout" ]] && return 0
    ln -s "sg13g2/ihp-sg13g2" "$upstream_layout"
}

link_missing_public_files() {
    [[ ! -d "$public_pdk" || ! -d "$technology" ]] && return 0
    [[ "$(realpath -m "$technology")" == "$(realpath -m "$public_pdk")" ]] && return 0

    for pdk_dir in lib lef verilog gds; do
        mkdir -p "$technology/$pdk_dir"
        for public_file in "$public_pdk"/"$pdk_dir"/*; do
            [[ -f "$public_file" ]] || continue

            file_name="$(basename "$public_file")"
            [[ -e "$technology/$pdk_dir/$file_name" || -L "$technology/$pdk_dir/$file_name" ]] && continue
            ln -s "../../ihp13/pdk/$pdk_dir/$file_name" "$technology/$pdk_dir/$file_name"
        done
    done
}

create_public_technology_link() {
    if [[ -L "$technology" && ! -e "$technology" ]]; then
        local link_target
        link_target="$(readlink "$technology")"

        if [[ "$link_target" != "ihp13/pdk" ]]; then
            echo "[ERROR] Unexpected dangling technology link: $technology -> $link_target" >&2
            exit 1
        fi

        if [[ ! -d "$public_pdk" ]]; then
            echo "[ERROR] Cannot recreate technology link; public PDK mirror missing: $public_pdk" >&2
            exit 1
        fi

        rm "$technology"
        ln -s ihp13/pdk "$technology"
        log "[INFO] Recreated technology -> ihp13/pdk"
        return
    fi

    [[ ! -e "$technology" && ! -L "$technology" ]] || return 0

    if [[ ! -d "$public_pdk" ]]; then
        echo "[ERROR] Public PDK mirror missing: $public_pdk" >&2
        exit 1
    fi

    ln -s ihp13/pdk "$technology"
    log "[INFO] Created technology -> ihp13/pdk"
}

create_public_technology_link
link_cmos5l_klayout_dependencies

if [[ ! -f "$public_pdk/verilog/sg13g2_stdcell.v" ]]; then
    echo "[ERROR] Missing public standard-cell source: $public_pdk/verilog/sg13g2_stdcell.v" >&2
    exit 1
fi

if [[ -e "$technology" ]]; then
    link_missing_public_files
    log "[INFO] Active technology view: $technology"
    if [[ "$(realpath -m "$technology")" == "$(realpath -m "$public_pdk")" ]]; then
        log "[INFO] Source: public mirror ihp13/pdk"
    else
        log "[INFO] Source: local technology directory"
        log "[INFO] Leaving active technology view unchanged"
    fi
fi