Skip to content

Commit

Permalink
(#16) Reenable Windows build script, fix a bunch of Windows errors/wa…
Browse files Browse the repository at this point in the history
…rnings
  • Loading branch information
Alcaro committed Feb 26, 2019
1 parent 9ceaf80 commit 21f6bfe
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 66 deletions.
4 changes: 2 additions & 2 deletions flips-w32.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -918,7 +918,7 @@ void GUILoadConfig()
configbin.len -= size

readconfig(&state, sizeof(state));
if (strncmp(state.signature, "FlipscfgW", sizeof(state.signature)) || state.cfgversion!=mycfgversion) goto badconfig;
if (memcmp(state.signature, "FlipscfgW", sizeof(state.signature))!=0 || state.cfgversion!=mycfgversion) goto badconfig;
int emulen;
readconfig(&emulen, sizeof(emulen));
set_st_emulator_len(NULL, emulen);
Expand All @@ -928,7 +928,7 @@ void GUILoadConfig()
else
{
badconfig:
strncpy(state.signature, "FlipscfgW", sizeof(state.signature));
memcpy(state.signature, "FlipscfgW", sizeof(state.signature));
state.cfgversion=mycfgversion;
state.lastRomType=0;
state.openInEmulatorOnAssoc=false;
Expand Down
25 changes: 13 additions & 12 deletions flips.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -555,7 +555,7 @@ static void CfgSumName(WCHAR* out, int type, const void* sum)
}
static bool CfgSumParseName(int* type, void* sum, LPCWSTR in)
{
if (!!wcsncmp(in, TEXT("rom."), strlen("rom.")))
if (wcsncmp(in, TEXT("rom."), strlen("rom.")) != 0)
return false;
uint8_t* out = (uint8_t*)sum;
for (int t=0;t<ch_last;t++)
Expand All @@ -572,7 +572,7 @@ static bool CfgSumParseName(int* type, void* sum, LPCWSTR in)
{
tmp[0] = hex[i*2+0]; // let non-hex yield garbage, messing with config voids your warranty anyways
tmp[1] = hex[i*2+1];
sscanf(tmp, "%x", &tmpout);
swscanf(tmp, TEXT("%x"), &tmpout);
out[i] = tmpout; // not %hhx because XP doesn't trust c99
}
return true;
Expand Down Expand Up @@ -793,16 +793,21 @@ struct errorinfo ApplyPatchMem2(file* patch, struct mem inrom, bool verifyinput,
if (++errtextid == 2) errtextid=0;
if (inf.size_in != inrom.len)
{
//http://msdn.microsoft.com/en-us/library/vstudio/tcxf1dw6.aspx says %zX is not supported; this is true up to and including Windows Vista
//let's define it to whatever they do support.
//http://msdn.microsoft.com/en-us/library/vstudio/tcxf1dw6.aspx says %zX is not supported
//this is true up to and including Windows Vista; 7 adds support for it
//I could define it to "I", but my GCC does not acknowledge its legitimacy and throws bogus warnings
//instead, let's just define it to size_t's underlying type: long unsigned int / long long unsigned in
#ifdef _WIN32
#define z "I"
# ifdef _WIN64
# define z "ll"
# else
# define z "l"
# endif
#else
#define z "z"
# define z "z"
#endif
sprintf(errtext, "This patch is not intended for this ROM. Expected file size %" z "u, got %" z "u.", inf.size_in, inrom.len);
errinf.description=errtext;
#undef z
}
else
{
Expand Down Expand Up @@ -1109,11 +1114,7 @@ int patchinfo(LPCWSTR patchname, struct manifestinfo * manifestinfo)
}

LPCWSTR inromname = FindRomForPatch(patch, NULL);
#ifdef FLIPS_WINDOWS
#define z "I"
#else
#define z "z"
#endif
//'z' macro defined above
printf("Input ROM: %" z "u bytes, CRC32 %.8X", info.size_in, info.crc_in);
if (inromname) wprintf(TEXT(", %s"), inromname);
puts("");
Expand Down
4 changes: 2 additions & 2 deletions flips.h
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
//#define EXTERN_C
//#endif

#define flipsversion "Flips v1.40"
#define flipsversion "Floating IPS v1.40-pre"


#if defined(FLIPS_WINDOWS)
Expand Down Expand Up @@ -91,7 +91,7 @@
#define wprintf printf
#define wsprintf sprintf
#define wscanf scanf
#define wsscanf sscanf
#define swscanf sscanf
#define wtoi atoi

#define iswalnum isalnum
Expand Down
46 changes: 46 additions & 0 deletions make-release.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
#!/bin/sh

if [ "$HOME" != "/home/alcaro" ]; then
#This script is for making official releases only.
#If you're intending to fork Floating IPS, or take over maintenance, you're welcome to edit this script.
echo "Use ./make.sh instead."
exit 1
fi

profile/download.sh || exit $?
# . rather than ./make.sh, so $FLAGS remains set
. ./make.sh
mv ./flips ~/bin/flips

#create windows binary
mingwver 64 || true # this is a script that sets the Wine PATH

echo 'Windows (1/3)'
rm obj/* flips.exe; wine mingw32-make TARGET=windows OPTFLAGS="$FLAGS -fprofile-generate -lgcov"
[ -e flips.exe ] || exit
echo 'Windows (2/3)'
profile/profile.sh 'wine flips.exe'
echo 'Windows (3/3)'
rm flips.exe; wine mingw32-make TARGET=windows OPTFLAGS="$FLAGS -fprofile-use"

#verify there are no unexpected dependencies
objdump -p flips.exe | grep 'DLL Name' | \
grep -Pvi '(msvcrt|advapi32|comctl32|comdlg32|gdi32|kernel32|shell32|user32)' && \
echo "Invalid dependency" && exit

#test cli binaries
echo "CLI"
make TARGET=cli DIVSUF=no
[ -e flips ] || exit
rm flips

#echo Finishing
#7z a floating.zip flips.exe
#zipcrush floating.zip
##The random numbers are the size of Lunar IPS, which I wish to stay below.
##(Or wished a while ago, but my feature set is so much greater than Lunar that I'll accept being bigger.)
#echo Size: $(stat -c%s flips.exe)/96768
#echo \(Linux: $(stat -c%s ~/bin/flips)\)
#echo \(Zipped: $(stat -c%s floating.zip)/59881\)

#./special.sh
70 changes: 20 additions & 50 deletions make.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,16 @@
FLAGS='-Wall -Werror -O3 -s -flto -fuse-linker-plugin -fweb -fomit-frame-pointer -fmerge-all-constants -fvisibility=hidden'
FLAGS=$FLAGS' -fno-exceptions -fno-unwind-tables -fno-asynchronous-unwind-tables'
FLAGS=$FLAGS' -ffunction-sections -fdata-sections -Wl,--gc-sections -fprofile-dir=obj/'
FLAGS=$FLAGS' -Wl,-z,relro,-z,now,--as-needed,--hash-style=gnu,--relax'
#Linux flags - they don't make sense on Windows
#make-release.sh uses this
LINFLAGS=' -Wl,-z,relro,-z,now,--as-needed,--hash-style=gnu,--relax'

#if old profile data is present, download the new one instead
#do it before checking for arguments, so --profile=no with old data existing doesn't do anything silly
if [ -e profile/firefox-45.0esr.tar ]; then
rm profile/firefox-45.0esr.tar profile/firefox-52.0esr.tar
touch profile/firefox-10.0esr.tar
fi

for i in "$@"; do
case "$i" in
Expand All @@ -26,23 +35,22 @@ case "$i" in
profile/download.sh || exit $?
fi
;;
*) # unknown option
*)
echo "Unknown argument $1; valid arguments are: --harden=no --harden=yes --profile=no --profile=yes"
exit 1
;;
esac
done


#if old profile data is present, download the new one
if [ -e profile/firefox-45.0esr.tar ]; then
rm profile/firefox-45.0esr.tar profile/firefox-52.0esr.tar
touch profile/firefox-10.0esr.tar
fi

if [ ! -e profile/choice ]; then
while true; do
read -p "Do you wish to use profile-guided optimization? This will download 40MB data from the internet and use 90MB disk space, and 800MB RAM during compilation. (y/n)" yn || exit $?
# 1 2 3 4 5 6 7 8
# 12345678901234567890123456789012345678901234567890123456789012345678901234567890
echo "Do you wish to use profile-guided optimization? This will download 40MB"
echo "data from the internet and use 90MB disk space, and use 800MB RAM during"
echo "compilation. The result is typically 2% faster."
read -p "(y/n)" yn || exit $?
case $yn in
[Yy]*) profile/download.sh || exit $?; break;;
[Nn]*) echo n > profile/choice; break;;
Expand All @@ -56,54 +64,16 @@ if [ -e profile/firefox-10.0esr.tar ]; then
profile/download.sh || exit $?
fi

#clean up
rm flips flips.exe floating.zip obj/*

##create windows binary
#echo 'Windows/Resource (Wine warmup)'
#mingwver 5.3
#wine windres flips.rc rc.o
#
#echo 'Windows (1/3)'
#rm flips.exe; wine mingw32-make TARGET=windows OPTFLAGS="$FLAGS -fprofile-generate -lgcov"
#[ -e flips.exe ] || exit
#echo 'Windows (2/3)'
#profile/profile.sh 'wine flips.exe'
#echo 'Windows (3/3)'
#rm flips.exe; wine mingw32-make TARGET=windows OPTFLAGS="$FLAGS -fprofile-use"
#
##verify there are no unexpected dependencies
#objdump -p flips.exe | grep 'DLL Name' | \
# grep -Pvi '(msvcrt|advapi32|comctl32|comdlg32|gdi32|kernel32|shell32|user32)' && \
# echo "Invalid dependency" && exit
#
##test cli binaries
#echo CLI
#rm flips; make TARGET=cli DIVSUF=no
#[ -e flips ] || exit

#create linux binary
if [ -e profile/firefox-10.0esr.tar ]; then
echo 'GTK+ (1/3)'
rm flips; TARGET=gtk make OPTFLAGS="$FLAGS -fprofile-generate -lgcov" || exit $?
rm obj/* flips; TARGET=gtk make OPTFLAGS="$FLAGS$LINFLAGS -fprofile-generate -lgcov" || exit $?
[ -e flips ] || exit 1
echo 'GTK+ (2/3)'
profile/profile.sh ./flips
echo 'GTK+ (3/3)'
rm flips; TARGET=gtk make OPTFLAGS="$FLAGS -fprofile-use"
#mv flips '~/bin/flips'
rm flips; TARGET=gtk make OPTFLAGS="$FLAGS$LINFLAGS -fprofile-use"
else
rm flips; TARGET=gtk make OPTFLAGS="$FLAGS" || exit $?
rm flips; TARGET=gtk make OPTFLAGS="$FLAGS$LINFLAGS" || exit $?
fi

#echo Finishing
##compress source
#7z a floating.zip flips.exe
#zipcrush floating.zip
#echo Size: $(stat -c%s flips.exe)/96768
#echo \(Linux: $(stat -c%s ~/bin/flips)\)
#echo \(Zipped: $(stat -c%s floating.zip)/59881\)
#
#./special.sh
#
#rm src.zip boring.zip

0 comments on commit 21f6bfe

Please sign in to comment.