Replaced the Makefile with one that handles things better.
* g++ compiled DLLs seem to not be seen by Winamp when the
-static-libgcc and -static-libstdc++ flags are used.
* clang++ compiled DLLs seem to cause Winamp to crash on exit.
--- a/src/Makefile
+++ b/src/Makefile
@@ -1,67 +1,102 @@
-#SOURCES= IN_XSF IN_2SF IN_GSF IN_SNSF IN_NCSF TMP
-SOURCES= IN_XSF IN_2SF IN_GSF IN_SNSF IN_NCSF
+UNAME:= $(shell uname -s)
-IN_XSF_SRCS = ./in_xsf.cpp $(shell find . \! -name . -prune \( -iname \*.cpp -o -iname \*.c \) \! -iname tmp.cpp \! -iname XSFConfig_\*.cpp \! -iname XSFPlayer_\*.cpp \! -iname in_\*sf.cpp)
-IN_2SF_SRCS = ./XSFConfig_2SF.cpp ./XSFConfig_Winamp.cpp ./XSFPlayer_2SF.cpp $(shell find ./desmume \( -iname \*.cpp -o -iname \*.c \) \! -iname cpu_detect_x86_win.cpp \! -iname debug.cpp)
-IN_GSF_SRCS = ./XSFConfig_GSF.cpp ./XSFConfig_Winamp.cpp ./XSFPlayer_GSF.cpp $(shell find ./vbam \( -iname \*.cpp -o -iname \*.c \))
-IN_SNSF_SRCS = ./XSFConfig_SNSF.cpp ./XSFConfig_Winamp.cpp ./XSFPlayer_SNSF.cpp $(shell find ./snes9x \( -iname \*.cpp -o -iname \*.c \))
-IN_NCSF_SRCS = ./XSFConfig_NCSF.cpp ./XSFConfig_Winamp.cpp ./XSFPlayer_NCSF.cpp $(shell find ./SSEQPlayer \( -iname \*.cpp -o -iname \*.c \))
-#TMP_SRCS = ./tmp.cpp
+SRCDIR:= $(dir $(abspath $(lastword $(MAKEFILE_LIST))))
-$(foreach SOURCE,$(SOURCES),$(eval $(SOURCE)_OBJS = $(addprefix obj/,$(patsubst %.cpp,%.o,$($(SOURCE)_SRCS:.c=.o)))))
-$(foreach SOURCE,$(SOURCES),$(eval ALL_OBJS += $($(SOURCE)_OBJS)))
+FRAMEWORK_SRCS:= $(sort $(wildcard $(SRCDIR)in_xsf_framework/*.cpp))
+FRAMEWORK_OBJS:= $(subst $(SRCDIR),,$(FRAMEWORK_SRCS:%.cpp=%.o))
-#DLLS = in_2sf.dll in_gsf.dll in_snsf.dll in_ncsf.dll tmp.exe
-DLLS = in_2sf.dll in_gsf.dll in_snsf.dll in_ncsf.dll
+in_2sf_SRCS:= $(wildcard $(SRCDIR)in_2sf/*.cpp) $(wildcard $(SRCDIR)in_2sf/desmume/*.cpp) $(wildcard $(SRCDIR)in_2sf/desmume/addons/*.cpp) \
+ $(wildcard $(SRCDIR)in_2sf/desmume/metaspu/*.cpp) $(wildcard $(SRCDIR)in_2sf/desmume/metaspu/SoundTouch/*.cpp) \
+ $(wildcard $(SRCDIR)in_2sf/desmume/utils/*.cpp) $(wildcard $(SRCDIR)in_2sf/desmume/utils/AsmJit/*.cpp) \
+ $(wildcard $(SRCDIR)in_2sf/desmume/utils/AsmJit/base/*.cpp) $(wildcard $(SRCDIR)in_2sf/desmume/utils/AsmJit/x86/*.cpp)
+in_2sf_SRCS:= $(filter-out $(SRCDIR)in_2sf/desmume/debug.cpp $(SRCDIR)in_2sf/desmume/metaspu/SoundTouch/cpu_detect_x86_win.cpp,$(in_2sf_SRCS))
+in_gsf_SRCS:= $(wildcard $(SRCDIR)in_gsf/*.cpp) $(wildcard $(SRCDIR)in_gsf/vbam/apu/*.cpp) $(wildcard $(SRCDIR)in_gsf/vbam/gba/*.cpp)
+in_ncsf_SRCS:= $(wildcard $(SRCDIR)in_ncsf/*.cpp) $(wildcard $(SRCDIR)in_ncsf/SSEQPlayer/*.cpp)
+in_snsf_SRCS:= $(wildcard $(SRCDIR)in_snsf/*.cpp) $(wildcard $(SRCDIR)in_snsf/snes9x/*.cpp) $(wildcard $(SRCDIR)in_snsf/snes9x/apu/*.cpp)
-$(foreach FILE,$(ALL_OBJS),$(shell mkdir -p $(dir $(FILE))))
+DLLS= in_2sf in_gsf in_ncsf in_snsf
+DLLS:= $(sort $(addsuffix .dll,$(DLLS)))
-CXX ?= g++
-CFLAGS ?= -pipe -pedantic -Wall -Wextra -Winit-self -Wfloat-equal -Wshadow -Wcast-qual -Wlogical-op -Wunreachable-code -Wabi -Wno-unused-parameter -Wno-variadic-macros -Wno-strict-aliasing
-CXXFLAGS ?= -Woverloaded-virtual
+COMPILER:= $(shell $(CXX) -v 2>/dev/stdout)
-obj/%.o : %.c
- @echo "Compiling $^..."
- @$(CC) -std=gnu99 $(CFLAGS) -Wc++-compat -DWINAMP_PLUGIN -D_WINDOWS -I. $(EXTRA_INCLUDES) -I/c/Program\ Files/Winamp\ SDK -o $@ -c $^
+CPPFLAGS+= -std=gnu++11 -I$(SRCDIR)in_xsf_framework -I/g/Code/Winamp\ SDK -DWINAMP_PLUGIN -DUNICODE_INPUT_PLUGIN
+CXXFLAGS+= -std=gnu++11 -pipe -Wall -Wctor-dtor-privacy -Wold-style-cast -Wextra -Wno-div-by-zero -Wfloat-equal -Wshadow -Winit-self -Wcast-qual -Wunreachable-code -Wabi -Woverloaded-virtual -Wno-long-long -I$(SRCDIR)in_xsf_framework -I/g/Code/Winamp\ SDK -DWINAMP_PLUGIN -DUNICODE_INPUT_PLUGIN
+ifeq (,$(findstring clang,$(COMPILER)))
+CXXFLAGS+= -Wlogical-op
+endif
+LDFLAGS+= -lz
-obj/%.o : %.cpp
- @echo "Compiling $^..."
- @$(CXX) -std=gnu++98 $(CFLAGS) $(CXXFLAGS) -DWINAMP_PLUGIN -D_WINDOWS -I. $(EXTRA_INCLUDES) -I/c/Program\ Files/Winamp\ SDK -o $@ -c $^
+ifneq (,$(findstring MINGW,$(UNAME)))
+ifeq (,$(findstring clang,$(COMPILER)))
+LDFLAGS+= -static-libgcc -static-libstdc++
+endif
+endif
-.PHONY: clean all profile debug optimized
+DLL_SRCS_template= $(1)_SRCS:= $$(sort $$($(1)_SRCS))
+DLL_OBJS_template= $(1)_OBJS:= $$(subst $(SRCDIR),,$$($(1)_SRCS:%.cpp=%.o))
+
+$(foreach dll,$(DLLS),$(eval $(call DLL_SRCS_template,$(basename $(notdir $(dll))))))
+$(foreach dll,$(DLLS),$(eval $(call DLL_OBJS_template,$(basename $(notdir $(dll))))))
+
+SRCS:= $(sort $(FRAMEWORK_SRCS) $(foreach dll,$(DLLS),$($(basename $(notdir $(dll)))_SRCS)))
+OBJS:= $(sort $(FRAMEWORK_OBJS) $(foreach dll,$(DLLS),$($(basename $(notdir $(dll)))_OBJS)))
+DEPS:= $(OBJS:%.o=%.d)
+
+.PHONY: all debug clean
+
+.SUFFIXES:
+.SUFFIXES: .cpp .o .d .a .dll
all: $(DLLS)
-profile: CFLAGS += -g -pg
-profile: all
-debug: CFLAGS += -g
+debug: CXXFLAGS+= -g -D_DEBUG
debug: all
-optimized: CFLAGS += -O3
-optimized: all
-$(IN_XSF_OBJS): CXXFLAGS += -Weffc++
-$(IN_2SF_OBJS): EXTRA_INCLUDES = -Idesmume
-$(IN_2SF_OBJS): CFLAGS += -DHAVE_LIBZ
-in_2sf.dll: $(IN_XSF_OBJS) $(IN_2SF_OBJS)
- @echo "Linking $@..."
- @$(CXX) $(CFLAGS) -static-libgcc -static-libstdc++ -shared -o $@ $^ -lz -lgdi32
-$(IN_GSF_OBJS): EXTRA_INCLUDES = -Ivbam
-$(IN_GSF_OBJS): CFLAGS += -DNO_DEBUGGER -DFINAL_VERSION
-in_gsf.dll: $(IN_XSF_OBJS) $(IN_GSF_OBJS)
- @echo "Linking $@..."
- @$(CXX) $(CFLAGS) -static-libgcc -static-libstdc++ -shared -o $@ $^ -lz -lgdi32
-$(IN_SNSF_OBJS): EXTRA_INCLUDES = -Isnes9x
-in_snsf.dll: $(IN_XSF_OBJS) $(IN_SNSF_OBJS)
- @echo "Linking $@..."
- @$(CXX) $(CFLAGS) -static-libgcc -static-libstdc++ -shared -o $@ $^ -lz -lgdi32
-$(IN_NCSF_OBJS): EXTRA_INCLUDES = -ISSEQPlayer
-in_snsf.dll: $(IN_XSF_OBJS) $(IN_NCSF_OBJS)
- @echo "Linking $@..."
- @$(CXX) $(CFLAGS) -static-libgcc -static-libstdc++ -shared -o $@ $^ -lz -lgdi32
-tmp.exe: $(IN_XSF_OBJS) $(IN_2SF_OBJS) $(TMP_OBJS)
- @echo "Linking $@..."
- @$(CXX) $(CFLAGS) -static-libgcc -static-libstdc++ -o $@ $^ -lz -lgdi32
+define DLL_template
+$(1): $$(FRAMEWORK_OBJS) $$($$(basename $$(notdir $(1)))_OBJS)
+ @echo "Linking $$@..."
+ @$$(CXX) -shared -fPIC $$(CXXFLAGS) -o $$@ $$^ $$(LDFLAGS)
+endef
+define SRC_template
+$$(subst $(SRCDIR),,$(1:%.cpp=%.o)): $(1)
+ @echo "Compiling $$<..."
+ @$$(CXX) $$(CXXFLAGS) -o $$(subst $(SRCDIR),,$$@) -c $$<
+endef
+define DEP_template
+$$(subst $(SRCDIR),,$(1:%.cpp=%.d)): $(1)
+ @echo "Calculating depends for $$<..."
+ -@mkdir -p $$(@D)
+ @$$(CXX) $$(CPPFLAGS) -MM -MF $$(subst $(SRCDIR),,$$@).tmp $$<
+ @sed 's,$$(notdir $$*)\.o[ :]*,$$(subst /,\/,$$*).o $$(subst /,\/,$$@): ,g' < $$(subst $(SRCDIR),,$$@).tmp > $$(subst $(SRCDIR),,$$@)
+ @rm $$(subst $(SRCDIR),,$$@).tmp
+endef
+
+$(foreach dll,$(DLLS),$(eval $(call DLL_template,$(dll))))
+$(foreach src,$(SRCS),$(eval $(call SRC_template,$(src))))
+$(foreach src,$(SRCS),$(eval $(call DEP_template,$(src))))
+
+$(subst $(SRCDIR),,$(in_2sf_SRCS:%.cpp=%.d)): CPPFLAGS+= -msse
+$(in_2sf_OBJS): CXXFLAGS+= -msse -DHAVE_LIBZ
+
+in_2sf/desmume/MMU.o: CXXFLAGS+= -Wno-shadow
+in_2sf/desmume/utils/AsmJit/base/codegen.o: CXXFLAGS+= -Wno-unused-value
+in_2sf/desmume/utils/AsmJit/base/runtime.o: CXXFLAGS+= -Wno-unused-parameter
+in_2sf/desmume/utils/AsmJit/base/vmem.o: CXXFLAGS+= -Wno-missing-field-initializers -Wno-unused-function
+ifneq (,$(findstring clang,$(COMPILER)))
+in_2sf/desmume/utils/AsmJit/base/vmem.o: CXXFLAGS+= -Wno-missing-braces
+endif
+in_2sf/desmume/utils/AsmJit/x86/x86assembler.o: CXXFLAGS+= -Wno-unused-variable
+ifneq (,$(findstring clang,$(COMPILER)))
+in_2sf/desmume/utils/AsmJit/x86/x86assembler.o: CXXFLAGS+= -Wno-missing-braces
+endif
+in_2sf/desmume/utils/AsmJit/x86/x86context.o: CXXFLAGS+= -Wno-unused-parameter -Wno-unused-value -Wno-unused-variable
+in_gsf/vbam/gba/GBA-arm.o: CXXFLAGS+= -Wno-unused-variable
+ifeq (,$(findstring clang,$(COMPILER)))
+in_gsf/vbam/gba/GBA-arm.o: CXXFLAGS+= -Wno-unused-but-set-variable
+endif
clean:
- @echo "Cleaning DLLs and OBJs..."
- @-rm -f $(DLLS) $(ALL_OBJS)
+ @echo "Cleaning OBJs and DLLs..."
+ -@rm $(OBJS) $(DLLS)
+-include $(DEPS)
+
--- a/src/in_2sf/desmume/mc.cpp
+++ b/src/in_2sf/desmume/mc.cpp
@@ -427,8 +427,6 @@
for (int t = 0; t < cc; ++t)
dst[dst_pos++] = src[src_pos++];
}
- size = dst_pos;
- return 0;
}
return 200;
}
--- a/src/in_xsf_framework/in_xsf.cpp
+++ b/src/in_xsf_framework/in_xsf.cpp
@@ -1,7 +1,7 @@
/*
* xSF - Winamp plugin
* By Naram Qashat (CyberBotX) [cyberbotx@cyberbotx.com]
- * Last modification on 2014-09-17
+ * Last modification on 2014-09-18
*
* Partially based on the vio*sf framework
*/
@@ -422,10 +422,12 @@
return 1;
}
+#ifdef _MSC_VER
extern "C" __declspec(dllexport) int winampClearExtendedFileInfoW(const wchar_t *)
{
return 0;
}
+#endif
intptr_t wrapperWinampGetExtendedRead_open(std::unique_ptr<XSFPlayer> tmpxSFPlayer, int *size, int *bps, int *nch, int *srate)
{