Can I pass variable value from my sketch to the build recipes at compile time?

I don't think there's any way to do that from the sketch.

The closest thing I can think of is you could use boards.txt to add a custom Tools menu.

You should also be able to do it from the command line via --pref if using arduino or -prefs with arduino-builder.