diff build.xml @ 28:c310ec097194

Add Linux support.
author David Barts <n5jrn@me.com>
date Fri, 25 Dec 2020 19:07:47 -0800
parents 9bf3d8de6904
children e90d290a9a8d
line wrap: on
line diff
--- a/build.xml	Fri Dec 25 18:58:45 2020 -0800
+++ b/build.xml	Fri Dec 25 19:07:47 2020 -0800
@@ -29,6 +29,31 @@
     ]]>
   </scriptdef>
 
+  <!-- estimate disk usage -->
+  <scriptdef language="javascript" name="du">
+    <attribute name="path" />
+    <attribute name="target" />
+    <![CDATA[
+      "use strict";
+      var File = Java.type('java.io.File');
+      function du(fp) {
+        if (fp.isDirectory()) {
+          var files = fp.listFiles();
+          if (!files) return 0;
+          var total = 0;
+          for (var i=0; i<files.length; i++)
+            total += du(files[i]);
+          return total;
+        } else {
+          return fp.length();
+        }
+      }
+      var path = new File(attributes.get("path"));
+      project.setProperty(attributes.get("target"),
+        Math.round(du(path) / 1024) + "");
+    ]]>
+  </scriptdef>
+
   <!-- Define the properties used by the build -->
   <property name="app.name"      value="${ant.project.name}"/>
   <toLowerCase target="lc.app.name" value="${app.name}"/>
@@ -191,4 +216,64 @@
     </sequential>
   </target>
 
+  <target name="deb" depends="jar" description="Create Debian package.">
+    <fail message="Linux packages can only be built on Linux.">
+      <condition>
+        <not><os family="unix"/></not>
+      </condition>
+    </fail>
+    <sequential>
+      <mkdir dir="${dist.home}/data/usr/share/applications"/>
+      <copy file="${pf.home}/linux/deb/imageprep.desktop"
+        tofile="${dist.home}/data/usr/share/applications/imageprep.desktop"/>
+      <mkdir dir="${dist.home}/data/usr/share/icons/hicolor/48x48/apps"/>
+      <copy file="${pf.home}/linux/icon_48x48.png"
+        tofile="${dist.home}/data/usr/share/icons/hicolor/48x48/apps/imageprep.png"/>
+      <mkdir dir="${dist.home}/data/usr/share/imageprep"/>
+      <copy file="${jar.name}" todir="${dist.home}/data/usr/share/imageprep"/>
+      <mkdir dir="${dist.home}/data/usr/share/doc/imageprep"/>
+      <copy todir="${dist.home}/data/usr/share/doc/imageprep">
+        <filelist dir="${basedir}" files="Readme.html,Readme.rst"/>
+      </copy>
+      <copy todir="${dist.home}/data/usr/share/doc/imageprep" encoding="UTF-8" overwrite="true">
+        <fileset file="${pf.home}/linux/deb/copyright"/>
+        <filterset>
+          <filter token="app.copyright" value="${app.copyright}"/>
+        </filterset>
+      </copy>
+      <gzip src="${pf.home}/linux/deb/changelog"
+        destfile="${dist.home}/data/usr/share/doc/imageprep/changelog.gz"/>
+      <mkdir dir="${dist.home}/data/usr/share/man/man1"/>
+      <gzip src="${pf.home}/linux/imageprep.1"
+        destfile="${dist.home}/data/usr/share/man/man1/imageprep.1.gz"/>
+      <mkdir dir="${dist.home}/data/usr/bin"/>
+      <copy todir="${dist.home}/data/usr/bin" encoding="UTF-8" overwrite="true">
+        <fileset file="${pf.home}/linux/imageprep"/>
+        <filterset>
+          <filter token="jar.filename" value="${lc.app.name}.jar"/>
+        </filterset>
+      </copy>
+      <chmod file="${dist.home}/data/usr/bin/imageprep" perm="755"/>
+      <du path="${dist.home}/data" target="deb.installed.size"/>
+      <mkdir dir="${dist.home}/control"/>
+      <copy todir="${dist.home}/control" encoding="UTF-8" overwrite="true">
+        <fileset file="${pf.home}/linux/deb/control"/>
+        <filterset>
+          <filter token="app.version" value="${app.version}"/>
+          <filter token="deb.installed.size" value="${deb.installed.size}"/>
+        </filterset>
+      </copy>
+      <copy todir="${dist.home}/control">
+        <filelist dir="${pf.home}/linux/deb" files="postinst,postrm"/>
+      </copy>
+      <chmod perm="755">
+        <filelist dir="${dist.home}/control" files="postinst,postrm"/>
+      </chmod>
+      <exec executable="${basedir}/make-debian-package" failonerror="true">
+        <arg value="${dist.home}"/>
+        <arg value="${lc.app.name}_${app.version}.deb"/>
+      </exec>
+    </sequential>
+  </target>
+
 </project>