I do not think it is possible to do it by usage of static libraries. It is because from prog1 prespective, function1 from lib2's module is simple defined 2 times. On Wikipedia you can see that
...external functions and variables which are resolved in a caller at compile-time and copied into a target application...
And you would probably not be suprised that this code would generate similar errors you see in your question:
prog1.f90
some code here...
function funtion1(x) ...
...first version of function1 ...
end function
function funtion1(x) ...
...second version of function1 ...
end function
some code here...
One possibility would be to compile at least lib1 as shared library and make sure (compiler/platform dependent) that the symbols from lib2 are not exported from shared lib1.