Make sure there is no irritation. Then insist/demand that he go to the bathroom or bedroom - adjust himself only in PRIVATE.... because it is not socially acceptable to do in public. Although I disagree with John Rosemond about some things, I agree with him about how simple it is to help children choose to change simple socially unacceptable behaviors or habits. There are so many consequences/rewards that can be given as encouragement. 3 chance stickers or cards per day and "you're out" (i.e the consequence such as Rosemond's infamous "You must be tired so you need to go to bed early for a few days (or week)."
But, I would make sure, first that there is no problem. Ask him what is going on. Take him to the doctor if needed. But teach him to do this in private.