Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up the Makefile #35

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 27 additions & 14 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,25 +1,38 @@
CXX ?= g++
CFLAGS = -Wall -Wconversion -O3 -fPIC
SHVER = 2
OS = $(shell uname)
OS := $(shell uname)

all: svm-train svm-predict svm-scale
all: svm-train svm-predict svm-scale lib

lib: svm.o
if [ "$(OS)" = "Darwin" ]; then \
SHARED_LIB_FLAG="-dynamiclib -Wl,-install_name,libsvm.so.$(SHVER)"; \
else \
SHARED_LIB_FLAG="-shared -Wl,-soname,libsvm.so.$(SHVER)"; \
fi; \
$(CXX) $${SHARED_LIB_FLAG} svm.o -o libsvm.so.$(SHVER)
ifeq ($(OS),Darwin)
DLLEXT := dylib
SHARED_LIB_FLAG = -dynamiclib
else
DLLEXT := so
SHARED_LIB_FLAG = -shared
endif

libsvm.$(DLLEXT): svm.o
$(CXX) $(SHARED_LIB_FLAG) $^ -o $@

libsvm.$(DLLEXT).$(SHVER): libsvm.$(DLLEXT)
ln $< $@

libsvm.a: svm.o
ar rc $@ $^
ranlib $@

.PHONY: lib
lib: libsvm.$(DLLEXT).$(SHVER) libsvm.a

svm-predict: svm-predict.c svm.o
$(CXX) $(CFLAGS) svm-predict.c svm.o -o svm-predict -lm
$(CXX) $(CFLAGS) $^ -o $@ -lm
svm-train: svm-train.c svm.o
$(CXX) $(CFLAGS) svm-train.c svm.o -o svm-train -lm
$(CXX) $(CFLAGS) $^ -o $@ -lm
svm-scale: svm-scale.c
$(CXX) $(CFLAGS) svm-scale.c -o svm-scale
$(CXX) $(CFLAGS) $^ -o svm-scale
svm.o: svm.cpp svm.h
$(CXX) $(CFLAGS) -c svm.cpp
$(CXX) $(CFLAGS) -c $<

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

out of curiosity: Couldn't we use implicit make rules for the 4 targets above?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes. 100%. I can add these, or you can fork my branch, PR me, and I'll pull, if you want the credit in the log for it.

Unfortunately I don't think the authors pay close attention to this repo---their official one seems private---so we will have to wait a while to see what they think.

clean:
rm -f *~ svm.o svm-train svm-predict svm-scale libsvm.so.$(SHVER)
rm -f *~ svm.o svm-train svm-predict svm-scale libsvm.$(DLLEXT).$(SHVER) libsvm.a
7 changes: 5 additions & 2 deletions Makefile.win
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,11 @@ $(TARGET)\svm-toy.exe: svm.h svm.obj svm-toy\windows\svm-toy.cpp
svm.obj: svm.cpp svm.h
$(CXX) $(CFLAGS) -c svm.cpp

lib: svm.cpp svm.h svm.def
$(CXX) $(CFLAGS) -LD svm.cpp -Fe$(TARGET)\libsvm -link -DEF:svm.def
$(TARGET)\svm.dll $(TARGET)\svm.lib $(TARGET)\svm.exp: svm.cpp svm.h svm.def
$(CXX) $(CFLAGS) -LD svm.obj -Fe$(TARGET)\svm -link -DEF:svm.def

.PHONY: lib
lib: $(TARGET)\svm.dll $(TARGET)\svm.lib $(TARGET)\svm.exp

clean:
-erase /Q *.obj $(TARGET)\.
Expand Down
2 changes: 1 addition & 1 deletion svm.def
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
LIBRARY libsvm
LIBRARY svm
EXPORTS
svm_train @1
svm_cross_validation @2
Expand Down