diff --git a/Makefile b/Makefile index d547776..225052b 100644 --- a/Makefile +++ b/Makefile @@ -9,10 +9,10 @@ SOURCES := $(wildcard *.cpp) OBJS := $(patsubst %.cpp,%.o,$(SOURCES)) SRCDIR = ./src -SRCLIB = $(SRCDIR)/cppjiebalib.a +SRCLIB = $(SRCDIR)/libcppjieba.a # remove the objs after compilation -.INTERMEDIATE: $(OBJS) +.INTERMEDIATE: $(OBJS) *.o .PHONY: clean $(SRCLIB) # Main Targets @@ -24,10 +24,17 @@ all: demo $(CC) $(CCOPT) $< demo: $(OBJS) $(SRCLIB) - $(DOLINK) + $(DOLINK) $(SRCLIB): $(SRCLIB_DEPS) cd $(SRCDIR) && $(MAKE) clean: rm -f *.o *.ut demo + +sinclude $(SOURCES:.cpp=.d) +%.d:%.cpp + @set -e; rm -f $@; \ + $(CC) -MM $< > $@.$$$$; \ + sed 's,\($*\).o[ :]*,\1.o $@ : ,g' < $@.$$$$ > $@; \ + rm -f $@.$$$$ diff --git a/demo.cpp b/demo.cpp index c96fb6d..fb76d28 100644 --- a/demo.cpp +++ b/demo.cpp @@ -1,9 +1,40 @@ #include -#include #include +#include "src/Segment.h" using namespace std; +using namespace CppJieba; + int main() { + Segment segment; + /* + if(!segment.init("./dicts/segdict.utf8.v2.1")) + { + cerr<<"1"< res; + string title; + title = "我来到北京清华大学"; + res.clear(); + segment.extract(title, res); + + title = "特价!camel骆驼 柔软舒适头层牛皮平底凉鞋女 休闲平跟妈妈鞋夏"; + res.clear(); + segment.extract(title, res); + + title = "包邮拉菲草18cm大檐进口草帽子超强遮阳防晒欧美日韩新款夏天 女"; + res.clear(); + segment.extract(title, res); + + title = "2013新款19CM超大檐帽 遮阳草帽子 沙滩帽防晒大檐欧美新款夏天女"; + res.clear(); + segment.extract(title, res); + + segment.destroy(); + */ return 0; } diff --git a/src/Makefile b/src/Makefile index dc512fb..851d984 100644 --- a/src/Makefile +++ b/src/Makefile @@ -5,30 +5,33 @@ LINKOPT = PACKA = ar PACKAOPT = rc DOLINK = $(LINK) $(LINKOPT) -o $@ $^ -DOPACK = $(PACKA) $(PACKAOPT) $@ $? +DOPACK = $(PACKA) $(PACKAOPT) $@ SOURCES := $(wildcard *.cpp) OBJS := $(patsubst %.cpp,%.o,$(SOURCES)) CMDIR = ./cppcommon -CMLIB = $(CMDIR)/cmlib.a +CMLIB = $(CMDIR)/libcm.a -LIBA = cppjiebalib.a +TMPDIR = ./cppjiebatmp + +LIBA = libcppjieba.a # remove the objs after compilation .INTERMEDIATE: -.PHONY: clean $(CMLIB) +.PHONY: clean $(CMLIB) all: $(LIBA) - # This is a suffix rule #.c.o: %.o: %.cpp $(CC) $(CCOPT) $< - -$(LIBA): $(OBJS) $(CMLIB) - $(DOPACK) +$(LIBA): $(OBJS) $(CMLIB) + mkdir $(TMPDIR) + cp $(CMLIB) $(TMPDIR) && cd $(TMPDIR) && ar x `basename $(CMLIB)` + $(DOPACK) $(OBJS) $(TMPDIR)/*.o + rm -rf $(TMPDIR) $(CMLIB): cd $(CMDIR) && $(MAKE) @@ -41,10 +44,10 @@ Segment.ut: Segment.cpp Trie.cpp Segment.h Trie.h globals.h $(CMLIB) $(CC) -o $@ Segment.cpp Trie.cpp -DSEGMENT_UT $(CMLIB) clean: - rm -f *.o *.d *.ut $(LIBA) + rm -f *.o *.d *.ut $(LIBA) + rm -rf $(TMPDIR) cd $(CMDIR) && make clean -sinclude $(SOURCES:.cpp=.d) %.d:%.cpp @set -e; rm -f $@; \ $(CC) -MM $< > $@.$$$$; \