From 497eac2c472b3b5bed4fa8a35e09b9a48cda1108 Mon Sep 17 00:00:00 2001 From: Slyvtt Date: Thu, 5 May 2022 22:05:33 +0200 Subject: [PATCH] making giteapc compatibility --- CMakeLists.txt | 47 +++++++++++ IMG.c | 17 +--- Makefile.prizm | 4 +- README.md | 28 +++++++ cSDL_image1_2_12.layout | 131 +++++++++++++++++++------------ cmake/FindcSDL_image_prizm.cmake | 49 ++++++++++++ giteapc.make | 26 ++++++ 7 files changed, 235 insertions(+), 67 deletions(-) create mode 100644 CMakeLists.txt create mode 100644 README.md create mode 100644 cmake/FindcSDL_image_prizm.cmake create mode 100644 giteapc.make diff --git a/CMakeLists.txt b/CMakeLists.txt new file mode 100644 index 0000000..f7d5669 --- /dev/null +++ b/CMakeLists.txt @@ -0,0 +1,47 @@ +# SDL_image_prizm: build system + +cmake_minimum_required(VERSION 3.16) +project(LibSDL_image VERSION 1.2.12 LANGUAGES C) + +# Libraries that libexample depends on +find_package(Gint 2.7.1 REQUIRED) + + +set(SOURCES + IMG.c + IMG_bmp.c + IMG_gif.c + IMG_jpg.c + IMG_lbm.c + IMG_pcx.c + IMG_png.c + IMG_pnm.c + IMG_tga.c + IMG_tif.c + IMG_webp.c + IMG_xcf.c + IMG_xpm.c + IMG_xv.c +) + +include_directories( + "${PROJECT_SOURCE_DIR}" + "${FXSDK_COMPILER_INSTALL}/include" + "${FXSDK_COMPILER_INSTALL}/include/openlibm") +add_compile_options(-Os -lm -m4-nofpu -mb -std=c11 -ffreestanding -nostdlib -Wa,--dsp -lcPNG -lczlib -lSDL_prizm -DLOAD_GIF -DLOAD_LBM -DLOAD_PCX -DLOAD_PNM -DLOAD_TGA -DLOAD_XCF -DLOAD_BMP -DLOAD_PNG) + +# Target name is "SDL_image_prizm", output file is "libSDL_image_prizm.a" (by default) +add_library(SDL_image_prizm STATIC ${SOURCES}) + +# After building, install the target (that is, SDL_image_prizm.a) in the compiler +install(TARGETS SDL_image_prizm + DESTINATION "${FXSDK_COMPILER_INSTALL}") + +# Install zlib.h from the build dir +install(FILES "${PROJECT_SOURCE_DIR}/SDL/SDL_image.h" + DESTINATION "${FXSDK_COMPILER_INSTALL}/include") + +# Install FindSDL_prizm.cmake so that users can do find_package(LibSDL_prizm) +install(FILES cmake/FindcSDL_image_prizm.cmake + DESTINATION "${FXSDK_CMAKE_MODULE_PATH}") + diff --git a/IMG.c b/IMG.c index 81cb354..0450518 100644 --- a/IMG.c +++ b/IMG.c @@ -149,22 +149,18 @@ SDL_Surface *IMG_Load_RW(SDL_RWops *src, int freesrc) /* Load an image from an SDL datasource, optionally specifying the type */ SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type) { - cSDL_LogToFile( "IMG_LoadTypeRW : %p - %d - %s", src, freesrc, type ); - int i; SDL_Surface *image; /* Make sure there is something to do.. */ if ( src == NULL ) { IMG_SetError("Passed a NULL data source"); - cSDL_LogToFile( "IMG_LoadTypeRW : src is NULL !!!" ); return(NULL); } /* See whether or not this data source can handle seeking */ if ( SDL_RWseek(src, 0, RW_SEEK_CUR) < 0 ) { IMG_SetError("Can't seek in this data source"); - cSDL_LogToFile( "IMG_LoadTypeRW : can't seek in the file !!!" ); if(freesrc) SDL_RWclose(src); return(NULL); @@ -176,19 +172,14 @@ SDL_Surface *IMG_LoadTyped_RW(SDL_RWops *src, int freesrc, char *type) if(type && IMG_string_equals(type, "TGA")) image = IMG_LoadTGA_RW(src); else if(IMG_isCUR(src)) image = IMG_LoadCUR_RW(src); else if(IMG_isICO(src)) image = IMG_LoadICO_RW(src); - - //else if(IMG_isBMP(src)) cSDL_LogToFile( "IMG_LoadTypeRW : will now call IMG_LoadBMP_RW" ), image = IMG_LoadBMP_RW(src); - else if(type && IMG_string_equals(type, "BMP")) image = IMG_LoadBMP_RW(src); - + else if(IMG_isBMP(src)) image = IMG_LoadBMP_RW(src); else if(IMG_isGIF(src)) image = IMG_LoadGIF_RW(src); else if(IMG_isJPG(src)) image = IMG_LoadJPG_RW(src); - else if(IMG_isLBM(src)) image = IMG_LoadLBM_RW(src); else if(IMG_isPCX(src)) image = IMG_LoadPCX_RW(src); - - //else if(IMG_isPNG(src)) cSDL_LogToFile( "IMG_LoadTypeRW : will now call IMG_LoadPNG_RW" ), image = IMG_LoadPNG_RW(src); - else if(type && IMG_string_equals(type, "PNG")) image = IMG_LoadPNG_RW(src); - + else if(IMG_isPNG(src)) image = IMG_LoadPNG_RW(src); else if(IMG_isPNM(src)) image = IMG_LoadPNM_RW(src); + + else if(IMG_isLBM(src)) image = IMG_LoadLBM_RW(src); else if(IMG_isTIF(src)) image = IMG_LoadTIF_RW(src); else if(IMG_isXCF(src)) image = IMG_LoadXCF_RW(src); else if(IMG_isXPM(src)) image = IMG_LoadXPM_RW(src); diff --git a/Makefile.prizm b/Makefile.prizm index 1608449..60f199c 100644 --- a/Makefile.prizm +++ b/Makefile.prizm @@ -1,10 +1,10 @@ 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) -lm -m4-nofpu -mb -ffreestanding -nostdlib -lcPNG -lczlib -lSDL_prizm -Wa,--dsp -DLOAD_GIF -DLOAD_LBM -DLOAD_PCX -DLOAD_PNM -DLOAD_TGA -DLOAD_XCF -DLOAD_BMP -DLOAD_PNG +CFLAGS = -O2 $(INCLUDE) -lm -m4-nofpu -mb -ffreestanding -nostdlib -lcJPG -lcPNG -lczlib -lSDL_prizm -Wa,--dsp -DLOAD_GIF -LOAD_JPG -DLOAD_LBM -DLOAD_PCX -DLOAD_PNM -DLOAD_TGA -DLOAD_XCF -DLOAD_BMP -DLOAD_PNG AR = sh-elf-gcc-ar RANLIB = sh-elf-gcc-ranlib CC = sh-elf-gcc -CONFIG_H = +CONFIG_H = TARGET = libSDL_image_prizm.a SOURCES = \ IMG.c \ diff --git a/README.md b/README.md new file mode 100644 index 0000000..44bf3cd --- /dev/null +++ b/README.md @@ -0,0 +1,28 @@ +# libSDL_image 1.2.12 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 + +**Note:** libSDL_image is configured to support PNG, so you need to have : +- a working libPNG, see here : [libPNG for PRIZM](https://gitea.planet-casio.com/Slyvtt/cPNG1_5_30), +- and also requires Zlib available, so the very first step is to get these libraries 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). +- and a working copy of SDL 1.2 that you can get here : [libSDL for PRIZM](https://gitea.planet-casio.com/Slyvtt/cSDL1_2_15) + +## Automatic installation using giteapc + +You can also use the `gitea install Slyvtt/cSDL_image1_2_12` command to get an automatic install + +when you compile a program for use with libSDL_image, do not forget to add a `-lSDL_image_prizm -lcPNG -lczlib -lSDL_prizm` option in your compilator command line. + +and then a `#include ` in your C/C++ sources + + +## Manual compilation using a Makefile + +Compilation is done by using the adhoc Makefile : +`make -f Makefile.prizm` in the main directory + +It should produce the library libSDL_image_prizm.a and copy everything in the right place. + +The following steps are not automatically done, so please proceed with the following manipulations : +* copy the library `libSDL_image_prizm.a` into your SH3/SH4 compiler lib folder +* copy `SDL_image.h` file contained in the SDL/ folder into the include/SDL folder of the SH3/SH4 compiler diff --git a/cSDL_image1_2_12.layout b/cSDL_image1_2_12.layout index 7e5ac01..f9501c2 100644 --- a/cSDL_image1_2_12.layout +++ b/cSDL_image1_2_12.layout @@ -2,34 +2,14 @@ - - - - - - - - - - - - - - - - - - - - - + @@ -39,42 +19,37 @@ + - + - + - - - - - - - - - + + + + + + + + - + - + - + - - - - - - + @@ -82,19 +57,14 @@ - + - + - - - - - - + - + @@ -102,14 +72,71 @@ + + + + + + + + + + + + + + - + - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/cmake/FindcSDL_image_prizm.cmake b/cmake/FindcSDL_image_prizm.cmake new file mode 100644 index 0000000..59df1c6 --- /dev/null +++ b/cmake/FindcSDL_image_prizm.cmake @@ -0,0 +1,49 @@ +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=libSDL_image_prizm.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 "libSDL_image_prizm.a") + # Find the version.h header + execute_process( + COMMAND ${CMAKE_C_COMPILER} -print-file-name=include/zconf.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(FindPackageHandleStandardArgs) +find_package_handle_standard_args(libczlib + 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(LibSDL_image_prizm_FOUND) + # This is an imported target, we don't build it, we just claim it's here + add_library(libSDL_image_prizm::libSDL_image_prizm UNKNOWN IMPORTED) + # Here we declare the compiler and linker flags that every user of LibExample + # needs to use. + set_target_properties(libSDL_image_prizm::libSDL_image_prizm 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 + INTERFACE_LINK_OPTIONS -lSDL_image_prizm + # Dependencies (for order on the command-line) + IMPORTED_LINK_INTERFACE_LIBRARIES Gint::Gint) +endif() diff --git a/giteapc.make b/giteapc.make new file mode 100644 index 0000000..453f68d --- /dev/null +++ b/giteapc.make @@ -0,0 +1,26 @@ +# giteapc: version=1 depends=Lephenixnoir/gint,Lephenixnoir/sh-elf-gcc,Lephenixnoir/fxsdk,Lephenixnoir/OpenLibm,Vhex-Kernel-Core/fxlibc +-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 +