Forum > Options

Execute after

(1/2) > >>

timppl:
For the application I maintain at work, I build for all platforms on Linux using cross-compiling.
I have an Execute After command to do some housekeeping when a build is finished.
The other day  I needed to build it under windows and the script called from Execute after did not work ( not surprising as it is a bash script ).
So my question is, is it possible to automatically select what runs in Execute after ( eg .sh on Linux and .bat on Windows) depending on the build platform?

Thanks

Tim

Gustavo 'Gus' Carreno:
Hey Timppl,

I'm not sure that there's a way to run different things based on the architecture, but let me propose a quick and dirty solution:

- Name the shell script execute_after, with the appropriate chmod +x and the hash bang (#!/bin/bash) to follow.
- Name the batch file execute_after.bat.

This way, the appropriate script will be run under the Linux and Windows architectures, since Windows will search for a *.com, *.exe and *.bat file and Linux will not.

Hope this workaround make sense and is of any use.

If there is a way to differentiate between architectures, I'm sure a more experienced person will chime in :)

Cheers,
Gus

MarkMLl:
Oh wow. This reminds me of the bad old days when geeks spent ridiculous amounts of time trying to get a single file compiling sensibly in both FORTRAN and Pascal.

I think it's a mighty good question, and one which I'd almost certainly have raised in the past if I were still using Windows. I think there's three possibilities:

a) Install a suitable extension to Windows which adds a shell and standard unix-style utilities.

b) Start the IDE with some shell/environment variables defining external commands: I think these can be expanded in the execute-after sequence. It might alternatively be possible to put these in the fpc.cfg file etc.

c) Modify the IDE to recognise predicates, i.e. "execute this bit if the OS is DOS/Windows, this if it's unix/Linux" and so on.

I've tinkered with the execute-after bit of the IDE in the past in order to allow it to be run with elevated privilege if it were necessary to "bless" the generated executable with e.g. additional POSIX-style capabilities. I haven't a clue what happened to my patch, it's vanished somewhere into the svn/git swithcover morass and I'm not going there... but it really wasn't too bad to work with.

MarkMLl

timppl:
Thanks chaps

Gustavo, I tried your solution but could not get it to work.

I did some playing around and found a solution. Instead of using a script, I rewrote it in pascal and compiled a version for linux and one for windows. Then in the execute after I put

--- Quote ---$MakeExe($(ProjSrcPath)/clean_after)
--- End quote ---
The MakeExe macro does nothing under linux so that "clean_after" is executed, and under windows it adds .exe to the name so that "clean_after.exe" is executed.
Once I worked this out it seemed so simple :D.

 Thanks Lazarus devs for this facility

MarkMLl:

--- Quote from: timppl on August 23, 2021, 07:23:52 am ---Thanks chaps

Gustavo, I tried your solution but could not get it to work.

I did some playing around and found a solution. Instead of using a script, I rewrote it in pascal and compiled a version for linux and one for windows. Then in the execute after I put

--- Quote ---$MakeExe($(ProjSrcPath)/clean_after)
--- End quote ---
The MakeExe macro does nothing under linux so that "clean_after" is executed, and under windows it adds .exe to the name so that "clean_after.exe" is executed.
Once I worked this out it seemed so simple :D.

 Thanks Lazarus devs for this facility

--- End quote ---

Congratulations, that's an elegant hack. Please make sure it gets into the wiki somewhere.

MarkMLl

Navigation

[0] Message Index

[#] Next page

Go to full version