adobe_dng_sdk.sh 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176
  1. #!/bin/bash
  2. set -e
  3. set -u
  4. set -o pipefail
  5. workdir="sdk"
  6. ver_xlib="1.3"
  7. ver_expat="2.1.0"
  8. if [ "$#" -ne 1 ]; then
  9. echo "Usage: $0 [build|install]"
  10. echo ""
  11. echo "build: Download and build the Adobe DNG 1.4 sdk"
  12. echo "install: Install the dng_validate command and required libraries (optional)"
  13. exit 0
  14. fi
  15. if [ "$1" == "install" ]; then
  16. if [ -f "$workdir"/dng_validate ]; then
  17. install -Dm755 "$workdir"/dng_validate /usr/local/bin/dng_validate
  18. install -Dm644 "$workdir"/libXMPCore.so /usr/local/lib/libXMPCore.so
  19. install -Dm644 "$workdir"/libXMPFiles.so /usr/local/lib/libXMPFiles.so
  20. exit 0
  21. else
  22. echo "Build the SDK first with the $0 build command (without superuser privilegs)"
  23. exit 1
  24. fi
  25. fi
  26. if [ "$1" != "build" ]; then
  27. echo "Invalid command"
  28. exit 1
  29. fi
  30. mkdir -p "$workdir"
  31. workdir=$(readlink -f "$workdir")
  32. echo "Working in '$workdir'"
  33. cd "$workdir"
  34. # Get XMP
  35. if [ -d "xmp_sdk" ]; then
  36. echo "> XMP sdk was already downloaded"
  37. else
  38. echo "> Downloading XMP"
  39. wget "http://download.macromedia.com/pub/developer/xmp/sdk/XMP-Toolkit-SDK-CC-201306.zip"
  40. unzip XMP-Toolkit-SDK-CC-201306.zip
  41. mv XMP-Toolkit-SDK-CC201306 xmp_sdk
  42. rm -f XMP-Toolkit-SDK-CC-201306.zip
  43. fi
  44. xmp_root="$workdir"/xmp_sdk
  45. # Get DNG sdk
  46. if [ -d "dng_sdk_1_4" ]; then
  47. echo "> DNG sdk was already downloaded"
  48. else
  49. echo "> Downloading DNG sdk"
  50. wget "http://download.adobe.com/pub/adobe/dng/dng_sdk_1_4.zip"
  51. unzip dng_sdk_1_4.zip
  52. rm -f dng_sdk_1_4.zip
  53. fi
  54. dng_root="$workdir"/dng_sdk_1_4
  55. # Get zlib
  56. cd "$xmp_root"/third-party/zlib
  57. if [ -f "zlib.h" ]; then
  58. echo "> ZLIB was already downloaded"
  59. else
  60. echo "> Downloading ZLIB $ver_zlib"
  61. wget "http://zlib.net/zlib-$ver_zlib.tar.gz"
  62. tar xzf zlib-$ver_zlib.tar.gz
  63. cp zlib-$ver_zlib/*.h zlib-$ver_zlib/*.c .
  64. fi
  65. # Get expat
  66. cd "$xmp_root"/third-party/expat
  67. if [ -f "lib/expat.h" ]; then
  68. echo "> EXPAT was already downloaded"
  69. else
  70. echo "> Downloading EXPAT $ver_expat"
  71. wget "https://downloads.sourceforge.net/project/expat/expat/$ver_expat/expat-$ver_expat-RENAMED-VULNERABLE-PLEASE-USE-2.3.0-INSTEAD.tar.gz"
  72. mv expat-$ver_expat-RENAMED-VULNERABLE-PLEASE-USE-2.3.0-INSTEAD.tar.gz expat-$ver_expat.tar.gz
  73. tar xzf expat-$ver_expat.tar.gz
  74. cp -R expat-$ver_expat/lib .
  75. fi
  76. # Build XMP
  77. cd "$xmp_root"
  78. if [ -f "public/libraries/i80386linux_x64/release/libXMPCore.so" ]; then
  79. echo "> XMP was already built"
  80. else
  81. echo "> Building XMP"
  82. cd "$xmp_root"/build
  83. sed -i '/set(XMP_ENABLE_SECURE_SETTINGS "ON")/c\set(XMP_ENABLE_SECURE_SETTINGS "OFF")' shared/ToolchainGCC.cmake
  84. sed -i '15 i #include "string.h"' ../XMPFiles/source/NativeMetadataSupport/ValueObject.h
  85. make
  86. fi
  87. xmp_build="$xmp_root"/public/libraries/i80386linux_x64/release
  88. # Build DNG sdk
  89. cd "$dng_root"
  90. cd dng_sdk/source
  91. if [ -f "dng_validate" ]; then
  92. echo "> DNG sdk was already built"
  93. else
  94. cat > Makefile <<'EOF'
  95. # Binary name
  96. APP=dng_validate
  97. INCL=-I $(XMP_PUB_DIR)/include
  98. XMP_RELEASE=$(XMP_PUB_DIR)/libraries/i80386linux_x64/release
  99. LIB=-ljpeg -lz -lpthread -ldl -L $(XMP_RELEASE) -lXMPCore -lXMPFiles
  100. # Execute the binary
  101. all: $(APP)
  102. # Linking
  103. $(APP): *.o
  104. g++ $^ $(LIB) -Wl,-rpath=. -Wl,-rpath=/usr/local/lib -o $(APP)
  105. # Compilation
  106. *.o: *.cpp
  107. g++ -c -Wall $(INCL) -DqDNGValidateTarget=1 $^
  108. clean:
  109. rm *.o
  110. EOF
  111. cat > RawEnvironment.h << 'EOF'
  112. #define qLinux 1
  113. #define qDNGThreadSafe 1
  114. #define UNIX_ENV 1
  115. EOF
  116. cat > "$workdir"/sdk.patch << 'EOF'
  117. diff --git a/dng_sdk/source/dng_string.cpp b/dng_sdk/source/dng_string.cpp
  118. index 6eafae1..82be01b 100644
  119. --- a/dng_sdk/source/dng_string.cpp
  120. +++ b/dng_sdk/source/dng_string.cpp
  121. @@ -30,7 +30,7 @@
  122. #include <windows.h>
  123. #endif
  124. -#if qiPhone || qAndroid
  125. +#if qiPhone || qAndroid || qLinux
  126. #include <ctype.h> // for isdigit
  127. #endif
  128. diff --git a/dng_sdk/source/dng_xmp_sdk.cpp b/dng_sdk/source/dng_xmp_sdk.cpp
  129. index 77d7ebe..3231587 100644
  130. --- a/dng_sdk/source/dng_xmp_sdk.cpp
  131. +++ b/dng_sdk/source/dng_xmp_sdk.cpp
  132. @@ -47,7 +47,7 @@
  133. #define XMP_INCLUDE_XMPFILES qDNGXMPFiles
  134. -#define XMP_StaticBuild 1
  135. +#define XMP_StaticBuild 0
  136. #if qiPhone
  137. #undef UNIX_ENV
  138. EOF
  139. patch -ruN -d "$dng_root" --strip 1 < "$workdir"/sdk.patch
  140. rm -f "$workdir"/sdk.patch
  141. make XMP_PUB_DIR="$xmp_root"/public
  142. fi
  143. cp "$dng_root"/dng_sdk/source/dng_validate "$workdir"/dng_validate
  144. cp "$xmp_build"/{libXMPCore.so,libXMPFiles.so} "$workdir"/