Recent

Author Topic: Creating `.app`s on the Mac with Lazarus 3.4 [SOLVED]  (Read 200 times)

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 416
Creating `.app`s on the Mac with Lazarus 3.4 [SOLVED]
« on: September 14, 2024, 03:58:24 pm »
What is the latest on how to create a self-contained `.app` package using Lazarus. I'm using Lazarus for the first time in over a year, and I've just tried building a simple form, as by default, it still just produces the raw `Unix Executable`.

Is there a simple, one or two step way of producing a self-contained `.app` package that behaves just like any other Mac application?
« Last Edit: September 20, 2024, 06:28:22 pm by carl_caulkett »
"It builds... ship it!"

dseligo

  • Hero Member
  • *****
  • Posts: 1365
Re: Creating `.app`s on the Mac with Lazarus 3.4
« Reply #1 on: September 14, 2024, 04:26:56 pm »
Menu Project, Project Options. On the bottom of Application (Application settings) there is 'Create Application Bundle'.

carl_caulkett

  • Sr. Member
  • ****
  • Posts: 416
Re: Creating `.app`s on the Mac with Lazarus 3.4
« Reply #2 on: September 14, 2024, 04:57:52 pm »
Thanks! I did try to search for that menu option before but couldn't find it! I notice that it creates an alias to the `Unix Executable` rather than doing a full copy. I did, in the meantime, get some advice from a friendly chap called Claude Sonnet 3.5 who gave me a shell script which does much the same thing...
Code: Bash  [Select][+][-]
  1. #!/bin/zsh
  2.  
  3. APP_NAME="OsmosePresets"
  4. APP_BUNDLE="${APP_NAME}.app"
  5. CONTENTS_DIR="${APP_BUNDLE}/Contents"
  6. FRAMEWORKS_DIR="${CONTENTS_DIR}/Frameworks"
  7. RESOURCES_DIR="${CONTENTS_DIR}/Resources"
  8. MACOS_DIR="${CONTENTS_DIR}/MacOS"
  9.  
  10. echo "Remove existing .app..."
  11. rm -rf "$APP_BUNDLE"
  12.  
  13. echo "Creating directories..."
  14. mkdir -p "${FRAMEWORKS_DIR}" "${RESOURCES_DIR}" "${MACOS_DIR}"
  15.  
  16. echo "Copying executable..."
  17. if [ -f "${APP_NAME}" ]; then
  18.     cp "${APP_NAME}" "${MACOS_DIR}/${APP_NAME}"
  19.     echo "Executable copied successfully."
  20. else
  21.     echo "Error: Executable '${APP_NAME}' not found!"
  22. fi
  23.  
  24. echo "Copying resources..."
  25. if [ -d "resources" ]; then
  26.     cp -R resources/* "${RESOURCES_DIR}/"
  27.     echo "Resources copied successfully."
  28. else
  29.     echo "Warning: 'resources' directory not found!"
  30. fi
  31.  
  32. echo "Copying and fixing dependencies..."
  33. LIBS=(${(f)"$(otool -L "${MACOS_DIR}/${APP_NAME}" | grep -v /System | grep -v /usr/lib | grep -v @executable_path | awk '{print $1}')"})
  34.  
  35. if [ ${#LIBS[@]} -eq 0 ]; then
  36.     echo "No external libraries found to copy."
  37. else
  38.     for lib in $LIBS; do
  39.         echo "Copying $lib"
  40.         cp "${lib}" "${FRAMEWORKS_DIR}/"
  41.         lib_name=${lib:t}
  42.         install_name_tool -change "${lib}" "@executable_path/../Frameworks/${lib_name}" "${MACOS_DIR}/${APP_NAME}"
  43.     done
  44. fi
  45.  
  46. # Update Info.plist (modify as needed)
  47. cat > "${CONTENTS_DIR}/Info.plist" << EOF
  48. <?xml version="1.0" encoding="UTF-8"?>
  49. <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
  50. <plist version="1.0">
  51. <dict>
  52.     <key>CFBundleExecutable</key>
  53.     <string>${APP_NAME}</string>
  54.     <key>CFBundleIdentifier</key>
  55.     <string>com.yourcompany.${APP_NAME}</string>
  56.     <key>CFBundleName</key>
  57.     <string>${APP_NAME}</string>
  58.     <key>CFBundleInfoDictionaryVersion</key>
  59.     <string>6.0</string>
  60.     <key>CFBundlePackageType</key>
  61.     <string>APPL</string>
  62.     <key>CFBundleSignature</key>
  63.     <string>????</string>
  64.     <key>LSMinimumSystemVersion</key>
  65.     <string>10.12</string>
  66.     <key>NSHighResolutionCapable</key>
  67.     <true/>
  68. </dict>
  69. </plist>
  70. EOF
  71.  
  72. echo "App bundle creation completed. Contents:"
  73. ls -R "${APP_BUNDLE}"
  74.  
"It builds... ship it!"

 

TinyPortal © 2005-2018