@@ -46,11 +46,34 @@ endif
46
46
# warnings
47
47
CXXFLAGS += -Wall -Wextra -Wpedantic -Wcast-qual -Wno-unused-function
48
48
49
+ # Find all .a archives in ARCHIVE_DIR
50
+ # (ggml can have different backends cpu, cuda, etc., each backend generates a .a archive)
51
+ GGML_ARCHIVE_DIR := build/ggml/src/
52
+ ALL_ARCHIVES := $(shell find $(GGML_ARCHIVE_DIR ) -type f -name '* .a')
53
+
54
+ # Name of the single merged library
55
+ COMBINED_LIB := libggmlall.a
56
+
57
+ # Rule to merge all the .a files into one
58
+ $(COMBINED_LIB ) : $(ALL_ARCHIVES )
59
+ @echo " Merging all .a into $( COMBINED_LIB) "
60
+ rm -f $@
61
+ mkdir -p merge-tmp
62
+ for a in $( ALL_ARCHIVES) ; do \
63
+ ( cd merge-tmp && ar x ../$$ a ); \
64
+ done
65
+ ( cd merge-tmp && ar rcs ../$@ * .o )
66
+ # Ensure we have a proper index
67
+ ranlib $@
68
+ # Clean up
69
+ rm -rf merge-tmp
70
+
49
71
build/libstable-diffusion.a :
50
72
mkdir -p build && \
51
73
cd build && \
52
74
cmake $(CMAKE_ARGS ) ../../../../../sources/stablediffusion-ggml.cpp && \
53
75
cmake --build . --config Release
76
+ $(MAKE ) $(COMBINED_LIB )
54
77
55
78
gosd.o :
56
79
$(CXX ) $(CXXFLAGS ) gosd.cpp -o gosd.o -c
@@ -60,4 +83,4 @@ libsd.a: gosd.o
60
83
$(AR ) rcs libsd.a gosd.o
61
84
62
85
clean :
63
- rm -f gosd.o libsd.a build
86
+ rm -rf gosd.o libsd.a build $( COMBINED_LIB )
0 commit comments