Files
RetroArch/samples/tasks/database/Makefile
T
U-DESKTOP-SPFP6AQ\twistedtechre 96ec45a82f samples/tasks: repair database demo, add decompress test
Two related changes under samples/tasks/.

samples/tasks/database: restore a buildable state

  The database demo had bit-rotted to the point where neither the
  C source nor the Makefile matched the current tree:

    * main_msg_queue_push: retro_task_queue_msg_t gained a
      retro_task_t* first parameter
    * main_db_cb: retro_task_callback_t gained the same
    * core_info_init_list: added a sixth bool *cache_supported
      parameter
    * Makefile: hash/rhash.c was renamed to hash/lrc_hash.c
    * Makefile: 7zip source list was stale -- 7zIn.c was renamed to
      7zArcIn.c, and BraIA64.c / CpuArch.c / Delta.c were added
    * Makefile: missing sources for trans_stream*, rzip_stream,
      features_cpu, rtime, rxml, m3u_file, logiqx_dat,
      manual_content_scan, yxml
    * link: missing -lm for roundf

  Several symbols reached via task_push_dbscan are defined only
  when RARCH_INTERNAL is set, which would transitively require
  linking most of retroarch.c, frontend_driver.c, runloop.c,
  configuration.c and the UI/video subsystems.  Since this sample
  exercises only the task queue, it provides lightweight stubs for:

    * msg_hash_get_help_us_enum  (real def in intl/msg_hash_us.c)
    * msg_hash_to_str_us         (real def in intl/msg_hash_us.c)
    * config_get_ptr             (real def in configuration.c)
    * runloop_msg_queue_push     (real def in runloop.c)
    * retroarch_override_setting_is_set
    * ui_companion_driver_notify_refresh
    * video_display_server_set_window_progress
    * frontend_driver_get_free_memory
    * dir_list_new_special       (real def in retroarch.c)

  All stubs are either no-ops or return a conservative value that
  lets the surrounding code bail gracefully; none of them are
  exercised on the happy dbscan path.

  After these changes the demo builds cleanly on a stock Ubuntu
  host (build-essential, zlib1g-dev, libpthread), and both
  `database_task` with no args and `database_task <5 dirs>` exit
  with the expected status.

samples/tasks/decompress: new standalone regression test

  Adds archive_name_safety_test, a 23-case predicate unit test for
  the archive_name_is_safe() function in tasks/task_decompress.c.

  This test was originally developed alongside the Zip Slip patch
  in the first security round and held out of
  libretro-common/samples/ because it exercises code in tasks/
  rather than libretro-common/.  samples/tasks/ is its natural
  home.

  The test keeps a verbatim copy of the predicate and validates it
  against a table of safe / unsafe paths:

    * safe:   file.txt, dir/file.txt, a.b/c, ..foo, foo..
    * unsafe: .., ../etc/passwd, foo/..//bar, /etc/passwd,
              \windows\system32, C:\evil, c:/evil, ..\..\windows,
              foo\..\bar, empty string, NULL

  If the predicate in task_decompress.c is ever edited, the copy
  here must be updated to match -- this is noted in the test file's
  header.
2026-04-19 18:24:46 +02:00

219 lines
5.4 KiB
Makefile

compiler := gcc
extra_flags :=
use_neon := 0
release := release
EXE_EXT :=
TARGET := database_task
HAVE_ZLIB := 1
HAVE_7ZIP := 1
HAVE_THREADS := 1
ifeq ($(platform),)
platform = unix
ifeq ($(shell uname -a),)
platform = win
else ifneq ($(findstring MINGW,$(shell uname -a)),)
platform = win
else ifneq ($(findstring Darwin,$(shell uname -a)),)
platform = osx
arch = intel
ifeq ($(shell uname -p),powerpc)
arch = ppc
endif
else ifneq ($(findstring win,$(shell uname -a)),)
platform = win
endif
endif
ifeq ($(compiler),gcc)
extra_rules_gcc := $(shell $(compiler) -dumpmachine)
endif
ifneq (,$(findstring armv7,$(extra_rules_gcc)))
extra_flags += -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon
CFLAGS += -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon
CXXFLAGS += -mcpu=cortex-a9 -mtune=cortex-a9 -mfpu=neon
use_neon := 1
endif
ifneq (,$(findstring hardfloat,$(extra_rules_gcc)))
extra_flags += -mfloat-abi=hard
CFLAGS += -mfloat-abi=hard
CXXFLAGS += -mfloat-abi=hard
endif
ifeq ($(build),)
build = release
endif
ifeq ($(DEBUG), 1)
build = debug
endif
ifeq (release,$(build))
extra_flags += -O2
CFLAGS += -O2
CXXFLAGS += -O2
LDFLAGS += -O2
endif
ifeq (debug,$(build))
extra_flags += -O0 -g
CFLAGS += -O0 -g
CXXFLAGS += -O0 -g
LDFLAGS += -O0 -g
endif
ifneq ($(SANITIZER),)
CFLAGS := -fsanitize=$(SANITIZER) $(CFLAGS)
CXXFLAGS := -fsanitize=$(SANITIZER) $(CXXFLAGS)
LDFLAGS := -fsanitize=$(SANITIZER) $(LDFLAGS)
endif
EXE_EXT :=
ifeq ($(platform), unix)
else ifeq ($(platform), osx)
compiler := $(CC)
else
EXE_EXT = .exe
endif
CORE_DIR = ../../..
DEPS_DIR = $(CORE_DIR)/deps
LIBRETRO_COMM_DIR = $(CORE_DIR)/libretro-common
INCDIRS := -I$(LIBRETRO_COMM_DIR)/include
CC := $(compiler)
CXX := $(subst CC,++,$(compiler))
asflags := $(extra_flags)
flags += -std=c99
SOURCES_C := \
$(CORE_DIR)/samples/tasks/database/main.c \
$(CORE_DIR)/tasks/task_database.c \
$(CORE_DIR)/tasks/task_database_cue.c \
$(CORE_DIR)/database_info.c \
$(CORE_DIR)/core_info.c \
$(CORE_DIR)/msg_hash.c \
$(CORE_DIR)/playlist.c \
$(CORE_DIR)/manual_content_scan.c \
$(CORE_DIR)/verbosity.c \
$(LIBRETRO_COMM_DIR)/formats/m3u/m3u_file.c \
$(LIBRETRO_COMM_DIR)/formats/logiqx_dat/logiqx_dat.c \
$(CORE_DIR)/libretro-db/bintree.c \
$(CORE_DIR)/libretro-db/libretrodb.c \
$(CORE_DIR)/libretro-db/query.c \
$(CORE_DIR)/libretro-db/rmsgpack.c \
$(CORE_DIR)/libretro-db/rmsgpack_dom.c \
$(LIBRETRO_COMM_DIR)/file/archive_file.c \
$(LIBRETRO_COMM_DIR)/file/config_file.c \
$(LIBRETRO_COMM_DIR)/file/file_path.c \
$(LIBRETRO_COMM_DIR)/file/file_path_io.c \
$(LIBRETRO_COMM_DIR)/file/retro_dirent.c \
$(LIBRETRO_COMM_DIR)/hash/lrc_hash.c \
$(LIBRETRO_COMM_DIR)/compat/compat_fnmatch.c \
$(LIBRETRO_COMM_DIR)/compat/compat_posix_string.c \
$(LIBRETRO_COMM_DIR)/compat/compat_strcasestr.c \
$(LIBRETRO_COMM_DIR)/compat/compat_strl.c \
$(LIBRETRO_COMM_DIR)/compat/fopen_utf8.c \
$(DEPS_DIR)/yxml/yxml.c \
$(LIBRETRO_COMM_DIR)/formats/json/rjson.c \
$(LIBRETRO_COMM_DIR)/formats/xml/rxml.c \
$(LIBRETRO_COMM_DIR)/encodings/encoding_crc32.c \
$(LIBRETRO_COMM_DIR)/encodings/encoding_utf.c \
$(LIBRETRO_COMM_DIR)/features/features_cpu.c \
$(LIBRETRO_COMM_DIR)/queues/task_queue.c \
$(LIBRETRO_COMM_DIR)/lists/dir_list.c \
$(LIBRETRO_COMM_DIR)/lists/string_list.c \
$(LIBRETRO_COMM_DIR)/streams/interface_stream.c \
$(LIBRETRO_COMM_DIR)/streams/memory_stream.c \
$(LIBRETRO_COMM_DIR)/streams/file_stream.c \
$(LIBRETRO_COMM_DIR)/streams/rzip_stream.c \
$(LIBRETRO_COMM_DIR)/streams/trans_stream.c \
$(LIBRETRO_COMM_DIR)/streams/trans_stream_pipe.c \
$(LIBRETRO_COMM_DIR)/string/stdstring.c \
$(LIBRETRO_COMM_DIR)/time/rtime.c \
$(LIBRETRO_COMM_DIR)/vfs/vfs_implementation.c
DEFINES = -DHAVE_LIBRETRODB -DHAVE_COMPRESSION
ifeq ($(HAVE_ZLIB), 1)
SOURCES_C += \
$(LIBRETRO_COMM_DIR)/file/archive_file_zlib.c \
$(LIBRETRO_COMM_DIR)/streams/trans_stream_zlib.c
DEFINES += -DHAVE_ZLIB
LIBS += -lz
LIBS += -lm
endif
ifeq ($(HAVE_7ZIP), 1)
SOURCES_C += \
$(LIBRETRO_COMM_DIR)/file/archive_file_7z.c
DEFINES += -DHAVE_7ZIP -D_7ZIP_ST
INCDIRS += -I$(DEPS_DIR)
SOURCES_C += $(DEPS_DIR)/7zip/7zArcIn.c \
$(DEPS_DIR)/7zip/7zBuf.c \
$(DEPS_DIR)/7zip/7zCrc.c \
$(DEPS_DIR)/7zip/7zCrcOpt.c \
$(DEPS_DIR)/7zip/7zDec.c \
$(DEPS_DIR)/7zip/7zFile.c \
$(DEPS_DIR)/7zip/7zStream.c \
$(DEPS_DIR)/7zip/Bcj2.c \
$(DEPS_DIR)/7zip/Bra.c \
$(DEPS_DIR)/7zip/Bra86.c \
$(DEPS_DIR)/7zip/BraIA64.c \
$(DEPS_DIR)/7zip/CpuArch.c \
$(DEPS_DIR)/7zip/Delta.c \
$(DEPS_DIR)/7zip/LzFind.c \
$(DEPS_DIR)/7zip/Lzma2Dec.c \
$(DEPS_DIR)/7zip/LzmaDec.c \
$(DEPS_DIR)/7zip/LzmaEnc.c
endif
ifeq ($(HAVE_THREADS), 1)
SOURCES_C += \
$(LIBRETRO_COMM_DIR)/rthreads/rthreads.c
DEFINES += -DHAVE_THREADS
ifeq (,$(findstring MSYS,$(uname -s)))
LIBS += -lpthread
endif
endif
flags := $(INCDIRS)
INCFLAGS := $(INCDIRS)
CFLAGS += $(DEFINES)
CXXFLAGS += $(DEFINES)
OBJECTS = $(SOURCES_C:.c=.o)
OBJOUT = -o
LINKOUT = -o
ifneq (,$(findstring msvc,$(platform)))
OBJOUT = -Fo
LINKOUT = -out:
ifeq ($(STATIC_LINKING),1)
LD ?= lib.exe
else
LD = link.exe
endif
else
LD = $(CC)
endif
all: $(TARGET)$(EXE_EXT)
$(TARGET)$(EXE_EXT): $(OBJECTS)
$(LD) $(LINKOUT)$@ $(SHARED) $(OBJECTS) $(LDFLAGS) $(LIBS)
%.o: %.c
$(CC) $(INCFLAGS) $(CFLAGS) -c $(OBJOUT)$@ $<
%.o: %.cpp
$(CXX) $(INCFLAGS) $(CXXFLAGS) -c $(OBJOUT)$@ $<
clean:
rm -f $(OBJECTS)