Is there any way to set env variable in top level Makefile and unset when done

Hello
I have compilation directory structure the top level Makefile is the one that contains all the sub directories
I want to set in this Makefile env variable say : setenv OPTIMIZATION_LEVEL "1"
and when all the sub directories done compiling it will set this variable to different lavel say : setenv OPTIMIZATION_LEVEL "2"
but only when all the sub directories done