Skip to content

Commit

Permalink
Libretro: support builds for windows/mac
Browse files Browse the repository at this point in the history
  • Loading branch information
jonian committed Aug 10, 2024
1 parent cd28c06 commit 3d1214b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
/eboot.bin
/noods
/noods*.so
/noods*.dll
/noods*.dylib
/noods.aab
/NooDS.app
/NooDS.dmg
Expand Down
16 changes: 14 additions & 2 deletions Makefile.libretro
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@ CPPFILES := $(foreach dir,$(SRCS),$(wildcard $(dir)/*.cpp))
HFILES := $(foreach dir,$(SRCS),$(wildcard $(dir)/*.h))
OFILES := $(patsubst %.cpp,$(BUILD)/%.o,$(CPPFILES))

ifeq ($(OS),Windows_NT)
ARGS += -static -DWINDOWS
SHARED_EXT := .dll
else
ifeq ($(shell uname -s),Darwin)
ARGS += -DMACOS
SHARED_EXT := .dylib
else
SHARED_EXT := .so
endif
endif

all: $(NAME)

$(NAME): $(OFILES)
g++ -shared -o $@.so $(ARGS) $^ $(LIBS)
g++ -shared -o $@$(SHARED_EXT) $(ARGS) $^ $(LIBS)

$(BUILD)/%.o: %.cpp $(HFILES) $(BUILD)
g++ -c -fPIC -o $@ $(ARGS) $(INCS) $<
Expand All @@ -21,4 +33,4 @@ $(BUILD):

clean:
rm -rf $(BUILD)
rm -f $(NAME).so
rm -f $(NAME)$(SHARED_EXT)
13 changes: 8 additions & 5 deletions src/libretro/libretro.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
#include <cstdarg>
#include <algorithm>
#include <cstring>
#include <regex>

#include <fcntl.h>
#include <fstream>
Expand Down Expand Up @@ -110,10 +111,12 @@ static int32_t clampValue(int32_t value, int32_t min, int32_t max)

static std::string normalizePath(std::string path, bool addSlash = false)
{
std::string normalizedPath = path;
if (addSlash && normalizedPath.back() != '/')
normalizedPath += '/';
return normalizedPath;
std::string newPath = path;
if (addSlash && newPath.back() != '/') newPath += '/';
#ifdef WINDOWS
std::replace(newPath.begin(), newPath.end(), '\\', '/');
#endif
return newPath;
}

static std::string getNameFromPath(std::string path)
Expand Down Expand Up @@ -743,7 +746,7 @@ bool retro_load_game_special(unsigned type, const struct retro_game_info* info,

for (size_t i = 0; i < info_size; i++)
{
std::string path = info[i].path;
std::string path = normalizePath(info[i].path);

if (path.find(".nds", path.length() - 4) != std::string::npos)
ndsPath = path;
Expand Down

0 comments on commit 3d1214b

Please sign in to comment.