<commit_before>include Makefile.defs

# main target
all: $(OUTPUT_DIR) $(LUAJIT) $(OUTPUT_DIR)/extr $(OUTPUT_DIR)/sdcv libs
ifndef EMULATE_READER
	$(STRIP) --strip-unneeded \
		$(OUTPUT_DIR)/extr \
		$(OUTPUT_DIR)/sdcv \
		$(LUAJIT) \
		$(OUTPUT_DIR)/*.so*
endif
	# set up some needed paths and links
	ln -sf ../../kpvcrlib/crengine/cr3gui/data $(OUTPUT_DIR)/data
	test -d $(OUTPUT_DIR)/history || mkdir $(OUTPUT_DIR)/history
	test -d $(OUTPUT_DIR)/clipboard || mkdir $(OUTPUT_DIR)/clipboard
	test -e $(OUTPUT_DIR)/data/cr3.css || \
		ln -sf ../../kpvcrlib/cr3.css $(OUTPUT_DIR)/data/
	test -d $(OUTPUT_DIR)/fonts || \
		ln -sf ../../$(TTF_FONTS_DIR) $(OUTPUT_DIR)/fonts
	test -e $(OUTPUT_DIR)/koreader-base || \
		ln -sf ../../koreader-base $(OUTPUT_DIR)/

# convenience target with preconfigured Kobo toolchain settings
kobo:
	TARGET_DEVICE=KOBO CHOST=arm-linux-gnueabihf make

$(OUTPUT_DIR):
	mkdir -p $(OUTPUT_DIR)

# ===========================================================================

# third party libraries:
# (for directory and file name config, see Makefile.defs)

# freetype, fetched via GIT as a submodule
$(FREETYPE_LIB):
	mkdir -p $(FREETYPE_DIR)/build
	cd $(FREETYPE_DIR) && sh autogen.sh
	cd $(FREETYPE_DIR)/build && \
		CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" \
		CXXFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
			../configure --disable-static --enable-shared \
				--without-zlib --without-bzip2 \
				--without-png \
				--host=$(CHOST)
	$(MAKE) -j$(PROCESSORS) -C $(FREETYPE_DIR)/build
	cp -fL $(FREETYPE_DIR)/build/.libs/$(notdir $(FREETYPE_LIB)) $@


# libjpeg, fetched via GIT as a submodule
$(JPEG_LIB):
	cd $(JPEG_DIR) && \
		CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" \
		CXXFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
			./configure --disable-static --enable-shared \
				--host=$(CHOST)
	$(MAKE) -j$(PROCESSORS) -C $(JPEG_DIR)
	cp -fL $(JPEG_DIR)/.libs/$(notdir $(JPEG_LIB)) $@


# mupdf, fetched via GIT as a submodule
# by default, mupdf compiles to a static library:
$(MUPDF_LIB_STATIC) $(MUPDF_THIRDPARTY_LIBS): $(JPEG_LIB) $(FREETYPE_LIB)
	$(MAKE) -j$(PROCESSORS) -C mupdf generate build="release" CC="$(HOSTCC)" \
		OS="Other" verbose=1
	$(MAKE) -j$(PROCESSORS) -C mupdf \
		LDFLAGS="-L../$(OUTPUT_DIR)" \
		XCFLAGS="$(CFLAGS) -DNOBUILTINFONT -fPIC -I../jpeg" \
		CC="$(CC)" \
		build="release" MUDRAW= MUTOOL= NOX11=yes \
		OS="Other" verbose=1 \
		FREETYPE_DIR=nonexisting \
		SYS_FREETYPE_INC="-I../$(FREETYPE_DIR)/include" \
		JPEG_DIR=nonexisting \
		CROSSCOMPILE=yes

# we generate a dynamic library from the static library:
$(MUPDF_LIB): $(MUPDF_LIB_STATIC) \
			$(MUPDF_THIRDPARTY_LIBS) \
			$(JPEG_LIB) \
			$(FREETYPE_LIB)
	$(CC) $(DYNLIB_CFLAGS) -fPIC -shared \
		-Wl,--whole-archive $(MUPDF_LIB_STATIC) \
		-Wl,--no-whole-archive $(MUPDF_THIRDPARTY_LIBS) \
		$(JPEG_LIB) $(FREETYPE_LIB) \
		-o $(MUPDF_LIB)


# djvulibre, fetched via GIT as a submodule
$(DJVULIBRE_LIB):
	mkdir -p $(DJVULIBRE_DIR)/build
	test -e $(DJVULIBRE_DIR)/build/Makefile \
		|| ( cd $(DJVULIBRE_DIR)/build \
		&& CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS) -fPIC" \
		CXXFLAGS="$(CXXFLAGS) -fPIC" LDFLAGS="$(LDFLAGS)" \
		../configure --disable-desktopfiles \
			--disable-static --enable-shared \
			--disable-xmltools --disable-largefile \
			$(if $(EMULATE_READER),,-host=$(CHOST)) )
	$(MAKE) -j$(PROCESSORS) -C $(DJVULIBRE_DIR)/build SUBDIRS_FIRST=libdjvu
	cp -fL $(DJVULIBRE_LIB_DIR)/$(notdir $(DJVULIBRE_LIB)) \
		$(DJVULIBRE_LIB)


# crengine, fetched via GIT as a submodule
$(CRENGINE_THIRDPARTY_LIBS) $(CRENGINE_LIB):
	test -e $(CRENGINE_WRAPPER_DIR)/CMakeFiles \
	|| ( cd $(CRENGINE_WRAPPER_DIR) \
	&& CFLAGS="$(CFLAGS) -fPIC" \
		CXXFLAGS="$(CXXFLAGS) -fPIC" CC="$(CC)" \
		CXX="$(CXX)" LDFLAGS="$(LDFLAGS)" \
		cmake -D CMAKE_BUILD_TYPE=Release . )
	cd $(CRENGINE_WRAPPER_DIR) &&  $(MAKE) VERBOSE=1
	cp -fL $(CRENGINE_WRAPPER_DIR)/$(notdir $(CRENGINE_LIB)) \
		$(CRENGINE_LIB)


# LuaJIT, fetched via GIT as a submodule
$(LUA_LIB) $(LUAJIT):
ifdef EMULATE_READER
	$(MAKE) -j$(PROCESSORS) -C $(LUA_DIR)
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) -j$(PROCESSORS) -C $(LUA_DIR) \
		CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" \
		CFLAGS="$(BASE_CFLAGS)" HOST_CFLAGS="$(HOSTCFLAGS)" \
		TARGET_CFLAGS="$(CFLAGS)" \
		TARGET_FLAGS="-DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2" \
		CROSS="$(strip $(CCACHE) $(CHOST))-"
endif
	# special case: LuaJIT compiles a libluajit.so, which must be named
	# differently when installing
	cp -fL $(LUA_DIR)/src/libluajit.so* $(LUA_LIB)
	cp -fL $(LUA_DIR)/src/$(notdir $(LUAJIT)) $(LUAJIT)


# popen-noshell, fetched via SVN
$(POPEN_NOSHELL_LIB):
	$(MAKE) -j$(PROCESSORS) -C $(POPEN_NOSHELL_DIR) \
		CC="$(CC)" AR="$(AR)" CFLAGS="$(CFLAGS) -fPIC"


# k2pdfopt, fetched via GIT as a submodule
$(K2PDFOPT_LIB) $(LEPTONICA_LIB) $(TESSERACT_LIB):
ifdef EMULATE_READER
	$(MAKE) -j$(PROCESSORS) -C $(K2PDFOPT_DIR) BUILDMODE=shared \
		CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS)" \
		CXX="$(HOSTCXX)" CXXFLAGS="$(HOSTCFLAGS)" \
		AR="$(AR)" EMULATE_READER=1 all
else
	$(MAKE) -j$(PROCESSORS) -C $(K2PDFOPT_DIR) BUILDMODE=shared \
		HOST="$(CHOST)" \
		CC="$(CC)" CFLAGS="$(CFLAGS) -O3" \
		CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" \
		AR="$(AR)" all
endif
	cp -a $(K2PDFOPT_DIR)/libk2pdfopt.so* $(OUTPUT_DIR)/
	cp -a $(K2PDFOPT_DIR)/liblept.so* $(OUTPUT_DIR)/
	cp -a $(K2PDFOPT_DIR)/libtesseract.so* $(OUTPUT_DIR)/<commit_msg>oversight: copy flags for libraries<commit_after>include Makefile.defs

# main target
all: $(OUTPUT_DIR) $(LUAJIT) $(OUTPUT_DIR)/extr $(OUTPUT_DIR)/sdcv libs
ifndef EMULATE_READER
	$(STRIP) --strip-unneeded \
		$(OUTPUT_DIR)/extr \
		$(OUTPUT_DIR)/sdcv \
		$(LUAJIT) \
		$(OUTPUT_DIR)/*.so*
endif
	# set up some needed paths and links
	ln -sf ../../kpvcrlib/crengine/cr3gui/data $(OUTPUT_DIR)/data
	test -d $(OUTPUT_DIR)/history || mkdir $(OUTPUT_DIR)/history
	test -d $(OUTPUT_DIR)/clipboard || mkdir $(OUTPUT_DIR)/clipboard
	test -e $(OUTPUT_DIR)/data/cr3.css || \
		ln -sf ../../kpvcrlib/cr3.css $(OUTPUT_DIR)/data/
	test -d $(OUTPUT_DIR)/fonts || \
		ln -sf ../../$(TTF_FONTS_DIR) $(OUTPUT_DIR)/fonts
	test -e $(OUTPUT_DIR)/koreader-base || \
		ln -sf ../../koreader-base $(OUTPUT_DIR)/

# convenience target with preconfigured Kobo toolchain settings
kobo:
	TARGET_DEVICE=KOBO CHOST=arm-linux-gnueabihf make

$(OUTPUT_DIR):
	mkdir -p $(OUTPUT_DIR)

# ===========================================================================

# third party libraries:
# (for directory and file name config, see Makefile.defs)

# freetype, fetched via GIT as a submodule
$(FREETYPE_LIB):
	mkdir -p $(FREETYPE_DIR)/build
	cd $(FREETYPE_DIR) && sh autogen.sh
	cd $(FREETYPE_DIR)/build && \
		CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" \
		CXXFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
			../configure --disable-static --enable-shared \
				--without-zlib --without-bzip2 \
				--without-png \
				--host=$(CHOST)
	$(MAKE) -j$(PROCESSORS) -C $(FREETYPE_DIR)/build
	cp -fL $(FREETYPE_DIR)/build/.libs/$(notdir $(FREETYPE_LIB)) $@


# libjpeg, fetched via GIT as a submodule
$(JPEG_LIB):
	cd $(JPEG_DIR) && \
		CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS)" \
		CXXFLAGS="$(CFLAGS)" LDFLAGS="$(LDFLAGS)" \
			./configure --disable-static --enable-shared \
				--host=$(CHOST)
	$(MAKE) -j$(PROCESSORS) -C $(JPEG_DIR)
	cp -fL $(JPEG_DIR)/.libs/$(notdir $(JPEG_LIB)) $@


# mupdf, fetched via GIT as a submodule
# by default, mupdf compiles to a static library:
$(MUPDF_LIB_STATIC) $(MUPDF_THIRDPARTY_LIBS): $(JPEG_LIB) $(FREETYPE_LIB)
	$(MAKE) -j$(PROCESSORS) -C mupdf generate build="release" CC="$(HOSTCC)" \
		OS="Other" verbose=1
	$(MAKE) -j$(PROCESSORS) -C mupdf \
		LDFLAGS="-L../$(OUTPUT_DIR)" \
		XCFLAGS="$(CFLAGS) -DNOBUILTINFONT -fPIC -I../jpeg" \
		CC="$(CC)" \
		build="release" MUDRAW= MUTOOL= NOX11=yes \
		OS="Other" verbose=1 \
		FREETYPE_DIR=nonexisting \
		SYS_FREETYPE_INC="-I../$(FREETYPE_DIR)/include" \
		JPEG_DIR=nonexisting \
		CROSSCOMPILE=yes

# we generate a dynamic library from the static library:
$(MUPDF_LIB): $(MUPDF_LIB_STATIC) \
			$(MUPDF_THIRDPARTY_LIBS) \
			$(JPEG_LIB) \
			$(FREETYPE_LIB)
	$(CC) $(DYNLIB_CFLAGS) -fPIC -shared \
		-Wl,--whole-archive $(MUPDF_LIB_STATIC) \
		-Wl,--no-whole-archive $(MUPDF_THIRDPARTY_LIBS) \
		$(JPEG_LIB) $(FREETYPE_LIB) \
		-o $(MUPDF_LIB)


# djvulibre, fetched via GIT as a submodule
$(DJVULIBRE_LIB):
	mkdir -p $(DJVULIBRE_DIR)/build
	test -e $(DJVULIBRE_DIR)/build/Makefile \
		|| ( cd $(DJVULIBRE_DIR)/build \
		&& CC="$(CC)" CXX="$(CXX)" CFLAGS="$(CFLAGS) -fPIC" \
		CXXFLAGS="$(CXXFLAGS) -fPIC" LDFLAGS="$(LDFLAGS)" \
		../configure --disable-desktopfiles \
			--disable-static --enable-shared \
			--disable-xmltools --disable-largefile \
			$(if $(EMULATE_READER),,-host=$(CHOST)) )
	$(MAKE) -j$(PROCESSORS) -C $(DJVULIBRE_DIR)/build SUBDIRS_FIRST=libdjvu
	cp -fL $(DJVULIBRE_LIB_DIR)/$(notdir $(DJVULIBRE_LIB)) \
		$(DJVULIBRE_LIB)


# crengine, fetched via GIT as a submodule
$(CRENGINE_THIRDPARTY_LIBS) $(CRENGINE_LIB):
	test -e $(CRENGINE_WRAPPER_DIR)/CMakeFiles \
	|| ( cd $(CRENGINE_WRAPPER_DIR) \
	&& CFLAGS="$(CFLAGS) -fPIC" \
		CXXFLAGS="$(CXXFLAGS) -fPIC" CC="$(CC)" \
		CXX="$(CXX)" LDFLAGS="$(LDFLAGS)" \
		cmake -D CMAKE_BUILD_TYPE=Release . )
	cd $(CRENGINE_WRAPPER_DIR) &&  $(MAKE) VERBOSE=1
	cp -fL $(CRENGINE_WRAPPER_DIR)/$(notdir $(CRENGINE_LIB)) \
		$(CRENGINE_LIB)


# LuaJIT, fetched via GIT as a submodule
$(LUA_LIB) $(LUAJIT):
ifdef EMULATE_READER
	$(MAKE) -j$(PROCESSORS) -C $(LUA_DIR)
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) -j$(PROCESSORS) -C $(LUA_DIR) \
		CC="$(HOSTCC)" HOST_CC="$(HOSTCC) -m32" \
		CFLAGS="$(BASE_CFLAGS)" HOST_CFLAGS="$(HOSTCFLAGS)" \
		TARGET_CFLAGS="$(CFLAGS)" \
		TARGET_FLAGS="-DLUAJIT_NO_LOG2 -DLUAJIT_NO_EXP2" \
		CROSS="$(strip $(CCACHE) $(CHOST))-"
endif
	# special case: LuaJIT compiles a libluajit.so, which must be named
	# differently when installing
	cp -fL $(LUA_DIR)/src/libluajit.so* $(LUA_LIB)
	cp -fL $(LUA_DIR)/src/$(notdir $(LUAJIT)) $(LUAJIT)


# popen-noshell, fetched via SVN
$(POPEN_NOSHELL_LIB):
	$(MAKE) -j$(PROCESSORS) -C $(POPEN_NOSHELL_DIR) \
		CC="$(CC)" AR="$(AR)" CFLAGS="$(CFLAGS) -fPIC"


# k2pdfopt, fetched via GIT as a submodule
$(K2PDFOPT_LIB) $(LEPTONICA_LIB) $(TESSERACT_LIB):
ifdef EMULATE_READER
	$(MAKE) -j$(PROCESSORS) -C $(K2PDFOPT_DIR) BUILDMODE=shared \
		CC="$(HOSTCC)" CFLAGS="$(HOSTCFLAGS)" \
		CXX="$(HOSTCXX)" CXXFLAGS="$(HOSTCFLAGS)" \
		AR="$(AR)" EMULATE_READER=1 all
else
	$(MAKE) -j$(PROCESSORS) -C $(K2PDFOPT_DIR) BUILDMODE=shared \
		HOST="$(CHOST)" \
		CC="$(CC)" CFLAGS="$(CFLAGS) -O3" \
		CXX="$(CXX)" CXXFLAGS="$(CXXFLAGS)" \
		AR="$(AR)" all
endif
	cp -fL $(K2PDFOPT_DIR)/$(notdir $(K2PDFOPT_LIB)) $(OUTPUT_DIR)/
	cp -fL $(K2PDFOPT_DIR)/$(notdir $(LEPTONICA_LIB)) $(OUTPUT_DIR)/
	cp -fL $(K2PDFOPT_DIR)/$(notdir $(TESSERACT_LIB)) $(OUTPUT_DIR)/
{'fraction_non_alphanumeric': 0.20620702135360117, 'fraction_numerical': 0.004162142598624683, 'mean_word_length': 4.331886155330439, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1574488', 'n_tokens_mistral': 4946, 'n_tokens_neox': 4502, 'n_words': 894}