Skip to content

Commit 297d4c6

Browse files
committed
ngspice builds
1 parent 8bc883b commit 297d4c6

File tree

3 files changed

+72
-5
lines changed

3 files changed

+72
-5
lines changed

Docker/Dockerfile

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
FROM ubuntu:latest
22

3+
# Default version is master
4+
ENV VERSION=master
5+
36
RUN apt-get update && apt-get install -y \
47
build-essential \
58
cmake \
@@ -30,7 +33,8 @@ RUN chmod +x /run.sh
3033
ENTRYPOINT ["/run.sh"]
3134

3235
## run this command in WSL2:
33-
## docker run -it -v $(realpath .):/mnt ngspice:emcc
36+
## docker run -it -e VERSION=next -v $(realpath .):/mnt ngspice:emcc
37+
3438

3539

3640

Docker/help.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
docker build --no-cache -t eecircuit .
22
# mkdir build
3-
docker run -t -v $(realpath .):/mnt eecircuit
3+
docker run -it -e VERSION=next -v $(realpath .):/mnt ngspice:emcc
44
node ./inject.js

Docker/run.sh

Lines changed: 66 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
#!/bin/bash
22
echo Entryponit script is Running...
33

4+
echo Installing emscripten...
5+
46
NGSPICE_HOME="https://github.com/danchitnis/ngspice-sf-mirror"
57
#NGSPICE_HOME="https://git.code.sf.net/p/ngspice/ngspice"
68

@@ -13,15 +15,65 @@ cd emsdk
1315
./emsdk activate latest
1416
source ./emsdk_env.sh
1517

18+
echo emscripten is installed
19+
20+
############################################
21+
1622
echo -e "\n"
17-
echo -e "installing ngspice...\n"
23+
echo cloning ngspice repository...
1824

1925
cd /opt
20-
2126
git clone $NGSPICE_HOME ngspice-ngspice
22-
2327
cd ngspice-ngspice
2428

29+
############################################
30+
31+
echo -e "\n"
32+
echo determining the latest release version and branch...
33+
34+
# Step 1: Find the latest tag with the version format "ngspice-X.Y"
35+
latest_tag=$(git tag | grep -E '^ngspice-[0-9]+\.[0-9]+$' | sort -V | tail -n 1)
36+
if [ -z "$latest_tag" ]; then
37+
echo "No ngspice tags found."
38+
exit 1
39+
fi
40+
latest_version=${latest_tag#ngspice-} # Extract version number (e.g., 44.2)
41+
echo "Latest tag: $latest_tag (version $latest_version)"
42+
43+
# Step 2: Find the branch with a higher version than the latest tag.
44+
# We assume branch names are in the form "pre-master-X" or "pre-master-X.Y"
45+
# Extract the version number, sort them, and then pick the first branch with a version > latest_version.
46+
branch_version=$(git branch -r | \
47+
grep -Eo 'pre-master-[0-9]+(\.[0-9]+)?' | \
48+
sed -E 's/.*pre-master-([0-9]+(\.[0-9]+)?)/\1/' | \
49+
sort -V | \
50+
awk -v latest="$latest_version" '{ if ($1+0 > latest+0) { print $1; exit } }')
51+
52+
if [ -n "$branch_version" ]; then
53+
echo "Branch with higher version: pre-master-$branch_version"
54+
else
55+
echo "No branch found with a version higher than $latest_version"
56+
exit 1
57+
fi
58+
59+
############################################
60+
61+
echo -e "\n"
62+
echo "Running build requested is: $VERSION"
63+
64+
if [ "$VERSION" == "next" ]; then
65+
echo "Checking out the branch pre-master-$branch_version"
66+
git checkout pre-master-$branch_version
67+
else
68+
echo "Checking out the master branch for version $latest_version"
69+
fi
70+
71+
############################################
72+
73+
echo -e "\n"
74+
echo "Applying patches..."
75+
76+
2577
#https://www.cyberciti.biz/faq/how-to-use-sed-to-find-and-replace-text-in-files-in-linux-unix-shell/
2678
#https://sourceforge.net/p/ngspice/patches/99/
2779
sed -i 's/-Wno-unused-but-set-variable/-Wno-unused-const-variable/g' ./configure.ac
@@ -30,6 +82,11 @@ sed -i 's|#include "ngspice/ngspice.h"|#include <emscripten.h>\n\n#include "ngsp
3082
sed -i 's|freewl = wlist = getcommand(string);|emscripten_sleep(100);\n\n\t\tfreewl = wlist = getcommand(string);|g' ./src/frontend/control.c
3183

3284

85+
############################################
86+
87+
echo -e "\n"
88+
echo "Building ngspice..."
89+
3390
./autogen.sh
3491
mkdir release
3592
cd release
@@ -46,13 +103,19 @@ emmake make -j
46103

47104
wait
48105

106+
############################################
49107

108+
echo -e "\n"
109+
echo "Copying the build artifacts..."
50110

51111
cd src
52112
mv spice.mjs spice.js
53113
mkdir -p /mnt/build
54114
\cp spice.js spice.wasm /mnt/build
55115

116+
echo "Build artifacts are copied to /mnt/build"
117+
118+
############################################
56119

57120
echo -e "\n"
58121
echo -e "This script is ended\n"

0 commit comments

Comments
 (0)