I always compiled out of the Lazarus IDE, which works. I never tried to compile from the command line (because I don't know which compiler / cross-compiler I had to use and all it's many parameters).
Your fpc.sh wrapper should be able to pass commandline parameters to the FPC executable.
For command line parameters for FPC, see
https://www.freepascal.org/docs-html/user/userap1.htmlYou should be looking at the options -T and -P for setting the target specifications in particular.
For information on targets see option -i, specifically -it
for instance (as an example) you can target windows with:
fpc -Twin32 -Pi386 myprogram.pas
in order to create a i386 executable that is bale to run on windows
for instance my FPC host compiler is running on x86-64 and in order to see the targets for 32-bit processors you can do:
fpc -Pi386 -it
Which would show (amongst others) that the windows target is win32 (that is the "value" you can add to the -T parameter)
Since I run on 64 bit x86 there is no need to add -Px86_64 as processor in order to list/see the supported target (but you can do so).
If you provide the (correct) CPU target argument then the FPC wrapper automatically selects the correct cross-compiler (ppcross386, ppcrossa64 and ppcrossavr).
Having said that, the avr target probably also requires you to set a subtarget but, I do not know much about the specifics. Try the avr wiki pages in that case.