Created
November 30, 2023 19:57
-
-
Save Ronsor/4793c20457aa00f20761c35aee3f46fd to your computer and use it in GitHub Desktop.
Script to amalgamate GGML into a single-file (source + header) library.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh | |
# License: 0BSD, Copyright (C) 2023 Ronsor Labs. | |
# Usage: ./amalgamate.sh path/to/ggml/repo | |
GGML_SRC_H='ggml-impl.h ggml-backend-impl.h ggml-quants.h' | |
GGML_SRC_C='ggml.c ggml-backend.c ggml-quants.c ggml-alloc.c' | |
GGML_INC_H='ggml.h ggml-alloc.h ggml-backend.h' | |
ONE_SRC=ggml_one.c | |
ONE_HDR=ggml_one.h | |
COUNTER=0 | |
cat_without_include() { | |
cat "$1" | grep -E -v '^#include\s+"' | grep -E -v '^#pragma once' | sed "s/ggml_are_same_layout/ggml_are_same_layout_$COUNTER/g" | |
COUNTER=$((COUNTER + 1)) | |
} | |
process_src() { | |
printf '#include "%s"\n' "$ONE_HDR" | |
for x in $GGML_SRC_H; do | |
cat_without_include "$1/src/$x" | |
done | |
for x in $GGML_SRC_C; do | |
cat_without_include "$1/src/$x" | |
done | |
} | |
process_inc() { | |
for x in $GGML_INC_H; do | |
cat_without_include "$1/include/ggml/$x" | |
done | |
} | |
process_src "$1" > $ONE_SRC | |
process_inc "$1" > $ONE_HDR |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment