From 3274c6d97c7c31529d8d28a9344c2fe1bdff439d Mon Sep 17 00:00:00 2001 From: Slyvtt Date: Tue, 30 Aug 2022 10:27:49 +0200 Subject: [PATCH] Updated name to cPNG + creation of automatic link with cZlib --- .gitignore | 2 + CMakeLists.txt | 24 +++--- Makefile.prizm | 40 ---------- README.md | 33 ++++---- build | 6 -- cPNG1_5_30.cbp | 81 ------------------- cPNG1_5_30.layout | 10 --- cmake/FindcPNG.cmake | 61 ++++---------- giteapc.make | 8 +- pnglibconf.out | 185 ------------------------------------------- 10 files changed, 46 insertions(+), 404 deletions(-) create mode 100644 .gitignore delete mode 100644 Makefile.prizm delete mode 100755 build delete mode 100644 cPNG1_5_30.cbp delete mode 100644 cPNG1_5_30.layout delete mode 100644 pnglibconf.out diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..3dadc61 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +/build-cg +/build-fx diff --git a/CMakeLists.txt b/CMakeLists.txt index 11f8d7f..b268414 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,6 +1,8 @@ +#cPNG source files cmake_minimum_required(VERSION 3.16) -project(Libcpng VERSION 1.5.30 LANGUAGES C) +project(cPNG VERSION 1.5.30 LANGUAGES C) find_package(Gint 2.9.0 REQUIRED) +find_package(cZlib 1.2.5 REQUIRED) set(SOURCES png.c @@ -19,25 +21,19 @@ set(SOURCES pngwtran.c pngwutil.c ) -include_directories( - "${PROJECT_SOURCE_DIR}" - "${PROJECT_BINARY_DIR}/include" - "${FXSDK_INCLUDE}") -add_compile_options(-Os -lm -m4-nofpu -mb -std=c11 -lczlib -ffreestanding -nostdlib -Wa,--dsp) -# Target name is "czlib", output file is "libcPNG.a" (by default) + +# Target name is "cPNG", output file is "libcPNG.a" (by default) add_library(cPNG STATIC ${SOURCES}) +target_compile_options(cPNG PRIVATE -Os -std=c11 -lcZlib) + # After building, install the target (that is, cPNG.a) in the compiler install(TARGETS cPNG DESTINATION "${FXSDK_LIB}") + # Install png.h from the build dir -install(FILES "${PROJECT_SOURCE_DIR}/png.h" - DESTINATION "${FXSDK_INCLUDE}") -# Install pngconf.h from the build dir -install(FILES "${PROJECT_SOURCE_DIR}/pngconf.h" - DESTINATION "${FXSDK_INCLUDE}") -# Install pnglibconf.h from the build dir -install(FILES "${PROJECT_SOURCE_DIR}/pnglibconf.h" +install(FILES png.h pngconf.h pnglibconf.h DESTINATION "${FXSDK_INCLUDE}") + # Install FindcPNG.cmake so that users can do find_package(LibcPNG) install(FILES cmake/FindcPNG.cmake DESTINATION "${FXSDK_CMAKE_MODULE_PATH}") diff --git a/Makefile.prizm b/Makefile.prizm deleted file mode 100644 index d12d318..0000000 --- a/Makefile.prizm +++ /dev/null @@ -1,40 +0,0 @@ -INCLUDE = -I./include -I/home/sylvain/.local/share/giteapc/Lephenixnoir/sh-elf-gcc/lib/gcc/sh3eb-elf/11.1.0/include/openlibm/ -CFLAGS = -O2 $(INCLUDE) -lczlib -lm -m4-nofpu -mb -ffreestanding -nostdlib -Wa,--dsp -DPNG_NO_FLOATING_ARITHMETIC -DPNG_NO_WRITE_SUPPORTED -DPNG_SETJMP_NOT_SUPPORTED -DPNG_WRITE_TRANSFORMS_NOT_SUPPORTED -DPNG_WRITE_ANCILLARY_CHUNKS_NOT_SUPPORTED -DPNG_NO_SAVE_UNKNOWN_CHUNKS -DPNG_NO_FLOATING_POINT -DPNG_NO_USER_MEM_SUPPORTED -DPNG_NO_TIME_RFC1123 -DPNG_NO_IO_STATE_SUPPORTED -DPNG_NO_USER_LIMITS_SUPPORTED -AR = sh-elf-gcc-ar -RANLIB = sh-elf-gcc-ranlib -CC = sh-elf-gcc - -CONFIG_H = config.h -TARGET = libcPNG.a -SOURCES = \ - png.c \ - pngerror.c \ - pngget.c \ - pngmem.c \ - pngpread.c \ - pngread.c \ - pngrio.c \ - pngrtran.c \ - pngrutil.c \ - pngset.c \ - pngtrans.c \ - pngwio.c \ - pngwrite.c \ - pngwtran.c \ - pngwutil.c - - -OBJECTS = $(SOURCES:.c=.o) - -all: $(TARGET) - -$(TARGET): $(OBJECTS) - #cp $(CONFIG_H).default $(CONFIG_H) - $(AR) cr $@ $^ - $(RANLIB) $@ - -.c.o: - $(CC) $(INCLUDE) $(CFLAGS) -c $< -o $@ - -clean: - rm -f $(OBJECTS) $(TARGET) diff --git a/README.md b/README.md index eae66f6..9ef27ca 100644 --- a/README.md +++ b/README.md @@ -1,25 +1,28 @@ -# libPNG 1.5.30 repository for CASIO fx-CG 10/20 (a.k.a. PRIZM) and fx-CG 50 (or Graph 90+E) +# Library cPNG 1.5.30 repository for CASIO fx-CG 10/20 (a.k.a. PRIZM) and fx-CG 50 (or Graph 90+E) -Need to have a fully working gcc toolchain for SH3/SH4 architecture, such as fxSDK +Need to have a fully working gcc toolchain for SH3/SH4 architecture. -**Note:** libPNG requires Zlib available, so the very first step is to get that library available and working prior to libPNG. You can get a working Zlib for CASIO fx-CG 10/20 (a.k.a. PRIZM) and fx-CG 50 (or Graph 90+E) here : [libZlib for PRIZM](https://gitea.planet-casio.com/Slyvtt/cZlib1_2_5) +**Note:** libcPNG requires cZlib available, so the very first step is to get that library available and working prior to libcPNG. +You can get a working Zlib for CASIO fx-CG 10/20 (a.k.a. PRIZM) and fx-CG 50 (or Graph 90+E) here : [libcZlib for PRIZM](https://gitea.planet-casio.com/Slyvtt/cZlib) -## Automatic installation using giteapc - -You can also use the `gitea install Slyvtt/cPNG1_5_30` command to get an automatic install - -when you compile a program for use with libPNG, do not forget to add a `-lcPNG -lczlib` option in your compilator command line. - -and then a `#include ` in your C/C++ sources +You can use the `giteapc install Slyvtt/cPNG` command to get an automatic install -## Manual compilation using a Makefile +## Using in a program -Compilation is done by using the adhoc Makefile : -`make -f Makefile.prizm` in the main directory +With CMake -It should produce the library libcPNG.a and copy everything in the right place. +```cmake +find_package(cPNG 1.5.30 REQUIRED) +target_link_libraries( PRIVATE cPNG::cPNG) +``` -The following steps are not automatically done, so please proceed with the following manipulations : + +With make, the following steps are not automatically done, so please proceed with the following manipulations : * copy the library `libcPNG.a` into your SH3/SH4 compiler lib folder * copy `png.h`, `pngconf.h` and `pnglibconf.h` files contained in the include folder into the include folder of the SH3/SH4 compiler +* link with `-lcPNG -lcZlib` + + + +In the C/C++ sources `#include ` \ No newline at end of file diff --git a/build b/build deleted file mode 100755 index dcc17ee..0000000 --- a/build +++ /dev/null @@ -1,6 +0,0 @@ -make -f Makefile.prizm clean -make -f Makefile.prizm -cp libcPNG.a ~/.local/share/giteapc/Lephenixnoir/sh-elf-gcc/lib/gcc/sh3eb-elf/11.1.0/ -cp ./png.h ~/.local/share/giteapc/Lephenixnoir/sh-elf-gcc/lib/gcc/sh3eb-elf/11.1.0/include -cp ./pngconf.h ~/.local/share/giteapc/Lephenixnoir/sh-elf-gcc/lib/gcc/sh3eb-elf/11.1.0/include -cp ./pnglibconf.h ~/.local/share/giteapc/Lephenixnoir/sh-elf-gcc/lib/gcc/sh3eb-elf/11.1.0/include diff --git a/cPNG1_5_30.cbp b/cPNG1_5_30.cbp deleted file mode 100644 index 59805be..0000000 --- a/cPNG1_5_30.cbp +++ /dev/null @@ -1,81 +0,0 @@ - - - - - - diff --git a/cPNG1_5_30.layout b/cPNG1_5_30.layout deleted file mode 100644 index 94ac952..0000000 --- a/cPNG1_5_30.layout +++ /dev/null @@ -1,10 +0,0 @@ - - - - - - - - - - diff --git a/cmake/FindcPNG.cmake b/cmake/FindcPNG.cmake index 7fdd3f7..01c1fc3 100644 --- a/cmake/FindcPNG.cmake +++ b/cmake/FindcPNG.cmake @@ -1,49 +1,18 @@ -find_package(Gint 2.7 REQUIRED) -# Find libexample.a; if we had platform-specific versions we could look for -# libexample-${FXSDK_PLATFORM}.a instead. -execute_process( - COMMAND ${CMAKE_C_COMPILER} -print-file-name=libcPNG.a - OUTPUT_VARIABLE EX_PATH OUTPUT_STRIP_TRAILING_WHITESPACE) -# EX_PATH is now the full path if libustl.a exists, "libustl.a" otherwise -if(NOT "${EX_PATH}" STREQUAL "libcPNG.a") - # Find the version.h header - execute_process( - COMMAND ${CMAKE_C_COMPILER} -print-file-name=include/pngconf.h - OUTPUT_VARIABLE EX_CONFIG OUTPUT_STRIP_TRAILING_WHITESPACE) - # Extract version information from the config.h header. This command prints - # the version on the line matching the regex and deletes every other line. - execute_process( - COMMAND sed -E "s/#define.*EX_VERSION\\s+\"(\\S+)\"$/\\1/p; d" ${EX_CONFIG} - OUTPUT_VARIABLE EX_VERSION OUTPUT_STRIP_TRAILING_WHITESPACE) -endif() -# The commands above seem common for gint libraries, so the fxSDK provides a -# helper function to get that directly. We simply provide the archive name, -# header file name, macro name, and names for output variables. -# include(FindSimpleLibrary) -# find_simple_library(libexample.a include/example/config.h "EX_VERSION" -# PATH_VAR EX_PATH VERSION_VAR EX_VERSION) -# This CMake utility will handle the version comparisons and other checks. We -# just specify: -# -> Some variables that are defined only if the library is found (so if -# they're undefined, CMake will conclude libexample was not found) -# -> The version, so CMake can compare with the user's requested one +include(FindSimpleLibrary) include(FindPackageHandleStandardArgs) -find_package_handle_standard_args(libcPNG - REQUIRED_VARS EX_CONFIG EX_VERSION - VERSION_VAR EX_VERSION) -# We now have a LibExample_FOUND variable, let's create the target that users -# can link against with target_link_libraries() -if(LibcPNG_FOUND) - # This is an imported target, we don't build it, we just claim it's here - add_library(libcPNG::libcPNG UNKNOWN IMPORTED) - # Here we declare the compiler and linker flags that every user of LibExample - # needs to use. - set_target_properties(libcPNG::libcPNG PROPERTIES - # If we specify where the library comes from, CMake will watch that file - # and relink any user application when the library is updated! - IMPORTED_LOCATION "${EX_PATH}" - # Linking options + +find_simple_library(libcPNG.a png.h "PNG_LIBPNG_VER_STRING" + PATH_VAR CPNG_PATH + VERSION_VAR CPNG_VERSION) + +find_package_handle_standard_args(cPNG + REQUIRED_VARS CPNG_PATH CPNG_VERSION + VERSION_VAR CPNG_VERSION) + +if(cPNG_FOUND) + add_library(cPNG::cPNG UNKNOWN IMPORTED) + set_target_properties(cPNG::cPNG PROPERTIES + IMPORTED_LOCATION "${CPNG_PATH}" INTERFACE_LINK_OPTIONS -lcPNG - # Dependencies (for order on the command-line) - IMPORTED_LINK_INTERFACE_LIBRARIES Gint::Gint -lczlib) + IMPORTED_LINK_INTERFACE_LIBRARIES Gint::Gint -lcZlib) endif() diff --git a/giteapc.make b/giteapc.make index 453f68d..f8cfb0d 100644 --- a/giteapc.make +++ b/giteapc.make @@ -1,26 +1,20 @@ -# giteapc: version=1 depends=Lephenixnoir/gint,Lephenixnoir/sh-elf-gcc,Lephenixnoir/fxsdk,Lephenixnoir/OpenLibm,Vhex-Kernel-Core/fxlibc +# giteapc: version=1 depends=Lephenixnoir/gint,Lephenixnoir/sh-elf-gcc,Lephenixnoir/fxsdk,Lephenixnoir/OpenLibm,Vhex-Kernel-Core/fxlibc,Slyvtt/cZlib -include giteapc-config.make configure: @ fxsdk build-fx -c - @ fxsdk build-cg -c build: @ fxsdk build-fx - @ fxsdk build-cg install: @ fxsdk build-fx install - @ fxsdk build-cg install uninstall: @ if [ -e build-fx/install_manifest.txt ]; then \ xargs rm -f < build-fx/install_manifest.txt; \ fi - @ if [ -e build-cg/install_manifest.txt ]; then \ - xargs rm -f < build-cg/install_manifest.txt; \ - fi .PHONY: configure build install uninstall diff --git a/pnglibconf.out b/pnglibconf.out deleted file mode 100644 index d641ccf..0000000 --- a/pnglibconf.out +++ /dev/null @@ -1,185 +0,0 @@ -/* pnglibconf.h - library build configuration */ - -/* libpng version 1.5.30, September 28, 2017 */ - -/* Copyright (c) 2011-2015 Glenn Randers-Pehrson */ - -/* This code is released under the libpng license. */ -/* For conditions of distribution and use, see the disclaimer */ -/* and license in png.h */ - -/* pnglibconf.h */ -/* Machine generated file: DO NOT EDIT */ -/* Derived from: scripts/pnglibconf.dfa */ -#ifndef PNGLCONF_H -#define PNGLCONF_H -/* options */ -#define PNG_16BIT_SUPPORTED -#define PNG_ALIGNED_MEMORY_SUPPORTED -/*#undef PNG_ARM_NEON_API_SUPPORTED*/ -/*#undef PNG_ARM_NEON_CHECK_SUPPORTED*/ -#define PNG_BENIGN_ERRORS_SUPPORTED -#define PNG_BUILD_GRAYSCALE_PALETTE_SUPPORTED -#define PNG_CHECK_FOR_INVALID_INDEX_SUPPORTED -#define PNG_CHECK_cHRM_SUPPORTED -#define PNG_CONSOLE_IO_SUPPORTED -#define PNG_CONVERT_tIME_SUPPORTED -#define PNG_EASY_ACCESS_SUPPORTED -/*#undef PNG_ERROR_NUMBERS_SUPPORTED*/ -#define PNG_ERROR_TEXT_SUPPORTED -#define PNG_FIXED_POINT_SUPPORTED -#define PNG_FLOATING_ARITHMETIC_SUPPORTED -#define PNG_FLOATING_POINT_SUPPORTED -#define PNG_GET_PALETTE_MAX_SUPPORTED -#define PNG_HANDLE_AS_UNKNOWN_SUPPORTED -#define PNG_INCH_CONVERSIONS_SUPPORTED -#define PNG_INFO_IMAGE_SUPPORTED -#define PNG_IO_STATE_SUPPORTED -#define PNG_MNG_FEATURES_SUPPORTED -#define PNG_POINTER_INDEXING_SUPPORTED -#define PNG_PROGRESSIVE_READ_SUPPORTED -#define PNG_READ_16BIT_SUPPORTED -#define PNG_READ_ALPHA_MODE_SUPPORTED -#define PNG_READ_ANCILLARY_CHUNKS_SUPPORTED -#define PNG_READ_BACKGROUND_SUPPORTED -#define PNG_READ_BGR_SUPPORTED -#define PNG_READ_CHECK_FOR_INVALID_INDEX_SUPPORTED -#define PNG_READ_COMPOSITE_NODIV_SUPPORTED -#define PNG_READ_COMPRESSED_TEXT_SUPPORTED -#define PNG_READ_EXPAND_16_SUPPORTED -#define PNG_READ_EXPAND_SUPPORTED -#define PNG_READ_FILLER_SUPPORTED -#define PNG_READ_GAMMA_SUPPORTED -#define PNG_READ_GET_PALETTE_MAX_SUPPORTED -#define PNG_READ_GRAY_TO_RGB_SUPPORTED -#define PNG_READ_INTERLACING_SUPPORTED -#define PNG_READ_INT_FUNCTIONS_SUPPORTED -#define PNG_READ_INVERT_ALPHA_SUPPORTED -#define PNG_READ_INVERT_SUPPORTED -#define PNG_READ_OPT_PLTE_SUPPORTED -#define PNG_READ_PACKSWAP_SUPPORTED -#define PNG_READ_PACK_SUPPORTED -#define PNG_READ_QUANTIZE_SUPPORTED -#define PNG_READ_RGB_TO_GRAY_SUPPORTED -#define PNG_READ_SCALE_16_TO_8_SUPPORTED -#define PNG_READ_SHIFT_SUPPORTED -#define PNG_READ_STRIP_16_TO_8_SUPPORTED -#define PNG_READ_STRIP_ALPHA_SUPPORTED -#define PNG_READ_SUPPORTED -#define PNG_READ_SWAP_ALPHA_SUPPORTED -#define PNG_READ_SWAP_SUPPORTED -#define PNG_READ_TEXT_SUPPORTED -#define PNG_READ_TRANSFORMS_SUPPORTED -#define PNG_READ_UNKNOWN_CHUNKS_SUPPORTED -#define PNG_READ_USER_CHUNKS_SUPPORTED -#define PNG_READ_USER_TRANSFORM_SUPPORTED -#define PNG_READ_bKGD_SUPPORTED -#define PNG_READ_cHRM_SUPPORTED -#define PNG_READ_gAMA_SUPPORTED -#define PNG_READ_hIST_SUPPORTED -#define PNG_READ_iCCP_SUPPORTED -#define PNG_READ_iTXt_SUPPORTED -#define PNG_READ_oFFs_SUPPORTED -#define PNG_READ_pCAL_SUPPORTED -#define PNG_READ_pHYs_SUPPORTED -#define PNG_READ_sBIT_SUPPORTED -#define PNG_READ_sCAL_SUPPORTED -#define PNG_READ_sPLT_SUPPORTED -#define PNG_READ_sRGB_SUPPORTED -#define PNG_READ_tEXt_SUPPORTED -#define PNG_READ_tIME_SUPPORTED -#define PNG_READ_tRNS_SUPPORTED -#define PNG_READ_zTXt_SUPPORTED -#define PNG_SAVE_INT_32_SUPPORTED -#define PNG_SEQUENTIAL_READ_SUPPORTED -#define PNG_SETJMP_SUPPORTED -/*#undef PNG_SET_OPTION_SUPPORTED*/ -#define PNG_SET_USER_LIMITS_SUPPORTED -#define PNG_STDIO_SUPPORTED -#define PNG_TEXT_SUPPORTED -#define PNG_TIME_RFC1123_SUPPORTED -#define PNG_UNKNOWN_CHUNKS_SUPPORTED -#define PNG_USER_CHUNKS_SUPPORTED -#define PNG_USER_LIMITS_SUPPORTED -#define PNG_USER_MEM_SUPPORTED -#define PNG_USER_TRANSFORM_INFO_SUPPORTED -#define PNG_USER_TRANSFORM_PTR_SUPPORTED -#define PNG_WARNINGS_SUPPORTED -#define PNG_WRITE_16BIT_SUPPORTED -#define PNG_WRITE_ANCILLARY_CHUNKS_SUPPORTED -#define PNG_WRITE_BGR_SUPPORTED -#define PNG_WRITE_CHECK_FOR_INVALID_INDEX_SUPPORTED -#define PNG_WRITE_COMPRESSED_TEXT_SUPPORTED -#define PNG_WRITE_CUSTOMIZE_COMPRESSION_SUPPORTED -#define PNG_WRITE_CUSTOMIZE_ZTXT_COMPRESSION_SUPPORTED -#define PNG_WRITE_FILLER_SUPPORTED -#define PNG_WRITE_FILTER_SUPPORTED -#define PNG_WRITE_FLUSH_SUPPORTED -#define PNG_WRITE_GET_PALETTE_MAX_SUPPORTED -#define PNG_WRITE_INTERLACING_SUPPORTED -#define PNG_WRITE_INT_FUNCTIONS_SUPPORTED -#define PNG_WRITE_INVERT_ALPHA_SUPPORTED -#define PNG_WRITE_INVERT_SUPPORTED -#define PNG_WRITE_OPTIMIZE_CMF_SUPPORTED -#define PNG_WRITE_PACKSWAP_SUPPORTED -#define PNG_WRITE_PACK_SUPPORTED -#define PNG_WRITE_SHIFT_SUPPORTED -#define PNG_WRITE_SUPPORTED -#define PNG_WRITE_SWAP_ALPHA_SUPPORTED -#define PNG_WRITE_SWAP_SUPPORTED -#define PNG_WRITE_TEXT_SUPPORTED -#define PNG_WRITE_TRANSFORMS_SUPPORTED -#define PNG_WRITE_UNKNOWN_CHUNKS_SUPPORTED -#define PNG_WRITE_USER_TRANSFORM_SUPPORTED -#define PNG_WRITE_WEIGHTED_FILTER_SUPPORTED -#define PNG_WRITE_bKGD_SUPPORTED -#define PNG_WRITE_cHRM_SUPPORTED -#define PNG_WRITE_gAMA_SUPPORTED -#define PNG_WRITE_hIST_SUPPORTED -#define PNG_WRITE_iCCP_SUPPORTED -#define PNG_WRITE_iTXt_SUPPORTED -#define PNG_WRITE_oFFs_SUPPORTED -#define PNG_WRITE_pCAL_SUPPORTED -#define PNG_WRITE_pHYs_SUPPORTED -#define PNG_WRITE_sBIT_SUPPORTED -#define PNG_WRITE_sCAL_SUPPORTED -#define PNG_WRITE_sPLT_SUPPORTED -#define PNG_WRITE_sRGB_SUPPORTED -#define PNG_WRITE_tEXt_SUPPORTED -#define PNG_WRITE_tIME_SUPPORTED -#define PNG_WRITE_tRNS_SUPPORTED -#define PNG_WRITE_zTXt_SUPPORTED -#define PNG_bKGD_SUPPORTED -#define PNG_cHRM_SUPPORTED -#define PNG_gAMA_SUPPORTED -#define PNG_hIST_SUPPORTED -#define PNG_iCCP_SUPPORTED -#define PNG_iTXt_SUPPORTED -#define PNG_oFFs_SUPPORTED -#define PNG_pCAL_SUPPORTED -#define PNG_pHYs_SUPPORTED -#define PNG_sBIT_SUPPORTED -#define PNG_sCAL_SUPPORTED -#define PNG_sPLT_SUPPORTED -#define PNG_sRGB_SUPPORTED -#define PNG_tEXt_SUPPORTED -#define PNG_tIME_SUPPORTED -#define PNG_tRNS_SUPPORTED -#define PNG_zTXt_SUPPORTED -/* end of options */ -/* settings */ -#define PNG_API_RULE 0 -#define PNG_DEFAULT_READ_MACROS 1 -#define PNG_GAMMA_THRESHOLD_FIXED 5000 -#define PNG_MAX_GAMMA_8 11 -#define PNG_QUANTIZE_BLUE_BITS 5 -#define PNG_QUANTIZE_GREEN_BITS 5 -#define PNG_QUANTIZE_RED_BITS 5 -#define PNG_USER_CHUNK_CACHE_MAX 1000 -#define PNG_USER_CHUNK_MALLOC_MAX 8000000 -#define PNG_USER_HEIGHT_MAX 1000000 -#define PNG_USER_WIDTH_MAX 1000000 -#define PNG_ZBUF_SIZE 8192 -#define PNG_sCAL_PRECISION 5 -/* end of settings */ -#endif /* PNGLCONF_H */