What are the true portable or best to define real 4 real 8 integer 4 integer 8, etc?

Depending on the options chosen, that file could be

module stdlib_kinds
  use iso_fortran_env, only: int8, int16, int32, int64
  use iso_c_binding, only: c_bool
  implicit none
  private
  public :: sp, dp, xdp, qp, int8, int16, int32, int64, lk, c_bool

  !> Single precision real numbers
  integer, parameter :: sp = selected_real_kind(6)

  !> Double precision real numbers
  integer, parameter :: dp = selected_real_kind(15)

  !> Extended double precision real numbers
  integer, parameter :: xdp = selected_real_kind(18)

  !> Quadruple precision real numbers
  integer, parameter :: qp = selected_real_kind(33)

  !> Default logical kind parameter
  integer, parameter :: lk = kind(.true.)

end module stdlib_kinds

With the driver

program main
use iso_fortran_env, only: compiler_version
use stdlib_kinds
implicit none
print*,trim(compiler_version())
print "(*(a6))","sp","dp","xdp","qp","lk"
print "(*(i6))",sp,dp,xdp,qp,lk
end program main

sample output is

 GCC version 12.0.1 20220213 (experimental)
    sp    dp   xdp    qp    lk
     4     8    10    16     4
 Intel(R) Fortran Intel(R) 64 Compiler Classic for applications running on Intel
 (R) 64, Version 2021.5.0 Build 20211109_000000
    sp    dp   xdp    qp    lk
     4     8    16    16     4
2 Likes