Skip to content

Commit

Permalink
Merge pull request #6 from xeonxu/ccache
Browse files Browse the repository at this point in the history
Use multi-thread and ccache to speed up compilation
  • Loading branch information
houqp committed Apr 8, 2013
2 parents 141b9c0 + 7137844 commit 21a34af
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 9 deletions.
20 changes: 11 additions & 9 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
include Makefile.defs

PROCESSORS:=$(shell grep processor /proc/cpuinfo|wc -l)

all: koreader-base extr

koreader-base: koreader-base.o einkfb.o pdf.o blitbuffer.o drawcontext.o koptcontext.o input.o $(POPENNSLIB) util.o ft.o lfs.o mupdfimg.o $(MUPDFLIBS) $(THIRDPARTYLIBS) $(LUALIB) djvu.o $(DJVULIBS) cre.o $(CRELIB) $(CRE_3RD_LIBS) pic.o lua_gettext.o pic_jpeg.o $(K2PDFOPTLIB)
Expand Down Expand Up @@ -114,11 +116,11 @@ cleanthirdparty:
$(MUPDFLIBS) $(THIRDPARTYLIBS):
# build only thirdparty libs, libfitz and pdf utils, which will care for libmupdf.a being built
ifdef EMULATE_READER
$(MAKE) -C mupdf XCFLAGS="$(CFLAGS) -DNOBUILTINFONT" build="release" CC="$(CC)" MUPDF= MU_APPS= BUSY_APP= XPS_APPS= verbose=1 NOX11=yes
$(MAKE) -j$(PROCESSORS) -C mupdf XCFLAGS="$(CFLAGS) -DNOBUILTINFONT" build="release" CC="$(CC)" MUPDF= MU_APPS= BUSY_APP= XPS_APPS= verbose=1 NOX11=yes
else
# generate data headers
$(MAKE) -C mupdf generate build="release"
$(MAKE) -C mupdf XCFLAGS="$(CFLAGS) -DNOBUILTINFONT" build="release" CC="$(CC)" MUPDF= MU_APPS= BUSY_APP= XPS_APPS= verbose=1 NOX11=yes CROSSCOMPILE=yes OS=Kindle
$(MAKE) -j$(PROCESSORS) -C mupdf generate build="release"
$(MAKE) -j$(PROCESSORS) -C mupdf XCFLAGS="$(CFLAGS) -DNOBUILTINFONT" build="release" CC="$(CC)" MUPDF= MU_APPS= BUSY_APP= XPS_APPS= verbose=1 NOX11=yes CROSSCOMPILE=yes OS=Kindle
endif

$(DJVULIBS):
Expand All @@ -128,33 +130,33 @@ ifdef EMULATE_READER
else
cd $(DJVUDIR)/build && CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" LDFLAGS="$(LDFLAGS)" ../configure --disable-desktopfiles --disable-static --enable-shared --host=$(CHOST) --disable-xmltools --disable-largefile
endif
$(MAKE) -C $(DJVUDIR)/build
$(MAKE) -j$(PROCESSORS) -C $(DJVUDIR)/build
test -d $(LIBDIR) || mkdir $(LIBDIR)
cp -a $(DJVULIBDIR)/libdjvulibre.so* $(LIBDIR)

$(CRE_3RD_LIBS) $(CRELIB):
cd $(KPVCRLIBDIR) && rm -rf CMakeCache.txt CMakeFiles && \
CFLAGS="$(CFLAGS)" CXXFLAGS="$(CXXFLAGS)" CC="$(CC)" CXX="$(CXX)" LDFLAGS="$(LDFLAGS)" cmake -D CMAKE_BUILD_TYPE=Release . && \
$(MAKE) VERBOSE=1
$(MAKE) -j$(PROCESSORS) VERBOSE=1
test -d $(LIBDIR) || mkdir $(LIBDIR)
cp -a $(KPVCRLIBDIR)/libcrengine.so $(CRELIB)

$(LUALIB):
ifdef EMULATE_READER
$(MAKE) -C $(LUADIR) BUILDMODE=shared
$(MAKE) -j$(PROCESSORS) -C $(LUADIR) BUILDMODE=shared CC="$(CC)" HOST_CC="$(HOSTCC)"
else
# To recap: build its TARGET_CC from CROSS+CC, so we need HOSTCC in CC. Build its HOST/TARGET_CFLAGS based on CFLAGS, so we need a neutral CFLAGS without arch
$(MAKE) -C $(LUADIR) BUILDMODE=shared CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CFLAGS="$(BASE_CFLAGS)" HOST_CFLAGS="$(HOSTCFLAGS)" TARGET_CFLAGS="$(CFLAGS)" CROSS="$(CHOST)-" TARGET_FLAGS="-DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2"
$(MAKE) -j$(PROCESSORS) -C $(LUADIR) BUILDMODE=shared CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" CFLAGS="$(BASE_CFLAGS)" HOST_CFLAGS="$(HOSTCFLAGS)" TARGET_CFLAGS="$(CFLAGS)" CROSS="$(CCACHE) $(CHOST)-" TARGET_FLAGS="-DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2"
endif
test -d $(LIBDIR) || mkdir $(LIBDIR)
cp -a $(LUADIR)/src/libluajit.so* $(LUALIB)
ln -s libluajit-5.1.so.2 $(LIBDIR)/libluajit-5.1.so

$(POPENNSLIB):
$(MAKE) -C $(POPENNSDIR) CC="$(CC)" AR="$(AR)"
$(MAKE) -j$(PROCESSORS) -C $(POPENNSDIR) CC="$(CC)" AR="$(AR)"

$(K2PDFOPTLIB):
$(MAKE) -C $(K2PDFOPTLIBDIR) BUILDMODE=shared CC="$(CC)" CFLAGS="$(CFLAGS) -O3" AR="$(AR)" all
$(MAKE) -j$(PROCESSORS) -C $(K2PDFOPTLIBDIR) BUILDMODE=shared CC="$(CC)" CFLAGS="$(CFLAGS) -O3" AR="$(AR)" all
test -d $(LIBDIR) || mkdir $(LIBDIR)
cp -a $(K2PDFOPTLIBDIR)/libk2pdfopt.so* $(LIBDIR)

Expand Down
12 changes: 12 additions & 0 deletions Makefile.defs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@ TTF_FONTS_DIR=$(MUPDFDIR)/fonts

SHELL:=/bin/bash
CHOST?=arm-none-linux-gnueabi
# Use ccache in build system by default. Define USE_NO_CCACHE=1 to force disable it.
ifeq ($(USE_NO_CCACHE), 1)
CCACHE:=
else
CCACHE?=$(shell which ccache)
endif
CC:=$(CHOST)-gcc
CXX:=$(CHOST)-g++
STRIP:=$(CHOST)-strip
Expand Down Expand Up @@ -61,6 +67,9 @@ endif
# in that case.

ifdef EMULATE_READER
HOSTCC:=$(strip $(CCACHE) $(HOSTCC))
HOSTCXX:=$(strip $(CCACHE) $(HOSTCXX))
HOSTAR:=$(strip $(CCACHE) $(HOSTAR))
CC:=$(HOSTCC) -g
CXX:=$(HOSTCXX)
AR:=$(HOSTAR)
Expand All @@ -74,6 +83,9 @@ ifdef EMULATE_READER
CXXFLAGS+= $(HOST_ARCH)
LIBDIR=libs-emu
else
CC:=$(strip $(CCACHE) $(CC))
CXX:=$(strip $(CCACHE) $(CXX))
AR:=$(strip $(CCACHE) $(AR))
CFLAGS+= $(ARM_ARCH) $(ARM_BACKWARD_COMPAT_CFLAGS)
CXXFLAGS+= $(ARM_ARCH) $(ARM_BACKWARD_COMPAT_CFLAGS) $(ARM_BACKWARD_COMPAT_CXXFLAGS)
LIBDIR=libs
Expand Down
20 changes: 20 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,26 @@ Follow these steps:
* run `make`. This will build the koreaderbase application which is a Lua
interpreter offering the koreader-base API to Lua scripts.

Use ccache
==========

Ccache can speed up recompilation by caching previous compilations and detecting
when the same compilation is being done again. In other words, it will decrease
build time when the source have been built. Ccache support has been added to
KOReader's build system. Before using it, you need to install a ccache in your
system.

* in ubuntu use:`sudo apt-get install ccache`
* in fedora use:`sudo yum install ccache`
* install from source:
* get latest ccache source from http://ccache.samba.org/download.html
* unarchieve the source package in a directory
* cd to that directory and use:`./configure && make && sudo make install`
* after using ccache, make a clean build will only take 15sec. Enjoy!
* to disable ccache, use `export USE_NO_CCACHE=1` before make.
* for more detail about ccache. visit:

http://ccache.samba.org

Device emulation
================
Expand Down

0 comments on commit 21a34af

Please sign in to comment.