Support compilation in WSL Ubuntu 20.04 LTS. Fix some warnings.

This commit is contained in:
Sorgelig
2021-10-07 03:08:56 +08:00
parent a215fb36bb
commit 7abbf7f8f4
12 changed files with 37 additions and 40 deletions

View File

@@ -1,8 +1,8 @@
# makefile to fail if any command in pipe is failed.
SHELL = /bin/bash -o pipefail
# using gcc version 7.5.0 (Linaro GCC 7.5-2019.12)
BASE = arm-linux-gnueabihf
# using gcc version 10.2.1
BASE = arm-none-linux-gnueabihf
CC = $(BASE)-gcc
LD = $(BASE)-ld
@@ -30,9 +30,9 @@ PRJ = MiSTer
C_SRC = $(wildcard *.c) \
$(wildcard ./lib/miniz/*.c) \
$(wildcard ./lib/md5/*.c) \
$(wildcard ./lib/lzma/*.c) \
$(wildcard ./lib/flac/src/*.c) \
$(wildcard ./lib/libchdr/*.c) \
$(wildcard ./lib/lzma/*.c) \
$(wildcard ./lib/flac/src/*.c) \
$(wildcard ./lib/libchdr/*.c) \
lib/libco/arm.c
CPP_SRC = $(wildcard *.cpp) \
@@ -47,7 +47,7 @@ OBJ = $(C_SRC:.c=.c.o) $(CPP_SRC:.cpp=.cpp.o) $(IMG:.png=.png.o)
DEP = $(C_SRC:.c=.c.d) $(CPP_SRC:.cpp=.cpp.d)
DFLAGS = $(INCLUDE) -D_7ZIP_ST -DPACKAGE_VERSION=\"1.3.3\" -DFLAC_API_EXPORTS -DFLAC__HAS_OGG=0 -DHAVE_LROUND -DHAVE_STDINT_H -DHAVE_STDLIB_H -DHAVE_SYS_PARAM_H -DENABLE_64_BIT_WORDS=0 -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -DVDATE=\"`date +"%y%m%d"`\"
CFLAGS = $(DFLAGS) -Wall -Wextra -Wno-strict-aliasing -Wno-format-truncation -Wno-psabi -c -O3
CFLAGS = $(DFLAGS) -Wall -Wextra -Wno-strict-aliasing -Wno-stringop-overflow -Wno-stringop-truncation -Wno-format-truncation -Wno-psabi -Wno-restrict -c -O3
LFLAGS = -lc -lstdc++ -lm -lrt $(IMLIB2_LIB) -Llib/bluetooth -lbluetooth
$(PRJ): $(OBJ)
@@ -56,30 +56,27 @@ $(PRJ): $(OBJ)
$(Q)cp $@ $@.elf
$(Q)$(STRIP) $@
.PHONY: clean
clean:
$(Q)rm -f *.elf *.map *.lst *.user *~ $(PRJ)
$(Q)rm -rf obj DTAR* x64
$(Q)find . \( -name '*.o' -o -name '*.d' -o -name '*.bak' -o -name '*.rej' -o -name '*.org' \) -exec rm -f {} \;
cleanall:
$(Q)rm -rf *.o *.d *.elf *.map *.lst *.bak *.rej *.org *.user *~ $(PRJ)
$(Q)rm -rf obj DTAR* x64
$(Q)find . -name '*.o' -delete
$(Q)find . -name '*.d' -delete
%.c.o: %.c
$(Q)$(info $<)
$(Q)$(CC) $(CFLAGS) -std=gnu99 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g'
%.cpp.o: %.cpp
$(Q)$(info $<)
$(Q)$(CC) $(CFLAGS) -std=gnu++14 -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g'
$(Q)$(CC) $(CFLAGS) -std=gnu++14 -Wno-class-memaccess -o $@ -c $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g'
%.png.o: %.png
$(Q)$(info $<)
$(Q)$(LD) -r -b binary -o $@ $< 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g'
ifneq ($(MAKECMDGOALS), clean)
-include $(DEP)
endif
%.c.d: %.c
$(Q)$(CC) $(DFLAGS) -MM $< -MT $@ -MT $*.c.o -MF $@ 2>&1 | sed -e 's/\(.[a-zA-Z]\+\):\([0-9]\+\):\([0-9]\+\):/\1(\2,\ \3):/g'

View File

@@ -26,9 +26,9 @@
</ImportGroup>
<PropertyGroup Label="UserMacros" />
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
<NMakeBuildCommandLine>git.lnk ./build.sh</NMakeBuildCommandLine>
<NMakeBuildCommandLine>%systemroot%\sysnative\windowspowershell\v1.0\powershell.exe wsl bash -lic ./build.sh</NMakeBuildCommandLine>
<NMakeOutput>MiSTer</NMakeOutput>
<NMakeCleanCommandLine>git.lnk ./clean.sh</NMakeCleanCommandLine>
<NMakeCleanCommandLine>%systemroot%\sysnative\windowspowershell\v1.0\powershell.exe wsl bash -lic ./clean.sh</NMakeCleanCommandLine>
<NMakePreprocessorDefinitions>__arm__;__GNUC__;__USE_GNU ;_GNU_SOURCE;VDATE="000000";_FILE_OFFSET_BITS=64;_LARGEFILE64_SOURCE;$(NMakePreprocessorDefinitions)</NMakePreprocessorDefinitions>
<NMakeIncludeSearchPath>c:\Work\Git\opt\gcc75\arm-linux-gnueabihf\libc\usr\include;c:\Work\Git\opt\gcc75\lib\gcc\arm-linux-gnueabihf\7.5.0\include;c:\Work\Git\opt\gcc75\arm-linux-gnueabihf\include\c++\7.5.0;c:\Work\Git\opt\gcc75\arm-linux-gnueabihf\include\c++\7.5.0\arm-linux-gnueabihf;$(NMakeIncludeSearchPath);lib\libco;lib\miniz;lib\lodepng;lib\libchdr\include;lib\bluetooth</NMakeIncludeSearchPath>
<OutDir>$(TEMP)</OutDir>

View File

@@ -33,7 +33,7 @@ static void setFilter()
has_filter = spi_uio_cmd(UIO_SET_AFILTER);
if (!has_filter) return;
sprintf(filter_cfg_path, AFILTER_DIR"/%s", filter_cfg + 1);
snprintf(filter_cfg_path, sizeof(filter_cfg_path), AFILTER_DIR"/%s", filter_cfg + 1);
if(filter_cfg[0]) printf("\nLoading audio filter: %s\n", filter_cfg_path);
if (filter_cfg[0] && FileOpen(&f, filter_cfg_path))

View File

@@ -1,5 +1,7 @@
#!/bin/bash
echo "Start building..."
# create simple text file named 'host' in this folder with IP address of your MiSTer.
HOST=192.168.1.75
@@ -12,14 +14,15 @@ set -o pipefail
make
set +e
plink root@$HOST -pw 1 'killall MiSTer'
plink root@$HOST -pw 1 -batch 'killall MiSTer'
set -e
ftp -n <<EOF
open $HOST
user root 1
passive
binary
put MiSTer /media/fat/MiSTer
EOF
plink root@$HOST -pw 1 'sync;PATH=/media/fat:$PATH;MiSTer >/dev/ttyS0 2>/dev/ttyS0 </dev/null &'
plink root@$HOST -pw 1 -batch 'sync;PATH=/media/fat:$PATH;MiSTer >/dev/ttyS0 2>/dev/ttyS0 </dev/null &'

View File

@@ -358,7 +358,7 @@ static void cheats_send()
fileTYPE f = {};
if (cheats[i].enabled)
{
sprintf(filename, "%s/%s", cheat_zip, cheats[i].name);
snprintf(filename, sizeof(filename), "%s/%s", cheat_zip, cheats[i].name);
if (FileOpen(&f, filename))
{
int len = f.size;

View File

@@ -1753,7 +1753,7 @@ static char* get_led_path(int dev, int add_id = 1)
static int set_led(char *base, const char *led, int brightness)
{
static char path[1024];
sprintf(path, "%s%s/brightness", base, led);
snprintf(path, sizeof(path), "%s%s/brightness", base, led);
FILE* f = fopen(path, "w");
if (f)
{
@@ -1768,7 +1768,7 @@ static int set_led(char *base, const char *led, int brightness)
static int get_led(char *base, const char *led)
{
static char path[1024];
sprintf(path, "%s%s/brightness", base, led);
snprintf(path, sizeof(path), "%s%s/brightness", base, led);
FILE* f = fopen(path, "r");
if (f)
{

View File

@@ -317,15 +317,11 @@ static int changeDir(char *dir)
if (p)
{
*p = 0;
uint32_t len = strlen(p+1);
if (len > sizeof(curdir) - 1) len = sizeof(curdir) - 1;
strncpy(curdir, p+1, len);
strncpy(curdir, p + 1, sizeof(curdir) - 1);
}
else
{
uint32_t len = strlen(selPath);
if (len > sizeof(curdir) - 1) len = sizeof(curdir) - 1;
strncpy(curdir, selPath, len);
strncpy(curdir, selPath, sizeof(curdir) - 1);
selPath[0] = 0;
}
}
@@ -6217,7 +6213,7 @@ void HandleUI(void)
if (btimeout > 0)
{
OsdWrite(12, "\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81\x81");
sprintf(str, " Bootcore -> %s", bootcoretype);
snprintf(str, sizeof(str), " Bootcore -> %s", bootcoretype);
OsdWrite(13, str, 0, 0);
strcpy(straux, cfg.bootcore);
sprintf(str, " %s", get_rbf_name_bootcore(straux));

View File

@@ -254,9 +254,9 @@ void recent_update(char* dir, char* path, char* label, int idx)
// update the selection
int indexToErase = RECENT_MAX - 1;
recent_rec_t rec = {};
strncpy(rec.dir, dir, sizeof(rec.dir));
strncpy(rec.name, name, sizeof(rec.name));
strncpy(rec.label, label ? label : name, sizeof(rec.label));
strncpy(rec.dir, dir, sizeof(rec.dir)-1);
strncpy(rec.name, name, sizeof(rec.name)-1);
strncpy(rec.label, label ? label : name, sizeof(rec.label)-1);
for (unsigned i = 0; i < sizeof(recents)/sizeof(recents[0]); i++)
{

View File

@@ -179,7 +179,7 @@ static const char *get_arcade_root(int rbf)
static char path[kBigTextSize];
if (!rbf) strcpy(path, mame_root);
else sprintf(path, "%s/cores", arcade_root);
else snprintf(path, sizeof(path), "%s/cores", arcade_root);
return path;
}
@@ -1149,7 +1149,7 @@ static const char *get_rbf(const char *xml)
}
}
if (lastfound[0]) sprintf(rbfname, "%s/%s", dirname, lastfound);
if (lastfound[0]) snprintf(rbfname, sizeof(rbfname), "%s/%s", dirname, lastfound);
closedir(dir);
return lastfound[0] ? rbfname : NULL;
@@ -1161,7 +1161,7 @@ int arcade_load(const char *xml)
static char path[kBigTextSize];
if(xml[0] == '/') strcpy(path, xml);
else sprintf(path, "%s/%s", getRootDir(), xml);
else snprintf(path, sizeof(path), "%s/%s", getRootDir(), xml);
set_arcade_root(path);
printf("arcade_load [%s]\n", path);

View File

@@ -453,7 +453,8 @@ int minimig_cfg_load(int num)
if (strcmp(tmpconf.kickstart, minimig_config.kickstart) != 0) {
updatekickstart = true;
}
memcpy((void*)&minimig_config, (void*)&tmpconf, sizeof(minimig_config));
memset((void*)&minimig_config, 0, sizeof(minimig_config));
memcpy((void*)&minimig_config, (void*)&tmpconf, sizeof(tmpconf));
minimig_config.cpu = tmpconf.cpu;
minimig_config.autofire = tmpconf.autofire;
memset(&minimig_config.hardfile[2], 0, sizeof(minimig_config.hardfile[2]));
@@ -473,7 +474,7 @@ int minimig_cfg_load(int num)
BootPrint("Setting config defaults\n");
// set default configuration
memset((void*)&minimig_config, 0, sizeof(minimig_config)); // Finally found default config bug - params were reversed!
strncpy(minimig_config.id, config_id, sizeof(minimig_config.id));
memcpy(minimig_config.id, config_id, sizeof(minimig_config.id));
snprintf(minimig_config.kickstart, 1024, "%s/%s", HomeDir(), "KICK.ROM");
minimig_config.memory = 0x11;
minimig_config.cpu = 0;

View File

@@ -409,7 +409,7 @@ static void parse_config()
do {
p = user_io_get_confstr(i);
printf("get cfgstring %d = %s\n", i, p);
printf("get cfgstring %d = %s\n", i, p ? p : "NULL");
if (!i)
{
OsdCoreNameSet((p && p[0]) ? p : "CORE");

View File

@@ -232,7 +232,7 @@ static void setScaler()
new_scaler = 1;
spi8(scaler_flt_cfg[0]);
DisableIO();
sprintf(filename, COEFF_DIR"/%s", scaler_flt_cfg + 1);
snprintf(filename, sizeof(filename), COEFF_DIR"/%s", scaler_flt_cfg + 1);
if (FileOpen(&f, filename))
{
@@ -342,7 +342,7 @@ static void setGamma()
has_gamma = 1;
spi8(0);
DisableIO();
sprintf(filename, GAMMA_DIR"/%s", gamma_cfg + 1);
snprintf(filename, sizeof(filename), GAMMA_DIR"/%s", gamma_cfg + 1);
if (FileOpen(&f, filename))
{
@@ -1105,7 +1105,7 @@ static char *get_file_fromdir(const char* dir, int num, int *count)
if (de)
{
sprintf(name, "%s/%s", dir, de->d_name);
snprintf(name, sizeof(name), "%s/%s", dir, de->d_name);
}
closedir(d);
if(count) *count = cnt;