This is a simple design to mount a Raspberry Pi3 to a 2020 or 3030 aluminum extrusion.
I would recommend printing 4 spacers. Use the M4 spacer but scale it to 75% so that its a M3 sized spacer in the X and Y directions. I would set the height (Z) of the spacer to 4 or 5mm.
You'll need 4 appropriate length M2.5 bolts - ~ 10mm or so. And 4 M2.5 hex nuts.
I used 2 M5 8mm cap head bolts and 2 printed M5 T-Nuts (Thingiverse has models for 2020 and 3030 extrusions, whatever works for you).
I've used this to mount the Pi3 onto both 2020 and 3030 aluminum extrusions. I don't have any 4040 aluminum extrusions so I don't know if it will work.
I printed the mount face down with the lip and brace facing up.
I printed with supports so that it would be a little cleaner. Not necessarily required depending on how well your printer prints with the particular material you use.
Print the 4 of the M4 spacer scaled to 75% X/Y. Set Z to ~ 5mm.