[Linux -> Windows Cross Compile] /bin/sh: 1: Syntax error: Bad for loop variable

Reporter: faissaloo  |  Status: closed  |  Last Modified: September 29, 2017, 12:56:17 PM

I was trying to test cross compilation with MinGW on Linux but whenever I try to compile the make fails:

echo // GENERATED RESOURCE FILE FRONTEND > /home/faissaloo/.enigma/.eobjs/Linux/Windows/Run/resources.rc
for %%r in (Preprocessor_Environment_Editable/Resources.rc Widget_Systems/Win32/resources.rc) do echo #include "%%r" >> /home/faissaloo/.enigma/.eobjs/Linux/Windows/Run/resources.rc
/bin/sh: 1: Syntax error: Bad for loop variable

Apparently another user came across this issue a while back on the forums: http://enigma-dev.org/forums/index.php?topic=2612.45

RobertBColton  
Ahh I bet this might have been my fault try reverting #1008 or more simply just try running with widgets disabled i.e. set widget systems to none.

faissaloo  

The issue persists even after disabling widgets.

RobertBColton  

You want to try reverting #1008? It really isn't that big of a change, I just merged 3 files together. That's the only thing i can think of that would have broke this.

There is b2bd052 too you could try reverting along with 8fcd0a9. Also take a look at the changes in aa5321b because I made it pick up resource files the correct way.

Basically everything listed here https://github.com/enigma-dev/enigma-dev/commits/master/ENIGMAsystem/SHELL/Widget_Systems/Win32 there haven't been many changes since 2015.

RobertBColton  

Even more simply than all that you could just go back and check out the 2015 version and copy over the folder for Win32 widgets, see if that does the trick.

Here's a handy link: https://github.com/enigma-dev/enigma-dev/tree/f6153abe87c8987b146f3cce3e8feaed5c11b49f

Just clone/download it and copy the folder over.

faissaloo  

I checked out 0570b2d#diff-a8cfb76cd8d4d06a8c65f8325dec3575 which didn't fix anything, and then tried f330ae7#diff-a8cfb76cd8d4d06a8c65f8325dec3575 which didn't fix anything either. I think this is a problem with the actual main Makefile, some googling indicated to me that the particular loop might require bash syntax but forcing the makefile to use bash only resulted in syntax error near unexpected token '(' so I don't think that's the solution.
Btw, here's a full log:
http://pastebin.com/raw/z9jZYmrd

RobertBColton  

Ok, and FYI I'm the one who wrote the output RC that does the game icon and all that, ENIGMA never used to have it (not bragging, just saying I am the right person for this). Another thing to point out in case you or anybody else doesn't know is that the RC file gets written to C:\ProgramData\ENIGMA\Preprocessor_Environment_Editable\Resources.rc and then later linked in or w/e.

GameSettings gameSet = es->gameSettings;

Also it looks like the only change to compile.cpp where that's written was with merging the GL3.3 branch.
https://github.com/enigma-dev/enigma-dev/commits/83bffa133def3f3621f47930a8eb224a53de95ad/CompilerSource/compiler/compile.cpp

Anyway, I'm a little confused about these issues with RC, what would BASH have anything to do with this and why would its syntax be different? The RC standard/format is set by Microsoft aint it?

It looks like those errors come from the SHELL makefile and that part @JoshDreamland helped write.

$(WINDRES) -o $@ -I. -I$(WORKDIR) $(OBJDIR)/resources.rc -O coff $(RCFLAGS)

How come these issues just come up all of the sudden if it's not related to any of our changes?

faissaloo  

Anyway, I'm a little confused about these issues with RC, what would BASH have anything to do with this and why would its syntax be different? The RC standard/format is set by Microsoft aint it?

The issue is with the makefile, 'Bad for loop variable' is often something that happens when someone tries to use a BASH for loop in a strictly POSIX shell (like dash) hence why I thought it might be something along those lines, especially since this only occurs when cross compiling. But then again, forcing bash with SHELL:=/bin/bash doesn't work either and just gives syntax error near unexpected token '(' so I don't think that's the solution but it might be somewhere towards the problem.

How come these issues just come up all of the sudden if it's not related to any of our changes?

I guess nobody really tested cross compilation much.

TheExDeus  

I might be at fault here. 642ba86#diff-920471cdc7109e6fb1d9680181917af3
That code is only supposed to run on Windows (Linux doesn't have rc files), so I made it run on cmd. I was aware it broke sh, but didn't know there was a possibility ENIGMA will be launched via sh on windows (like in cross-compilation). This means the makefile has to check for shell and do the correct loop? I remember searching extensively for something that would work on both shells, but couldn't find anything.
Try reverting the changes in that commit (specifically that makefile) and see if it fixes it for you.

The fix was required for this bug: http://enigma-dev.org/forums/index.php?topic=2488.0

faissaloo  

Reverting the Makefile makes the syntax error disappear, though compile still fails because of:

/home/faissaloo/.enigma/.eobjs/Linux/Windows/Run/Platforms/Win32/WINDOWSexternals.o: file not recognized: File format not recognised
collect2: error: ld returned 1 exit status

This is probably unrelated though.

RobertBColton  

Maybe try deleting .eobjs and do a clean build?

faissaloo  

Ok, it works now. The Makefile needs some modification, as well as some other stuff (as per the tutorial here https://enigma-dev.org/docs/Wiki/CrossCompileWithAudio). This is what my diff looks like right now: http://pastebin.com/z94E3JpV
The main issue here seems to be that native Windows compilation isn't separated enough from cross compilation.

Solitudinal  

Just wanted to remark that I have the same issue as of the latest commit 34e3c17 on Windows 10 when compiling with the 32-bit compiler.
No Linux involved for me, purely Win10.

RobertBColton  

Me and Josh just tracked down this bug to @fundies PR to implement the travis CI bot.
bc3dac1#diff-920471cdc7109e6fb1d9680181917af3L134

Working on a fix.

RobertBColton  

Closing as fixed by #1076
RobertBColton  

@JoshDreamland That's so strange that fundies and TheExDeus made the same for loop changes to the SHELL makefile independently of each other.
fundies: bc3dac1#diff-920471cdc7109e6fb1d9680181917af3L134
TheExDeus: 642ba86#diff-920471cdc7109e6fb1d9680181917af3

Not sure if what TheExDeus said above should be heeded.

JoshDreamland  

Okay; perhaps that archaic syntax is Batch. Microsoft does love using % for things. Our makefiles are run through MSys, now; that change should be obsolete. Just make sure game icons still work. There could be a make-specific way of doing that, but I couldn't find it when I looked earlier.
RobertBColton  

I used that Death Star icon that only works in LGM because of a patch by iirc sorlok. Anyway, looks like it works, so yeah, good.

enigmarcicon

Please sign in to post comments, or you can view this issue on GitHub.