I don't know why you would want to go to the trouble, but a bore shape like any of these, twisted or straight, can be readily produced by ECM (Electrochemical Machining). I worked with a fellow and we made some rifled, experimental, 20mm cannon barrels out of a proprietary, very hard, very high temperature resistant material. The final bore diameter and rifling were produced by ECM. The barrels came out perfectly, worked great in testing, and then disappeared into a "black" program. No square bullets though - all round.
As I remember from some of my old books, some square bore guns were produced in the Arabic world in the 16th and 17th centuries with interchangeable barrels - one with a square bore and one with a round bore. The square bored barrels were for shooting at "infidels" who were not worthy of being killed with a round bullet.