pkguild is a command-line tool used to create installers, there are easier tools for creating installers such as Packages which uses a graphical user interface.
The way pkgbuild works is that you create a folder structure that acts as the root directory of the target machine, then you move the files for the installer into this fake root folder with the desired folder structure.
When you run the pkgbuild command you tell it what the root folder is and pkbuild essentially trims off that part of the file path to figure out where to install your files.
The result will be an installer (.pkg file) that will install your files and look something like this:
I want "myApp" to be installed at /Applications/myApp so I've copied it to the new folder:
~/Documents/instroot/Applications/MyApp
I also want some text files to be installed at /Library/Application Support/myApp so I've copied them into the new folder too:
~/Documents/instroot/Library/Application Support/myApp/myAppFile1.txt
once all the files for the installer are in the correct place, we just need to call this command:
pkgbuild --root --identifier --version packagename
root: the install root
identifier: an ID for your installer (used only by the operating system and can be anything you want but so try to make it meaningful and unique)
version: the version of your project
packagename: the name for the output installer, the name is also used in the installer dialog
for my example project the command is:
pkgbuild --root ~/Documents/instroot --identifier com.myapp.test --version 1.0 myapp.pkg
We can also use the pkgutil --payload-files command to list the installer files and sanity check the contents.
Now we have an installer called myapp.pkg! Double clicking it will start the installer.