modify makefile for packing lib*.a

This commit is contained in:
gwdwyy 2013-07-11 17:45:00 +08:00
parent 8f64356c87
commit e5f4d05777
3 changed files with 55 additions and 14 deletions

View File

@ -9,10 +9,10 @@ SOURCES := $(wildcard *.cpp)
OBJS := $(patsubst %.cpp,%.o,$(SOURCES)) OBJS := $(patsubst %.cpp,%.o,$(SOURCES))
SRCDIR = ./src SRCDIR = ./src
SRCLIB = $(SRCDIR)/cppjiebalib.a SRCLIB = $(SRCDIR)/libcppjieba.a
# remove the objs after compilation # remove the objs after compilation
.INTERMEDIATE: $(OBJS) .INTERMEDIATE: $(OBJS) *.o
.PHONY: clean $(SRCLIB) .PHONY: clean $(SRCLIB)
# Main Targets # Main Targets
@ -31,3 +31,10 @@ $(SRCLIB): $(SRCLIB_DEPS)
clean: clean:
rm -f *.o *.ut demo 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 $@.$$$$

View File

@ -1,9 +1,40 @@
#include <iostream> #include <iostream>
#include <stdint.h>
#include <fstream> #include <fstream>
#include "src/Segment.h"
using namespace std; using namespace std;
using namespace CppJieba;
int main() int main()
{ {
Segment segment;
/*
if(!segment.init("./dicts/segdict.utf8.v2.1"))
{
cerr<<"1"<<endl;
return 1;
}
//segment.init("dicts/jieba.dict.utf8");
vector<string> 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; return 0;
} }

View File

@ -5,14 +5,16 @@ LINKOPT =
PACKA = ar PACKA = ar
PACKAOPT = rc PACKAOPT = rc
DOLINK = $(LINK) $(LINKOPT) -o $@ $^ DOLINK = $(LINK) $(LINKOPT) -o $@ $^
DOPACK = $(PACKA) $(PACKAOPT) $@ $? DOPACK = $(PACKA) $(PACKAOPT) $@
SOURCES := $(wildcard *.cpp) SOURCES := $(wildcard *.cpp)
OBJS := $(patsubst %.cpp,%.o,$(SOURCES)) OBJS := $(patsubst %.cpp,%.o,$(SOURCES))
CMDIR = ./cppcommon CMDIR = ./cppcommon
CMLIB = $(CMDIR)/cmlib.a CMLIB = $(CMDIR)/libcm.a
LIBA = cppjiebalib.a TMPDIR = ./cppjiebatmp
LIBA = libcppjieba.a
# remove the objs after compilation # remove the objs after compilation
.INTERMEDIATE: .INTERMEDIATE:
@ -20,15 +22,16 @@ LIBA = cppjiebalib.a
all: $(LIBA) all: $(LIBA)
# This is a suffix rule # This is a suffix rule
#.c.o: #.c.o:
%.o: %.cpp %.o: %.cpp
$(CC) $(CCOPT) $< $(CC) $(CCOPT) $<
$(LIBA): $(OBJS) $(CMLIB) $(LIBA): $(OBJS) $(CMLIB)
$(DOPACK) mkdir $(TMPDIR)
cp $(CMLIB) $(TMPDIR) && cd $(TMPDIR) && ar x `basename $(CMLIB)`
$(DOPACK) $(OBJS) $(TMPDIR)/*.o
rm -rf $(TMPDIR)
$(CMLIB): $(CMLIB):
cd $(CMDIR) && $(MAKE) cd $(CMDIR) && $(MAKE)
@ -42,9 +45,9 @@ Segment.ut: Segment.cpp Trie.cpp Segment.h Trie.h globals.h $(CMLIB)
clean: clean:
rm -f *.o *.d *.ut $(LIBA) rm -f *.o *.d *.ut $(LIBA)
rm -rf $(TMPDIR)
cd $(CMDIR) && make clean cd $(CMDIR) && make clean
sinclude $(SOURCES:.cpp=.d)
%.d:%.cpp %.d:%.cpp
@set -e; rm -f $@; \ @set -e; rm -f $@; \
$(CC) -MM $< > $@.$$$$; \ $(CC) -MM $< > $@.$$$$; \