zelda3 icon indicating copy to clipboard operation
zelda3 copied to clipboard

Windows Building with MSYS haven't icon

Open impeeza opened this issue 3 years ago • 14 comments

Describe your bug here. And how to reproduce it.

Hi,

Thanks a lot for all your work

I just finish to compile the Windows 64 version using MSYS MINGW64 and run make, a exe file was created and works fine, but the exe file have not icon, shows the windows default one and no details are on the file.

image image

There are any additional steps to use the resource.h, triforce.ico & zelda3.rc files on zelda3\platform\win32 folder?

What is your build target?

Windows

impeeza avatar Oct 10 '22 05:10 impeeza

If someone wants to fix this please make a PR, I don't have an msys environment set up.

snesrev avatar Oct 11 '22 00:10 snesrev

I wish to know how to do, but my programming skills stops on basic :D

impeeza avatar Oct 11 '22 01:10 impeeza

Hello there, I am not the most skilled but was able to compile Windows executable with icon using MSYS

the additional steps was:

  • compile the platform/win32/zelda3.rc using the command windres platform/win32/zelda3.rc -O coff -o Zelda.res
  • Then when compiling executable add the filename Zelda.res as parameter by example: cc ancilla.o ... snes/tracing.o -o zelda3 Zelda.res -LC:/msys64/mingw64/lib -lmingw32 -mwindows -lSDL2main -lSDL2

So try to tweak the Makefile and add the next commands: image

left file is original one and right one is the edited by me.

The new makefile is:

TARGET_EXEC:=zelda3
RES_FILE:=Zelda3.res
RC_FILE:=platform/win32/zelda3.rc
ROM:=tables/zelda3.sfc
SRCS:=$(wildcard *.c snes/*.c)
OBJS:=$(SRCS:%.c=%.o)
PYTHON:=/usr/bin/env python3
WINDRES:=windres
CFLAGS:=$(if $(CFLAGS),$(CFLAGS),-O2)

CFLAGS:=${CFLAGS} $(shell sdl2-config --cflags) -DSYSTEM_VOLUME_MIXER_AVAILABLE=0
LDFLAGS:=${LDFLAGS} $(RES_FILE) $(shell sdl2-config --libs)

.PHONY: all clean clean_obj clean_gen

all: resfile $(TARGET_EXEC) tables/zelda3_assets.dat 
resfile:
	$(WINDRES) $(RC_FILE) -O coff -o $(RES_FILE)

$(TARGET_EXEC): $(OBJS)
	$(CC) $(OBJS) -o $@ $(LDFLAGS)
%.o : %.c
	$(CC) -c $(CFLAGS) $< -o $@

tables/zelda3_assets.dat: tables/dialogue.txt
	cd tables; $(PYTHON) compile_resources.py ../$(ROM)
tables/dialogue.txt:
	cd tables; $(PYTHON) extract_resources.py ../$(ROM)

clean: clean_obj clean_gen
clean_obj: clean_resfile
	$(RM) $(OBJS) $(TARGET_EXEC)
clean_resfile:
	$(RM) $(RES_FILE)
clean_gen:
	$(RM) tables/zelda3_assets.dat

I don't know if some of the names/command should be managed by variables, need your help, also still no learn how to create PRs if somebody help me will thank you lot.

impeeza avatar Oct 11 '22 07:10 impeeza

Another perk I found, the MSYS compilation doesn't copy SDL2.dll to the output folder, but the TCC and VC does.

impeeza avatar Oct 11 '22 08:10 impeeza

Hm, not sure how to do this, because the makefile is used also by Linux...

snesrev avatar Oct 12 '22 15:10 snesrev

Humm, I see, then could we use a target section for win and other for linux, something like:

ifeq ($(WINDOWS_BUILD),1)
else
	ifeq ($(OS),Windows_NT)
		WINDOWS_BUILD := 1
	else
		WINDOWS_BUILD := 0
	endif
end if


ifeq ($(WINDOWS_BUILD),1)
	TARGET_EXEC := $(TARGET_EXEC).exe
	......  #windows specific steps
else # Linux builds/binary namer
	......  #LINUX specific steps
endif

... #common steps

then you can run make on a windows and additional steps are executed, or you can run make WINDOWS_BUILD=1 to generate Windows executable on linux.

What do you think?

impeeza avatar Oct 12 '22 16:10 impeeza

I'm not very good with makefiles.. Please give me a version that I can test on Linux

snesrev avatar Oct 12 '22 16:10 snesrev

Me neither, will try and ask a friend to test it :D

impeeza avatar Oct 12 '22 21:10 impeeza

Well, the next makefile works fine on linux debian 11 and Windows 10/11 (MSYS).

Just setup a Virtual machine with debian, and my current MSYS setup, tested several times, make clean, make -j and works perfect.

Just compile linux executable and windows exe with icon 😸

Basically, just add the windows variables and a if block to execute a target with windows commands

TARGET_EXEC:=zelda3
ROM:=tables/zelda3.sfc
SRCS:=$(wildcard *.c snes/*.c)
OBJS:=$(SRCS:%.c=%.o)
PYTHON:=/usr/bin/env python3
CFLAGS:=$(if $(CFLAGS),$(CFLAGS),-O2)
CFLAGS:=${CFLAGS} $(shell sdl2-config --cflags) -DSYSTEM_VOLUME_MIXER_AVAILABLE=0
LDFLAGS:=${LDFLAGS} $(shell sdl2-config --libs)

WINDRES:=windres
RES_FILE:=Zelda3.res
RC_FILE:=platform/win32/zelda3.rc



#If run on a Windows Setup, build Windows Executable, unless expressed with argument WINDOWS_BUILD=0 of make
ifeq ($(OS),Windows_NT)
	WINDOWS_BUILD := 1
else
	WINDOWS_BUILD := 0
endif

#set environment for Windows build, add icon to executable
ifeq ($(WINDOWS_BUILD),1)
LDFLAGS:=${LDFLAGS} $(RES_FILE) $(shell sdl2-config --libs)
all: win $(TARGET_EXEC) tables/zelda3_assets.dat
endif



.PHONY: all clean clean_obj clean_resfile clean_gen

all: $(TARGET_EXEC) tables/zelda3_assets.dat
$(TARGET_EXEC): $(OBJS)
	$(CC) $(OBJS) -o $@ $(LDFLAGS)
%.o : %.c
	$(CC) -c $(CFLAGS) $< -o $@

tables/zelda3_assets.dat: tables/dialogue.txt
	cd tables; $(PYTHON) compile_resources.py ../$(ROM)
tables/dialogue.txt:
	cd tables; $(PYTHON) extract_resources.py ../$(ROM)

win:
	$(WINDRES) $(RC_FILE) -O coff -o $(RES_FILE)
	cp ${MINGW_PREFIX}/bin/SDL2.dll ./

clean: clean_obj clean_gen clean_resfile
clean_obj: clean_resfile
	$(RM) $(OBJS) $(TARGET_EXEC)
	$(RM) SDL2.dll
clean_resfile:
	$(RM) $(RES_FILE)
clean_gen:
	$(RM) tables/zelda3_assets.dat

Hope somebody could help us to test and if all is correct could be merged on the next release.

impeeza avatar Oct 13 '22 05:10 impeeza

On Arch Linux, the Linux executable compiles perfectly; however, make WINDOWS_BUILD=1 results in errors. WINDRES:=windres had to be changed to WINDRES:=x86_64-w64-mingw32-windres, but resulted in:

x86_64-w64-mingw32-windres platform/win32/zelda3.rc -O coff -o Zelda3.res
x86_64-w64-mingw32-windres: can't open icon file `platform\win32\triforce.ico': No such file or directory
make: *** [Makefile:45: win] Error 1

patrickmollohan avatar Oct 14 '22 15:10 patrickmollohan

Cool, I am looking how to set the prerequisites to compile Windows executable on Windows. windres is one of them.

Thanks.

impeeza avatar Oct 14 '22 15:10 impeeza

OK, seems you need MSYS on linux, so is not the target, could remove the use of external WINDOWS_BUILD=1 and leave only the code what autodetect windows, so the windows executable is only created under windows and under linux always create the linux executable :D

impeeza avatar Oct 14 '22 16:10 impeeza

I don't like all this windows specific stuff in the shared Makefile

Can some parts be moved out to a makefile in ports/win32/ somehow?

snesrev avatar Oct 18 '22 00:10 snesrev

Yes could be a better solution. Like the switch one when i will able to compile again try new makefile

impeeza avatar Oct 18 '22 10:10 impeeza

The merged PR https://github.com/snesrev/zelda3/pull/164 solve all problems thanks to @hgdagon

impeeza avatar Oct 26 '22 04:10 impeeza