$NetBSD: patch-Makefile,v 1.6 2025/01/05 09:12:32 adam Exp $

Use LIBTOOL.
Add support for LDFLAGS.

--- Makefile.orig	2023-07-09 12:45:51.000000000 +0000
+++ Makefile
@@ -1,34 +1,29 @@
 CXX ?= g++
 CC ?= gcc
-CFLAGS = -Wall -Wconversion -O3 -fPIC
-LIBS = blas/blas.a
+LIBS = blas/libblas.la
 #LIBS = -lblas
 SHVER = 6
-OS = $(shell uname)
-ifeq ($(OS),Darwin)
-	SHARED_LIB_FLAG = -dynamiclib -Wl,-install_name,liblinear.so.$(SHVER)
-else
-	SHARED_LIB_FLAG = -shared -Wl,-soname,liblinear.so.$(SHVER)
-endif
 
 all: train predict
 
-lib: linear.o newton.o blas/blas.a
-	$(CXX) $(SHARED_LIB_FLAG) linear.o newton.o blas/blas.a -o liblinear.so.$(SHVER)
+lib: linear.lo newton.lo $(LIBS)
+	${LIBTOOL} --mode=link $(CXX) -o liblinear.la $(LDFLAGS) $> -rpath ${PREFIX}/lib -version-info ${SHVER}:0
 
-train: newton.o linear.o train.c blas/blas.a
-	$(CXX) $(CFLAGS) -o train train.c newton.o linear.o $(LIBS)
+train: newton.lo linear.lo train.c $(LIBS)
+	${LIBTOOL} --mode=link $(CXX) $(CFLAGS) -o train $(LDFLAGS) $>
 
-predict: newton.o linear.o predict.c blas/blas.a
-	$(CXX) $(CFLAGS) -o predict predict.c newton.o linear.o $(LIBS)
+predict: newton.lo linear.lo predict.c $(LIBS)
+	${LIBTOOL} --mode=link $(CXX) $(CFLAGS) -o predict $(LDFLAGS) $>
 
-newton.o: newton.cpp newton.h
+newton.lo: newton.cpp newton.h
+	${LIBTOOL} --mode=compile \
 	$(CXX) $(CFLAGS) -c -o newton.o newton.cpp
 
-linear.o: linear.cpp linear.h
+linear.lo: linear.cpp linear.h
+	${LIBTOOL} --mode=compile \
 	$(CXX) $(CFLAGS) -c -o linear.o linear.cpp
 
-blas/blas.a: blas/*.c blas/*.h
+$(LIBS): blas/*.c blas/*.h
 	make -C blas OPTFLAGS='$(CFLAGS)' CC='$(CC)';
 
 clean:
