You might use the r project with function poly2nb(queen=TRUE or queen=FALSE for the rock contiguity), in the library spdep (you see Applied Spatial Data Analysis with R .Roger S. Bivand, Edzer Pebesma and V. Gómez-Rubio Pág 240).
Below, you will find a link to a tutorial to calculate your matrix under GeoDa. Rook and Queen contiguity matrix can be created using GeoDa (as .gal files).
https://geodacenter.asu.edu/node/380#map
If you work with Stata, you can use spwmatrix command to import the .gal file as a Stata matrix.
Is it possible to generate spatial weight file for disconnected polygon feature? For example, I have sample parks and I would like to generate spatial weight matrix for them, which polygon should I use?