flat assembler
Message board for the users of flat assembler.

Index > Linux > linux fasmg include path

Author
Thread Post new topic Reply to topic
donn



Joined: 05 Mar 2010
Posts: 321
donn 03 Aug 2020, 21:28
Super simple:

Does anyone have any make.sh examples on Linux? Tried dozens of variations of getting include in the path, including putting it in the PATH outside the script.

Coming from a Windows project, trying to extend to Linux finally https://board.flatassembler.net/topic.php?t=21361.


Code:
#!/bin/sh
#export include=include
#set include=include
#export include=/mnt/c/Users/donn/datap/external/fasmg/include
#export PATH=/mnt/c/Users/donn/datap/external/fasmg/include:$PATH
../fasmg.x64 ../../../src/main/asm/linux/datap.asm ../../../src/main/asm/datap.obj
    


Tried re-arranging the folders with relative paths as a temporary workaround, but farthest I got was this:

Code:
Error: symbol 'SCNHDR' is undefined or out of scope.    
and it's starting to get messy. Assume this was already mentioned on another post, but I searched and could not yet find.
Post 03 Aug 2020, 21:28
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 04 Aug 2020, 07:41
This is what works for me:
Code:
#!/bin/bash
export INCLUDE=/mnt/c/asm/fasmg/examples/x86/include
./fasmg.x64 test.asm    


Last edited by Tomasz Grysztar on 06 Aug 2020, 07:50; edited 1 time in total
Post 04 Aug 2020, 07:41
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2545
Furs 04 Aug 2020, 15:41
Tomasz Grysztar wrote:
This is what works for me:
Code:
#!/bin/bash
INCLUDE=/mnt/c/asm/fasmg/examples/x86/include
./fasmg.x64 test.asm    
Don't you need to export INCLUDE?

donn, any particular reason your lines are commented out? The # sign in front means the line is a comment. BTW don't forget to use quotes around variables to be safe, like $PATH. Just quote the entire thing.
Post 04 Aug 2020, 15:41
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 04 Aug 2020, 17:35
Hmm, tried a few more things, put the make_linux.sh and .asm file in the fasmg folder (/mnt/c/Users/donn/datap/external/fasmg2) so relative paths wouldn't be needed too:

Code:
#!/bin/bash
echo "Making"
INCLUDE=/mnt/c/Users/donn/datap/external/fasmg2/examples/x86/include
echo $INCLUDE
./fasmg.x64 datap.asm    


Tried updating fasmg to version g.izxz, echoing from within the script echoes as expected, and tried the quotes around the path. I also tried cd'ing to the dir that was echoed to make sure I typed it right; I could cd there and back.

In the asm file, I have:

Code:
include 'format/format.inc'
    


Yeah, the # lines are commented out, just wanted to show some variations on what I tried. I think exports are available outside the running script, they are otherwise available only within the script. Tried export again too though. It's been a while since I regularly used Linux so I could be missing something.
Maybe it's a WSL thing on this computer. I can try some other variations later.


Description: Screen grab
Filesize: 117.97 KB
Viewed: 11222 Time(s)

NotFound.JPG


Post 04 Aug 2020, 17:35
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 20430
Location: In your JS exploiting you and your system
revolution 04 Aug 2020, 23:05
Code:
export INCLUDE=/path/to/folder    
Note the all-caps and the export.
Post 04 Aug 2020, 23:05
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2545
Furs 05 Aug 2020, 19:54
donn wrote:
I think exports are available outside the running script, they are otherwise available only within the script. Tried export again too though. It's been a while since I regularly used Linux so I could be missing something.
No that's not how it works. Variables are available only within the shell. FASM, however, is not the shell, it's an external process launched by the shell. It won't see the shell's variables.

export makes the variable visible to all spawned processes after that point.

It won't make them visible "outside" the script, as in, affect currently running processes! That makes no sense since the environment is set at process launch. And it's not persistent, as soon as the shell is over it's gone.

Of course, apps launched with the exported variables will still have them, since they're fixed at launch.

Code:
a=1
b=2
c=3
export a
some_app &
export b
some_app2 &
unset a
b=0
some_app3 &
wait    
some_app will have the 'a' environment variable only.
some_app2 will have both 'a' and 'b' variables.
some_app3 will have only 'b', but the value of 'b' will be 0.

some_app2 will still be running (it's ran in the background due to &) and its 'b' will be 2 still.


Last edited by Furs on 06 Aug 2020, 14:39; edited 1 time in total
Post 05 Aug 2020, 19:54
View user's profile Send private message Reply with quote
bitRAKE



Joined: 21 Jul 2003
Posts: 4061
Location: vpcmpistri
bitRAKE 06 Aug 2020, 05:01
Furs wrote:
some_app will still be running (it's ran in the background due to &) and its 'b' will be 2 still.
when does some_app get a "b"?

_________________
¯\(°_o)/¯ “languages are not safe - uses can be” Bjarne Stroustrup
Post 06 Aug 2020, 05:01
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 8357
Location: Kraków, Poland
Tomasz Grysztar 06 Aug 2020, 07:50
Furs wrote:
Don't you need to export INCLUDE?
Yes, you're right. Thank you for the correction!
Post 06 Aug 2020, 07:50
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 2545
Furs 06 Aug 2020, 14:34
bitRAKE wrote:
when does some_app get a "b"?
In my example, never, since b was never exported before running it. EDIT: oops I had a typo in my previous post, sorry, probably where the confusion comes from.

Think of it like this, in high-level terms, what the shell does when you launch an app from it:

Code:
LaunchAppFromShell()
{
    CreateNewApp

    Iterate through all environment and exported variables:
      Copy them to the new App's environment
      Start the app
}    
The app's environment is fixed at the time of its launch. Think of non-exported variables as local variables in other languages: they're only available to the shell, they're not "inherited".

Since there was no 'b' when we launched some_app, it won't have one in its environment, and this applies for its entire lifespan.

If you launch another some_app later, after you exported b, of course it's a completely new and separate process, which will have b set to whatever value it has when you launch it.

Of course, if you execute a child shell/process, it will also get a copy of environment and exported variables.

That's why if you export variables in your user's profile (~/.profile shell script), they'll be available for your user session: the profile script is the parent of all of your user apps and is executed at the beginning of user login.
Post 06 Aug 2020, 14:34
View user's profile Send private message Reply with quote
donn



Joined: 05 Mar 2010
Posts: 321
donn 07 Aug 2020, 19:29
It works now! Was these pesky carriage return characters:

Code:
#!/bin/bash^M
echo "Making"^M
#export include=include^M
export INCLUDE="/mnt/c/Users/donn/datap/external/fasmg2/examples/x86/include"^M
echo $INCLUDE^M
#export include=/mnt/c/Users/donn/datap/external/fasmg/include^M
#export PATH=/mnt/c/Users/donn/datap/external/fasmg/include:$PATH^M
./fasmg.x64 datap.asm    


Edited in vi and now up to this:
Code:
donn@DESKTOP-14N7AAI:/mnt/c/users/donn/datap/solution/linux$ ../../src/main/asm/make_linux2.sh
Making2
/mnt/c/Users/donn/datap/external/fasmg2/examples/x86/include
flat assembler  version g.iveex
../../src/main/asm/linux/datap.asm [11] ../../src/main/asm/linux/../datap.inc [3] ../../src/main/asm/linux/../Includes.inc [1] ../../src/main/asm/linux/../Include/Allocate.inc [1] ../../src/main/asm/linux/../Include/../Allocate/Allocate.inc [3]:
        section '.data' data readable writeable align 16
macro section [33]
Custom error: invalid argument.    


Final make script looks like this:

Code:
#!/bin/bash
echo "Making2"
export INCLUDE="/mnt/c/Users/donn/datap/external/fasmg2/examples/x86/include"
echo $INCLUDE
./fasmg.x64 datap.asm
    


I agree with everything you said regarding env vars also, my terminology and conceptual knowledge is a bit behind with this. So I guess there are three levels of variable scope here.

[shell session
---[bash script
------VAR=VALUE
------export VAR2=VALUE2
------[called process
------------VAR2=VALUE
------]
---]
]

None of the vars will be available in the shell session itself unless if you use one of these methods.

That point about env vars not being available to already running processes is totally legitimate too. I included echoes within the script to test these things, and adjusted my understanding of the scope from this.
Post 07 Aug 2020, 19:29
View user's profile Send private message Reply with quote
4next



Joined: 06 Nov 2024
Posts: 1
4next 06 Nov 2024, 18:45
Hello everyone,

for those still struggling with Fasmg INCLUDE environment variable, here's a Makefile way to go:

Code:
.PHONY: all

ASM_SRC = $(wildcard *.asm)
AS = fasmg
SHELL=bash
SHFLAGS=-c
INCLUDE=$(shell pwd)/include

all: .exp

.exp:
        @echo "Exported INCLUDE"
        export INCLUDE=$(INCLUDE); \
        $(SHELL) $(SHFLAGS) '$(MAKE) .asm'

.asm: $(ASM_SRC)
        @echo
        @echo "Building ..."
        @echo "Include is $(INCLUDE)"
        $(AS) $< $(basename $(notdir $<))
        chmod +x $(basename $(notdir $<))

clean: $(ASM_SRC)
        rm -f $(basename $(notdir $<))  
    


Cheers Smile
Post 06 Nov 2024, 18:45
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.