It's from the verb "tun", which means "to do" (and has the same root as the English "do"). It is used in compound verbs like "wehtun" (to hurt, takes the dative when transitive) or by itself just as it would in English. "Was tust du?" means "What are you doing?" In the case of "es tut mir leid", it's more idiomatic, since that literally means "It does sorry to me" or "it makes me sorry". The difference between "machen" and "tun" isn't totally clear, but I've noticed that "machen" is usually more emphatic or refers to doing something more specific (remember that "machen" can also mean "to make", while "tun" generally cannot).