--- CMakeLists.txt.orig	2021-10-19 16:15:25 UTC
+++ CMakeLists.txt
@@ -113,7 +113,6 @@ install(CODE "
     endif()
 ")
 
-
 elseif(CMAKE_SYSTEM_NAME STREQUAL FreeBSD)
 
 if ($ENV{PREFIX})
@@ -122,27 +121,33 @@ else()
     # default is "/usr/local"
 endif()
 
+if ($ENV{STAGEDIR})
+    set(CMAKE_INSTALL_STAGEDIR $ENV{STAGEDIR})
+else()
+    set(CMAKE_INSTALL_STAGEDIR "../stage")
+endif()
+
 install(TARGETS ${PROJECT_NAME}
     RUNTIME DESTINATION sbin
 )
 
 install(CODE "
-    if(NOT EXISTS ${CMAKE_INSTALL_PREFIX}/etc/airsane/ignore.conf)
+    if(NOT EXISTS ${CMAKE_INSTALL_STAGEDIR}/${CMAKE_INSTALL_PREFIX}/etc/airsane/ignore.conf)
         file(INSTALL ${CMAKE_SOURCE_DIR}/etc/ignore.conf DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/airsane)
     endif()
 ")
 install(CODE "
-    if(NOT EXISTS ${CMAKE_INSTALL_PREFIX}/etc/airsane/options.conf)
+    if(NOT EXISTS ${CMAKE_INSTALL_STAGEDIR}/${CMAKE_INSTALL_PREFIX}/etc/airsane/options.conf)
         file(INSTALL ${CMAKE_SOURCE_DIR}/etc/options.conf DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/airsane)
     endif()
 ")
 install(CODE "
-    if(NOT EXISTS ${CMAKE_INSTALL_PREFIX}/etc/airsane/Gnome-scanner.png)
+    if(NOT EXISTS ${CMAKE_INSTALL_STAGEDIR}/${CMAKE_INSTALL_PREFIX}/etc/airsane/Gnome-scanner.png)
         file(INSTALL ${CMAKE_SOURCE_DIR}/etc/Gnome-scanner.png DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/airsane)
     endif()
 ")
 install(CODE "
-    if(NOT EXISTS ${CMAKE_INSTALL_PREFIX}/etc/rc.d/airsaned)
+    if(NOT EXISTS ${CMAKE_INSTALL_STAGEDIR}/${CMAKE_INSTALL_PREFIX}/etc/rc.d/airsaned)
         file(INSTALL ${CMAKE_SOURCE_DIR}/freebsd/airsaned DESTINATION ${CMAKE_INSTALL_PREFIX}/etc/rc.d)
     endif()
 ")
