--- ./build.sh	2023-05-29 17:29:20.000000000 -0400
+++ ./build.sh	2023-05-29 17:34:27.000000000 -0400
@@ -122,7 +122,19 @@
 			-o "${builddir}/maddy" ${GOFLAGS} ./cmd/maddy
 	else
 		echo "-- Building main server executable..." >&2
-		go build -tags "$tags" -trimpath -ldflags="-X \"github.com/foxcpp/maddy.Version=${version}\"" -o "${builddir}/maddy" ${GOFLAGS} ./cmd/maddy
+		go build \
+                    -tags "$tags" \
+                    -trimpath \
+                    -ldflags="
+                        -X \"github.com/foxcpp/maddy.ConfigDirectory=${prefix}/etc/maddy\"
+                        -X \"github.com/foxcpp/maddy.DefaultStateDirectory=${prefix}/var/lib/maddy\"
+                        -X \"github.com/foxcpp/maddy.DefaultRuntimeDirectory=${prefix}/var/run/maddy\"
+                        -X \"github.com/foxcpp/maddy.DefaultLibexecDirectory=${prefix}/libexec/maddy\"
+                        -X \"github.com/foxcpp/maddy.Version=${version}\"
+                    " \
+                    -o "${builddir}/maddy" \
+                    ${GOFLAGS} \
+                    ./cmd/maddy
 	fi
 
 	build_man_pages
@@ -140,8 +152,8 @@
 	command install -m 0755 -d "${destdir}/${prefix}/bin/"
 	command install -m 0755 "${builddir}/maddy" "${destdir}/${prefix}/bin/"
 	command ln -s maddy "${destdir}/${prefix}/bin/maddyctl"
-	command install -m 0755 -d "${destdir}/etc/maddy/"
-	command install -m 0644 ./maddy.conf "${destdir}/etc/maddy/maddy.conf"
+	command install -m 0755 -d "${destdir}/${prefix}/etc/maddy/"
+	command install -m 0644 ./maddy.conf "${destdir}/${prefix}/etc/maddy/maddy.conf"
 
 	# Attempt to install systemd units only for Linux.
 	# Check is done using GOOS instead of uname -s to account for possible
