The below routine can be used for it.

CLSCOPY
Q

COPY(Class,NewClass,Qual="")
; Copy a class
; Pass Qual as 'ck' to keep the source
(Class,NewClass, Qual)
;TSTART
Q:Class="" "Class Name Can't be empty"
Q:$D(^oddDEF(Class))'=11 "Class "_Class_" is not found."
^oddDEF(NewClass) = ^oddDEF(Class)
^oddDEF(NewClass,1) = NewClass
K:'(Qual["k") ^oddDEF(NewClass,"s")
$system.OBJ.Compile(NewClass,Qual,.ER)
$system.OBJ.Compile(NewClass,Qual,.ER)
;I ER TROLLBACK Q ER(1)
ER ER(1)
;TCOMMIT
1

COPYPKG(Pkg,NewPkg,Qual="") ; Copy a package
(Pkg, NewPkg, St, Qual)
St
Sub = Pkg_"."
While 1 {
Sub = $O(^oddDEF(Sub)) Q:Sub=""
Sub,!
$P(Sub,".") '= Pkg Q
St($I(St)) = Sub_"|"_$$COPY(Sub,NewPkg_"."_$P(Sub,".",2,*),Qual)
}
St