Measuring "phase" difference between two square waves

Low pass filtering of output of XOR gate gives voltage proportional to magnitude of phase difference. But I don't know if there is an easy way to get sign of the difference too. Maybe with help of a latch?

Also if you want to make a PLL you may look at HC4046 chip.