Skip to content

Commit

Permalink
Make the PB build compatible with awfully old FW (#1062)
Browse files Browse the repository at this point in the history
* Ensure the PB build generates binaries that run on truly ancient FW

i.e., glibc 2.5

(Also, actually fix glib on legacy/pb).

* And fix tar on legacy/pb, too.
  • Loading branch information
NiLuJe committed Mar 12, 2020
1 parent 5342839 commit 60c8dc7
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 21 deletions.
6 changes: 4 additions & 2 deletions Makefile.defs
Expand Up @@ -316,6 +316,8 @@ MG2K12_COMPAT_CFLAGS:=-fno-stack-protector -U_FORTIFY_SOURCE -D_GNU_SOURCE -fno-
MG2K12_COMPAT_CXXFLAGS:=-fno-use-cxa-atexit
# My legacy TC is based on glibc 2.9, that should be enough :).
NILUJE_COMPAT_CFLAGS:=-fno-stack-protector -U_FORTIFY_SOURCE -D_GNU_SOURCE -mno-unaligned-access
# As for PB, despite the old TC targeting glibc 2.9, some devices are apparently still running glibc 2.5... (#5939)
PB_COMPAT_CFLAGS:=-D_GNU_SOURCE

# Same deal, but when targeting the K5/Kobo & using Ubuntu's Linaro TCs
UBUNTU_COMPAT_CFLAGS:=-fno-finite-math-only -fno-stack-protector -U_FORTIFY_SOURCE
Expand Down Expand Up @@ -366,8 +368,8 @@ else ifeq ($(TARGET), pocketbook)
ARM_ARCH+=-mfloat-abi=softfp
# NOTE: Because of course everything is terrible, newer FW (5.19+) use GCC 6.3.0's libstdc++,
# so, ideally, we shouldn't be using this on those newer devices...
COMPAT_CFLAGS:=$(STLABI_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(STLABI_COMPAT_CFLAGS)
COMPAT_CFLAGS:=$(STLABI_COMPAT_CFLAGS) $(PB_COMPAT_CFLAGS)
COMPAT_CXXFLAGS:=$(STLABI_COMPAT_CFLAGS) $(PB_COMPAT_CFLAGS)
ifeq ($(shell PATH='$(PATH)' $(CC) -dumpmachine 2>/dev/null), arm-linux-gnueabi)
COMPAT_CFLAGS+=$(UBUNTU_COMPAT_CFLAGS)
COMPAT_CXXFLAGS+=$(UBUNTU_COMPAT_CFLAGS)
Expand Down
1 change: 0 additions & 1 deletion Makefile.third
Expand Up @@ -449,7 +449,6 @@ $(OUTPUT_DIR)/tar: $(THIRDPARTY_DIR)/tar/*.*
-DCFLAGS="$(CFLAGS)" \
-DLDFLAGS="$(LDFLAGS)" \
-DLIBS="$(if $(or $(ANDROID),$(WIN32),$(DARWIN)),,-lrt) $(if $(ANDROID),-static,)" \
$(if $(LEGACY),-DDISABLE_LARGEFILE:BOOL=ON -DDISABLE_FORTIFY:BOOL=ON,) \
-DCHOST="$(if $(EMULATE_READER),,$(CHOST))" \
$(CURDIR)/$(THIRDPARTY_DIR)/tar && \
$(CMAKE_MAKE_PROGRAM) $(CMAKE_MAKE_PROGRAM_FLAGS)
Expand Down
33 changes: 20 additions & 13 deletions thirdparty/glib/CMakeLists.txt
Expand Up @@ -23,28 +23,35 @@ ep_get_binary_dir(BINARY_DIR)
# but fails to actually honor the specified/detected Python version in every cases,
# sometimes just hoping there's a python binary somewhere in $PATH (which, granted, there should be)...
# Enforce that to python3 for containers where that's the only available Python version.
if(($ENV{APPIMAGE}) OR ($ENV{CERVANTES}) OR ($ENV{KINDLE}) OR ($ENV{KOBO}))
if(DEFINED ENV{APPIMAGE} OR DEFINED ENV{CERVANTES} OR DEFINED ENV{KINDLE} OR DEFINED ENV{KOBO})
set(PATCH_CMD1 "${KO_PATCH} ${CMAKE_CURRENT_SOURCE_DIR}/glib-2.56.2-python3.patch")
endif()
# Android makes Linux syscalls hard to get to... Fix pilfered from Python.
if($ENV{ANDROID})
if(DEFINED ENV{ANDROID})
set(PATCH_CMD2 "${KO_PATCH} ${CMAKE_CURRENT_SOURCE_DIR}/glib-2.58.2-android-linux-syscalls.patch")
endif()

set(PATCH_CMD3 sh -c "NOCONFIGURE=1 ./autogen.sh")

# in order to support legacy PocketBook 4.x firmware we should get rid of
# eventfd@GLIBC_2.7 and pipe2@GLIB_2.9
set(gen_arm_config "glib_cv_stack_grows=no\\n")
# Autotools needs some hints when x-compiling
set(gen_arm_config "${gen_arm_config}glib_cv_stack_grows=no\\n")
set(gen_arm_config "${gen_arm_config}glib_cv_uscore=no\\n")
set(gen_arm_config "${gen_arm_config}glib_cv_eventfd=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_pipe2=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_posix_getpwuid_r=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_posix_getgrgid_r=no\\n")
# disable getpwuid, getgrgid and timegm for > android-12
set(gen_arm_config "${gen_arm_config}ac_cv_func_getpwuid_r=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_getgrgid_r=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_timegm=no\\n")
# In order to support legacy PocketBook 4.x firmware we should get rid of eventfd@GLIBC_2.7 and pipe2@GLIBC_2.9
if(DEFINED ENV{LEGACY} OR DEFINED ENV{POCKETBOOK})
set(gen_arm_config "${gen_arm_config}glib_cv_eventfd=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_pipe2=no\\n")
# As well as mkostemp@GLIBC_2.7
set(gen_arm_config "${gen_arm_config}ac_cv_func_mkostemp=no\\n")
endif()
if(DEFINED ENV{ANDROID})
# disable getpwuid, getgrgid and timegm for > android-12
set(gen_arm_config "${gen_arm_config}ac_cv_func_posix_getpwuid_r=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_posix_getgrgid_r=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_getpwuid_r=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_getgrgid_r=no\\n")
set(gen_arm_config "${gen_arm_config}ac_cv_func_timegm=no\\n")
endif()

set(gen_arm_config sh -c "printf \"${gen_arm_config}\" > arm_cache.conf")

set(CFG_ENV_VAR "CC=\"${CC}\" AR=\"${AR}\" RANLIB=\"${RANLIB}\"")
Expand Down
4 changes: 2 additions & 2 deletions thirdparty/libzmq/CMakeLists.txt
Expand Up @@ -22,14 +22,14 @@ set(CFG_ENV_VAR "CC=\"${CC}\" CXX=\"${CXX}\" CFLAGS=\"${CFLAGS}\" CXXFLAGS=\"${C
set(CFG_ENV_VAR "${CFG_ENV_VAR} libzmq_have_xmlto=no libzmq_have_asciidoc=no")

set(CFG_OPTS "-q --prefix=${BINARY_DIR} --disable-static --enable-shared --without-documentation --host=\"${CHOST}\"")
if(${LEGACY})
if(DEFINED ENV{LEGACY} OR DEFINED ENV{POCKETBOOK})
set(CFG_OPTS "${CFG_OPTS} --disable-eventfd")
endif()

set(CFG_CMD sh -c "${CFG_ENV_VAR} ${SOURCE_DIR}/configure ${CFG_OPTS}")
set(PATCH_CMD sh -c "${ISED} \"s|-lstdc++||g\" libtool")

if($ENV{ANDROID})
if(DEFINED ENV{ANDROID})
set(CFG_CMD "${CFG_CMD} && ${ISED} 's|version_type=none|version_type=linux|' libtool")
set(CFG_CMD "${CFG_CMD} && ${ISED} 's|need_lib_prefix=no|need_lib_prefix=yes|' libtool")
set(CFG_CMD "${CFG_CMD} && ${ISED} 's|need_version=no|need_version=yes|' libtool")
Expand Down
11 changes: 8 additions & 3 deletions thirdparty/tar/CMakeLists.txt
Expand Up @@ -21,15 +21,20 @@ endif()
#set(PATCH_CMD2 sh -c "touch ABOUT-NLS po/Makevars.template")
#set(PATCH_CMD3 sh -c "AUTOPOINT=true ./bootstrap --skip-po")

set(CFG_ENV_VAR "CC=\"${CC} -DHAVE_MKFIFO=1\" CFLAGS=\"${CFLAGS}\" LDFLAGS=\"${LDFLAGS}\"")
# Avoid pulling > GLIBC_2.4 symbols on crappy platforms
if(DEFINED ENV{LEGACY} OR DEFINED ENV{POCKETBOOK})
set(CFG_ENV_VAR "ac_cv_func_utimensat=no ac_cv_func_futimens=no")
endif()

set(CFG_ENV_VAR "${CFG_ENV_VAR} CC=\"${CC} -DHAVE_MKFIFO=1\" CFLAGS=\"${CFLAGS}\" LDFLAGS=\"${LDFLAGS}\"")
set(CFG_OPTS "-q LIBS=\"${LIBS}\" --host=\"${CHOST}\"")

if(${DISABLE_LARGEFILE})
if(DEFINED ENV{LEGACY} OR DEFINED ENV{POCKETBOOK})
set(CFG_OPTS "${CFG_OPTS} --disable-largefile")
endif()
set(CFG_CMD "${CFG_ENV_VAR} ${SOURCE_DIR}/configure --disable-nls --disable-gcc-warnings --disable-acl --without-xattrs --without-posix-acls ${CFG_OPTS}")

if(${DISABLE_FORTIFY})
if(DEFINED ENV{LEGACY} OR DEFINED ENV{POCKETBOOK})
# Forcibly disable FORTIFY on legacy devices...
set(CFG_CMD "${CFG_CMD} && ${ISED} 's/# define _FORTIFY_SOURCE 2/#undef _FORTIFY_SOURCE/' config.h")
endif()
Expand Down

0 comments on commit 60c8dc7

Please sign in to comment.