diff --git a/CMakeLists.txt b/CMakeLists.txt index d990e11..8c47574 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -2,6 +2,11 @@ cmake_minimum_required(VERSION 3.10) project(tzdb2nx VERSION 1.0) +set(TZDB_VERSION "$ENV{TZDB_VERSION}") +if ("${TZDB_VERSION}" STREQUAL "") + set(TZDB_VERSION "2022c") +endif() + set(CMAKE_CXX_STANDARD 20) add_subdirectory(src) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index dcfc32f..99e953e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -8,3 +8,4 @@ add_compile_options( include_directories(.) add_subdirectory(tzdb2nx) +add_subdirectory(tzdb) diff --git a/src/tzdb/CMakeLists.txt b/src/tzdb/CMakeLists.txt new file mode 100644 index 0000000..4821cce --- /dev/null +++ b/src/tzdb/CMakeLists.txt @@ -0,0 +1,65 @@ +find_program(GNU_MAKE make) +if ("${GNU_MAKE}" STREQUAL "GNU_MAKE-NOTFOUND") + message(ERROR "make program not found") +endif() + +set(TZDB_ARCHIVE "tzdb-${TZDB_VERSION}.tar.lz") +set(TZDB_LOCATION "${CMAKE_CURRENT_BINARY_DIR}/tzdb-${TZDB_VERSION}") +if (NOT (EXISTS "${CMAKE_CURRENT_BINARY_DIR}/${TZDB_ARCHIVE}" AND EXISTS "${TZDB_LOCATION}")) + file(DOWNLOAD "https://data.iana.org/time-zones/releases/${TZDB_ARCHIVE}" "${CMAKE_CURRENT_BINARY_DIR}/${TZDB_ARCHIVE}") + file(ARCHIVE_EXTRACT INPUT "${CMAKE_CURRENT_BINARY_DIR}/${TZDB_ARCHIVE}" DESTINATION "${CMAKE_CURRENT_BINARY_DIR}") +endif() + +set(TZDB_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/build") +set(TZDB_ZONEINFO "${TZDB_BUILD_DIR}/usr/share/zoneinfo") +set(TZIF_LIST_FILE "${CMAKE_CURRENT_BINARY_DIR}/tzif_list.txt") + +set(NX_BUILD_DIR "${CMAKE_CURRENT_BINARY_DIR}/nx") + +add_custom_target(x80e + ALL + DEPENDS + tzdb2nx) + +if (NOT EXISTS "${TZDB_BUILD_DIR}" OR NOT EXISTS ${TZIF_LIST_FILE}) + execute_process( + COMMAND + "${GNU_MAKE}" DESTDIR=${TZDB_BUILD_DIR} install + WORKING_DIRECTORY + "${TZDB_LOCATION}" + COMMAND_ERROR_IS_FATAL ANY + ) + + # execute_process( + # COMMAND + # "${TZDB_LOCATION}/zic" -b fat -d ${TZDB_ZONEINFO} africa antarctica asia australasia europe northamerica southamerica etcetera backward factory + # WORKING_DIRECTORY + # "${TZDB_LOCATION}" + # COMMAND_ERROR_IS_FATAL ANY + # ) + + execute_process( + COMMAND + /bin/bash "${CMAKE_CURRENT_SOURCE_DIR}/find_tzif.sh" "${TZDB_ZONEINFO}" "${TZIF_LIST_FILE}" + COMMAND_ERROR_IS_FATAL ANY + ) +endif() + +file(STRINGS "${TZIF_LIST_FILE}" TZ_FILES) +foreach(FILE ${TZ_FILES}) + file(RELATIVE_PATH TARG "${TZDB_ZONEINFO}" "${FILE}") + get_filename_component(TARG_PATH "${NX_BUILD_DIR}/${TARG}" DIRECTORY) + string(REGEX REPLACE "\/" "_" TARG_SANITIZED "${TARG}") + add_custom_target(${TARG_SANITIZED} + BYPRODUCTS + ${NX_BUILD_DIR}/${TARG} + COMMAND + mkdir -p ${TARG_PATH} + COMMAND + "${PROJECT_BINARY_DIR}/src/tzdb2nx/tzdb2nx" ${FILE} ${NX_BUILD_DIR}/${TARG} + DEPENDS + tzdb2nx + ) + + add_dependencies(x80e ${TARG_SANITIZED}) +endforeach() diff --git a/src/tzdb/find_tzif.sh b/src/tzdb/find_tzif.sh new file mode 100644 index 0000000..3a96a53 --- /dev/null +++ b/src/tzdb/find_tzif.sh @@ -0,0 +1,14 @@ +#/bin/bash +set -e +directory=$1 +tzif_list=$2 + +truncate -s 0 $tzif_list + +for i in `find $directory -type f`; do + header=`head -c 4 $i` + if [ "$header" == "TZif" ]; then + echo "$i" >> $tzif_list + fi +done +