Skip to contentSkip to conversation

Setting timezone for uClibc, and setting localtime

PATCH Superseded Yann E. MORIN 2 participants 11 messages Mar 3, 2014 – Mar 7, 2014

v3 of 4 Superseded Latest is v4 →

lore
Share & tools
lore
#0 lore raw

v3 cover Setting timezone for uClibc, and setting localtime

From: "Yann E. MORIN" <[email protected]>

Hello All!

Here is a series that adds the possibility to:

- install the timezone info for uClibc; currently, that was only supported for glibc or eglibc-based systems. Thanks to Alexandre's packaging of tzdump, we can generate zoneinfo for uClibc, too.

- set a default localtime for the system, for both *glibc-based systems and uClibc-based systems.

Unfortunately, musl-based systems are still left behind for now. This is not too bad, as musl is not yet widely available.

Regards,
Yann E. MORIN.

----------------------------------------------------------------
Alexandre Belloni (3):
tzdata: allow host build
tzdump: new host package
tz: new package

Yann E. MORIN (4):
system: make the zoneinfo list a system option
system: add selection of a default localtime package/zic: install header
system: allow setting the local timezone for uClibc

 Config.in.legacy         | 15 +++++++++++++++
 package/Config.in        |  1 +
 package/tz/Config.in     |  4 ++++
 package/tz/tz.mk         | 30 ++++++++++++++++++++++++++++++
 package/tzdata/Config.in | 23 +++--------------------
 package/tzdata/tzdata.mk | 31 ++++++++++++++++++++++++++++---
 package/tzdump/tzdump.mk | 24 ++++++++++++++++++++++++
 package/zic/zic.mk       |  2 ++
 system/Config.in         | 40 ++++++++++++++++++++++++++++++++++++++++
 9 files changed, 147 insertions(+), 23 deletions(-)
 create mode 100644 package/tz/Config.in
 create mode 100644 package/tz/tz.mk
 create mode 100644 package/tzdump/tzdump.mk
Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#1 lore raw

PATCH v3 1/7 system: make the zoneinfo list a system option

From: "Yann E. MORIN" <[email protected]>

Cc Alexandre Belloni <[email protected]>

---
Note: because the tzdata package loses its prompt, it defaults to 'n'. This means a user will loose his timezone settings, unless he selects to install timezone info in the system configuration menu.

We can not add a legacy option for that, or we'd get a circular dependency. The only way we'd be fool-proof would be by renaming the package altogether, and adding a legacy option for the old name.

---
 Config.in.legacy         | 15 +++++++++++++++
 package/tzdata/Config.in | 23 +++--------------------
 package/tzdata/tzdata.mk |  4 ++--
 system/Config.in         | 22 ++++++++++++++++++++++
 4 files changed, 42 insertions(+), 22 deletions(-)
Config.in.legacy +15 -0
index afcd3b1..5e2970a 100644
@@ -184,6 +184,21 @@ config BR2_PACKAGE_XLIB_LIBPTHREAD_STUBS
 ###############################################################################
 comment "Legacy options removed in 2014.02"
 
+config BR2_TARGET_TZ_ZONELIST
+	default BR2_PACKAGE_TZDATA_ZONELIST if BR2_PACKAGE_TZDATA_ZONELIST != ""
+
+config BR2_PACKAGE_TZDATA_ZONELIST
+	string "tzdata: the timezone list option has been renamed"
+	help
+	  The option BR2_PACKAGE_TZDATA_ZONELIST has been renamed to
+	  BR2_TARGET_TZ_ZONELIST, and moved to the "System configuration"
+	  menu. You'll need to select BR2_TARGET_TZ_INFO.
+
+config BR2_PACKAGE_TZDATA_ZONELIST_WRAP
+	bool
+	default y if BR2_PACKAGE_TZDATA_ZONELIST != ""
+	select BR2_LEGACY
+
 config BR2_sh2
 	bool "sh2 support removed"
 	help
package/tzdata/Config.in +3 -20
index 1be6814..1e6cc0f 100644
@@ -1,26 +1,9 @@
-comment "tzdata needs an (e)glibc toolchain"
-	depends on !BR2_TOOLCHAIN_USES_GLIBC
+# This package is not meant to be user-visible.
+# It gets selected by BR2_TARGET_TZ in system/Config.in
 
 config BR2_PACKAGE_TZDATA
-	bool "tzdata"
-	depends on BR2_TOOLCHAIN_USES_GLIBC
+	bool
 	help
 	  Time zone database
 
 	  http://www.iana.org/time-zones/repository/tz-link.html
-
-if BR2_PACKAGE_TZDATA
-
-config BR2_PACKAGE_TZDATA_ZONELIST
-	string "Time zone list"
-	default "default"
-	help
-	  Space-separated list of time zones to compile.
-
-	  The value "default" includes all commonly used time zones. Note
-	  that this set consumes around 5.5M.
-
-	  The full list is the list of files in the time zone database source,
-	  not including the build and .tab files.
-
-endif
package/tzdata/tzdata.mk +2 -2
index 1cb5b3f..b6f07e2 100644
@@ -13,10 +13,10 @@ TZDATA_LICENSE = Public domain
 TZDATA_DEFAULT_ZONELIST = africa antarctica asia australasia backward etcetera \
 			europe factory northamerica pacificnew southamerica
 
-ifeq ($(call qstrip,$(BR2_PACKAGE_TZDATA_ZONELIST)),default)
+ifeq ($(call qstrip,$(BR2_TARGET_TZ_ZONELIST)),default)
 TZDATA_ZONELIST = $(TZDATA_DEFAULT_ZONELIST)
 else
-TZDATA_ZONELIST = $(call qstrip,$(BR2_PACKAGE_TZDATA_ZONELIST))
+TZDATA_ZONELIST = $(call qstrip,$(BR2_TARGET_TZ_ZONELIST))
 endif
 
 # Don't strip any path components during extraction.
system/Config.in +22 -0
index 89578c5..7ea0208 100644
@@ -265,6 +265,28 @@ config BR2_TARGET_GENERIC_GETTY_OPTIONS
 endmenu
 endif
 
+config BR2_TARGET_TZ_INFO
+	bool "Install timezone info"
+	depends on BR2_TOOLCHAIN_USES_GLIBC
+	select BR2_PACKAGE_TZDATA
+	help
+	  Say 'y' here to install timezone info.
+
+if BR2_TARGET_TZ_INFO
+
+config BR2_TARGET_TZ_ZONELIST
+	string "timezone list"
+	help
+	  Space-separated list of time zones to compile.
+
+	  The value "default" includes all commonly used time zones. Note
+	  that this set consumes around 5.5M.
+
+	  The full list is the list of files in the time zone database source,
+	  not including the build and .tab files.
+
+endif # BR2_TARGET_TZ_INFO
+
 config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW
 	bool "remount root filesystem read-write during boot"
 	default y
Signature · 1 line
1.8.3.2
#2 lore raw

PATCH v3 2/7 system: add selection of a default localtime

In reply to Yann E. MORIN

From: "Yann E. MORIN" <[email protected]>

[alexandre.belloni: move from "tzdata" to "system configuration"]
[yann.morin.1998 at free.fr: move into the BR2_TARGET_TZ_INFO conditionnal block]
---
 package/tzdata/tzdata.mk |  7 ++++++-
 system/Config.in         | 14 ++++++++++++++
 2 files changed, 20 insertions(+), 1 deletion(-)
package/tzdata/tzdata.mk +6 -1
index b6f07e2..c23b3df 100644
@@ -39,8 +39,13 @@ define TZDATA_INSTALL_TARGET_CMDS
 	cp -a $(@D)/_output/* $(TARGET_DIR)/usr/share/zoneinfo
 	cd $(TARGET_DIR)/usr/share/zoneinfo;    \
 	for zone in posix/*; do                 \
-	    ln -sfn "$${zone}" "$${zone##*/}";    \
+	    ln -sfn "$${zone}" "$${zone##*/}";  \
 	done
+	if [ -n "$(BR2_TARGET_LOCALTIME)" ]; then                           \
+	    cd $(TARGET_DIR)/etc;                                           \
+	    ln -sf ../usr/share/zoneinfo/$(BR2_TARGET_LOCALTIME) localtime; \
+	    echo "$(BR2_TARGET_LOCALTIME)" >timezone;                       \
+	fi
 endef
 
 $(eval $(generic-package))
system/Config.in +14 -0
index 7ea0208..008369f 100644
@@ -285,6 +285,20 @@ config BR2_TARGET_TZ_ZONELIST
 	  The full list is the list of files in the time zone database source,
 	  not including the build and .tab files.
 
+config BR2_TARGET_LOCALTIME
+	string "default local time"
+	help
+	  The time zone to install as the default local time, expressed as a
+	  tzdata location, such as:
+	    GMT
+	    Europe/Paris
+	    America/New_York
+	    Pacific/Wallis
+	    ...
+
+	  If empty, no local time will be set, and the dates will be
+	  expressed in UTC.
+
 endif # BR2_TARGET_TZ_INFO
 
 config BR2_TARGET_GENERIC_REMOUNT_ROOTFS_RW
Signature · 1 line
1.8.3.2
#3 lore raw

PATCH v3 3/7 tzdata: allow host build

In reply to Yann E. MORIN

From: Alexandre Belloni <[email protected]>

uClibc uses its own format for timezone info. OTOH, we can generate uClibc-compatible timezone info from existing tzdata.

Add a host-version of tzdata, so we can harvest its installed timezone info.

---
 package/tzdata/tzdata.mk | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
package/tzdata/tzdata.mk +20 -0
index c23b3df..7a60c2c 100644
@@ -48,4 +48,24 @@ define TZDATA_INSTALL_TARGET_CMDS
 	fi
 endef
 
+define HOST_TZDATA_EXTRACT_CMDS
+	gzip -d -c $(DL_DIR)/$(TZDATA_SOURCE) \
+		| $(TAR) --strip-components=0 -C $(@D) -xf -
+endef
+
+define HOST_TZDATA_BUILD_CMDS
+	(cd $(@D); \
+		for zone in $(TZDATA_ZONELIST); do \
+			$(ZIC) -d _output/posix -y yearistype.sh $$zone; \
+			$(ZIC) -d _output/right -L leapseconds -y yearistype.sh $$zone; \
+		done; \
+	)
+endef
+
+define HOST_TZDATA_INSTALL_CMDS
+	mkdir -p $(HOST_DIR)/usr/share/zoneinfo
+	cp -a $(@D)/_output/* $(HOST_DIR)/usr/share/zoneinfo
+endef
+
 $(eval $(generic-package))
+$(eval $(host-generic-package))
Signature · 1 line
1.8.3.2
#4 lore raw

PATCH v3 4/7 package/zic: install header

In reply to Yann E. MORIN

From: "Yann E. MORIN" <[email protected]>

The incoming host-tzdump package requires the tzfile header, so we isntall it.

[yann.morin.1998 at free.fr: split zic header-install to its own cset]
---
 package/zic/zic.mk | 2 ++
 1 file changed, 2 insertions(+)
package/zic/zic.mk +2 -0
index c9b6c7b..4814fba 100644
@@ -22,6 +22,8 @@ endef
 define HOST_ZIC_INSTALL_CMDS
 	mkdir -p $(HOST_DIR)/usr/sbin
 	install -D -m 755 $(@D)/zic $(HOST_DIR)/usr/sbin/zic
+	mkdir -p $(HOST_DIR)/usr/include
+	install -D -m 644 $(@D)/tzfile.h $(HOST_DIR)/usr/include/tzfile.h
 endef
 
 $(eval $(host-generic-package))
Signature · 1 line
1.8.3.2
#5 lore raw

PATCH 4/7 package/zic: install header

Dear Yann E. MORIN,

Quoted 17 lines · Yann E. MORIN

From: "Yann E. MORIN" <[email protected]>

The incoming host-tzdump package requires the tzfile header, so we isntall it.

[yann.morin.1998 at free.fr: split zic header-install to its own cset]
---
 package/zic/zic.mk | 2 ++
 1 file changed, 2 insertions(+)
package/zic/zic.mk +0 -0
index c9b6c7b..4814fba 100644

package/zic/zic.mk endef · line 27

Quoted 6 lines
package/zic/zic.mk +2 -0
@@ -22,6 +22,8 @@ endef
 define HOST_ZIC_INSTALL_CMDS
 	mkdir -p $(HOST_DIR)/usr/sbin
 	install -D -m 755 $(@D)/zic $(HOST_DIR)/usr/sbin/zic
+	mkdir -p $(HOST_DIR)/usr/include
+	install -D -m 644 $(@D)/tzfile.h $(HOST_DIR)/usr/include/tzfile.h
 endef

Applied, thanks.

However, I've removed the mkdir -p line, which is useless because of the use of install -D. And I've replaced install by $(INSTALL), was we do in all other packages.

Thomas

Signature · 3 lines
Thomas Petazzoni, CTO, Free Electrons
Embedded Linux, Kernel and Android engineering
http://free-electrons.com
#6 lore raw

PATCH v3 5/7 tzdump: new host package

In reply to Yann E. MORIN

From: Alexandre Belloni <[email protected]>

tzdump takes timezone info in the installed tzdata format, and outputs timezone info parseable by uClibc.

[yann.morin.1998 at free.fr: split zic header-install to its own cset]
---
 package/tzdump/tzdump.mk | 24 ++++++++++++++++++++++++
 1 file changed, 24 insertions(+)
 create mode 100644 package/tzdump/tzdump.mk
package/tzdump/tzdump.mk new file +24 -0
new file mode 100644
index 0000000..471a719
@@ -0,0 +1,24 @@
+################################################################################
+#
+# tzdump
+#
+################################################################################
+
+TZDUMP_VERSION = 65a10105564801094b18c3fcacf4dde4c44e4ab8
+TZDUMP_SITE = $(call github,alexandrebelloni,tzdump,$(TZDUMP_VERSION))
+TZDUMP_DEPENDENCIES = host-zic
+
+define HOST_TZDUMP_BUILD_CMDS
+	(cd $(@D) ;\
+		$(HOSTCC) $(HOST_CFLAGS) $(HOST_LDFLAGS) -o tzdump tzdump.c ; \
+	)
+endef
+
+define HOST_TZDUMP_INSTALL_CMDS
+	mkdir -p $(HOST_DIR)/usr/sbin
+	install -D -m 755 $(@D)/tzdump $(HOST_DIR)/usr/sbin/tzdump
+endef
+
+$(eval $(host-generic-package))
+
+TZDUMP = $(HOST_DIR)/usr/sbin/tzdump
Signature · 1 line
1.8.3.2
#7 lore raw

PATCH v3 6/7 tz: new package

In reply to Yann E. MORIN

From: Alexandre Belloni <[email protected]>

uClibc can not use timezone info from tzdata as-is, but accepts setting the local timezone in /etc/TZ.

[yann.morin.1998 at free.fr: make it a blind package; little tweak to help text]
---
 package/Config.in    |  1 +
 package/tz/Config.in |  4 ++++
 package/tz/tz.mk     | 30 ++++++++++++++++++++++++++++++
 3 files changed, 35 insertions(+)
 create mode 100644 package/tz/Config.in
 create mode 100644 package/tz/tz.mk
package/Config.in +1 -0
index 417c9b8..68d1f33 100644
@@ -800,6 +800,7 @@ source "package/protobuf/Config.in"
 source "package/protobuf-c/Config.in"
 source "package/schifra/Config.in"
 source "package/startup-notification/Config.in"
+source "package/tz/Config.in"
 source "package/tzdata/Config.in"
 source "package/zlog/Config.in"
 endmenu
package/tz/Config.in new file +4 -0
new file mode 100644
index 0000000..943dc5c
@@ -0,0 +1,4 @@
+config BR2_PACKAGE_TZ
+	bool
+	help
+	  Timezone info for uClibc.
package/tz/tz.mk new file +30 -0
new file mode 100644
index 0000000..e74c41b
@@ -0,0 +1,30 @@
+################################################################################
+#
+# tz
+#
+################################################################################
+
+TZ_SOURCE =
+TZ_DEPENDENCIES = host-tzdata host-tzdump
+TZ_LICENSE = Public domain
+
+define TZ_BUILD_CMDS
+	(cd $(HOST_DIR)/usr/share/zoneinfo/posix/;                 \
+		for i in $$(find . -type f); do                    \
+			mkdir -p $(@D)/output/$$(dirname $$i);         \
+			$(TZDUMP) -p . -q $${i#./} > $(@D)/output/$$i; \
+		done                                               \
+	)
+endef
+
+define TZ_INSTALL_TARGET_CMDS
+	mkdir -p $(TARGET_DIR)/usr/share/zoneinfo/uclibc
+	cp -a $(@D)/output/* $(TARGET_DIR)/usr/share/zoneinfo/uclibc
+	if [ -n "$(BR2_TARGET_LOCALTIME)" ]; then                     \
+		ln -sf /usr/share/zoneinfo/uclibc/$(BR2_TARGET_LOCALTIME) \
+			$(TARGET_DIR)/etc/TZ;                                 \
+	fi
+
+endef
+
+$(eval $(generic-package))
Signature · 1 line
1.8.3.2
#8 lore raw

PATCH v3 7/7 system: allow setting the local timezone for uClibc

In reply to Yann E. MORIN

From: "Yann E. MORIN" <[email protected]>

---
 system/Config.in | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
system/Config.in +7 -3
index 008369f..cea9429 100644
@@ -267,8 +267,10 @@ endif
 
 config BR2_TARGET_TZ_INFO
 	bool "Install timezone info"
-	depends on BR2_TOOLCHAIN_USES_GLIBC
-	select BR2_PACKAGE_TZDATA
+	# No timezone for musl; only for uClibc or (e)glibc.
+	depends on BR2_TOOLCHAIN_USES_GLIBC || BR2_TOOLCHAIN_USES_UCLIBC
+	select BR2_PACKAGE_TZDATA if BR2_TOOLCHAIN_USES_GLIBC
+	select BR2_PACKAGE_TZ if BR2_TOOLCHAIN_USES_UCLIBC
 	help
 	  Say 'y' here to install timezone info.
 
@@ -276,11 +278,13 @@ if BR2_TARGET_TZ_INFO
 
 config BR2_TARGET_TZ_ZONELIST
 	string "timezone list"
+	# Only valid for uClibc or (e)glibc
+	depends on BR2_TOOLCHAIN_USES_GLIBC || BR2_TOOLCHAIN_USES_UCLIBC
 	help
 	  Space-separated list of time zones to compile.
 
 	  The value "default" includes all commonly used time zones. Note
-	  that this set consumes around 5.5M.
+	  that this set consumes around 5.5M for (e)glibc and 2.1M for uClibc.
 
 	  The full list is the list of files in the time zone database source,
 	  not including the build and .tab files.
Signature · 1 line
1.8.3.2
#9 lore raw

PATCH v3 7/7 system: allow setting the local timezone for uClibc

Alexandre, All,

Reviewing our own patch here:

On 2014-03-03 23:10 +0100, Yann E. MORIN spake thusly:

Quoted 26 lines

From: "Yann E. MORIN" <[email protected]>

---
 system/Config.in | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)
system/Config.in +4 -2
index 008369f..cea9429 100644
@@ -267,8 +267,10 @@ endif
 
 config BR2_TARGET_TZ_INFO
 	bool "Install timezone info"
-	depends on BR2_TOOLCHAIN_USES_GLIBC
-	select BR2_PACKAGE_TZDATA
+	# No timezone for musl; only for uClibc or (e)glibc.
+	depends on BR2_TOOLCHAIN_USES_GLIBC || BR2_TOOLCHAIN_USES_UCLIBC
+	select BR2_PACKAGE_TZDATA if BR2_TOOLCHAIN_USES_GLIBC
+	select BR2_PACKAGE_TZ if BR2_TOOLCHAIN_USES_UCLIBC
 	help
 	  Say 'y' here to install timezone info.
 

system/Config.in if BR2_TARGET_TZ_INFO · line 282

Quoted 5 lines
system/Config.in +2 -0
@@ -276,11 +278,13 @@ if BR2_TARGET_TZ_INFO
 
 config BR2_TARGET_TZ_ZONELIST
 	string "timezone list"
+	# Only valid for uClibc or (e)glibc
+	depends on BR2_TOOLCHAIN_USES_GLIBC || BR2_TOOLCHAIN_USES_UCLIBC

Unneeded, it already 'depends on' BR2_TARGET_TZ_INFO (in an if-block), so we do not need to repeat this here.

Regards,
Yann E. MORIN.

Signature · 6 lines
.-----------------.--------------------.------------------.--------------------.
|  Yann E. MORIN  | Real-Time Embedded | /"\ ASCII RIBBON | Erics' conspiracy: |
| +33 662 376 056 | Software  Designer | \ / CAMPAIGN     |  ___               |
| +33 223 225 172 `------------.-------:  X  AGAINST      |  \e/  There is no  |
| http://ymorin.is-a-geek.org/ | _/*\_ | / \ HTML MAIL    |   v   conspiracy.  |
'------------------------------^-------^------------------^--------------------'
#10 lore raw

PATCH 1/1 system: allow setting the local timezone for uClibc

In reply to Yann E. MORIN

From: "Yann E. MORIN" <[email protected]>

---
Changes v3 -> v4
- do not double-depend on glibc||uClibc

---
 system/Config.in | 8 +++++---
 1 file changed, 5 insertions(+), 3 deletions(-)
system/Config.in +5 -3
index 008369f..11656df 100644
@@ -267,8 +267,10 @@ endif
 
 config BR2_TARGET_TZ_INFO
 	bool "Install timezone info"
-	depends on BR2_TOOLCHAIN_USES_GLIBC
-	select BR2_PACKAGE_TZDATA
+	# No timezone for musl; only for uClibc or (e)glibc.
+	depends on BR2_TOOLCHAIN_USES_GLIBC || BR2_TOOLCHAIN_USES_UCLIBC
+	select BR2_PACKAGE_TZDATA if BR2_TOOLCHAIN_USES_GLIBC
+	select BR2_PACKAGE_TZ if BR2_TOOLCHAIN_USES_UCLIBC
 	help
 	  Say 'y' here to install timezone info.
 
@@ -280,7 +282,7 @@ config BR2_TARGET_TZ_ZONELIST
 	  Space-separated list of time zones to compile.
 
 	  The value "default" includes all commonly used time zones. Note
-	  that this set consumes around 5.5M.
+	  that this set consumes around 5.5M for (e)glibc and 2.1M for uClibc.
 
 	  The full list is the list of files in the time zone database source,
 	  not including the build and .tab files.
Signature · 1 line
1.8.3.2