The invention discloses a method for preparing a compound of a formula (I) or pharmaceutically acceptable salts thereof. The method is characterized by comprising the following steps of: (1) using a compound of a formula (II) as a
raw material and carrying out a reduction and
amination reaction with an appropriate
reducing agent to obtain a compound of a formula (III); (2) using 2-quinary heterocyclic substituted
ethanol as a
raw material and reacting to obtain a compound of a formula (IV) under the conditions of appropriate
reagent, temperature and
solvent; (3) after carrying out chiral separation on the compound of the formula (III), carrying out a
condensation reaction with the compound of the formula (I) under an alkaline condition to obtain a compound of a formula (V); and (4) carrying out
demethylation protection on the compound of the formula (V) under the condition of appropriate temperature and
solvent to obtain the compound of the formula (I), wherein R1 in each formula is selected from C1-8
alkyl groups or aromatic bases which can be arbitrarily substituted, X is selected from
halogen atoms or p-toluenesulfonic acid groups and
methanesulfonic acid groups for protecting alcoholic extract hydroxyl groups, and Y is selected from O, S and N. A target product obtained by the method has high optical purity, convenient operation, lower cost, higher yield and less
pollution and is suitable for industrialized production.