]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
osx: add a target to build an OSX package
authorVincent Bernat <bernat@luffy.cx>
Sun, 23 Jun 2013 21:26:05 +0000 (23:26 +0200)
committerVincent Bernat <bernat@luffy.cx>
Mon, 24 Jun 2013 17:45:56 +0000 (19:45 +0200)
We use pkgbuild and productbuild (which seem to have superseded
PackageMaker). Those tools are shipped from OSX 10.6.6. There are only
a few examples of how to use those tools with daemons. You may also
look at Jenkins or ngircd.

See `README.md` for more information on how to invoke the build of a
package.

12 files changed:
.gitignore
Makefile.am
NEWS
README.md
configure.ac
osx/Makefile.am [new file with mode: 0644]
osx/distribution.xml.in [new file with mode: 0644]
osx/im.bernat.lldpd.plist.in [new file with mode: 0644]
osx/resources/Welcome.rtf [new file with mode: 0644]
osx/resources/license.txt [new file with mode: 0644]
osx/scripts/postinstall.in [new file with mode: 0755]
osx/scripts/preinstall.in [new file with mode: 0755]

index ea514246c6a0f3e11cd46b82d47eeae31993c0d4..1455fd19bb01263e5528781425b76f7567a34bb3 100644 (file)
@@ -30,7 +30,7 @@
 /src/compat/Makefile.in
 /src/Makefile.in
 /tests/Makefile.in
-/man/Makefile.in
+/osx/Makefile.in
 /ar-lib
 
 # cscope
index 23c55f37ce8a1dbef8709d25c68fdaf29051d05d..fde6c0296bc0f57057b83a7fd44463eb8f2a021b 100644 (file)
@@ -2,7 +2,7 @@ include doxygen.am
 
 ACLOCAL_AMFLAGS = -I m4
 
-SUBDIRS      = src/compat src src/daemon src/lib src/client tests
+SUBDIRS      = src/compat src src/daemon src/lib src/client tests osx
 EXTRA_DIST   = $(DX_CONFIG) include get-version autogen.sh
 DIST_SUBDIRS = $(SUBDIRS) libevent
 DISTCLEANFILES = ChangeLog
diff --git a/NEWS b/NEWS
index 9f906261255c0dee117a160af8b5567ed9d4f72a..2f7dbb39854594ad66746b11ede8d5a0c031abf3 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -1,4 +1,6 @@
 lldpd (0.7.6)
+  * Features:
+    + Provide a way to build packages for OSX.
   * Fixes:
     + Compilation fix for OSX 10.6.
 
index a0056ec7a4af239ce108d47dd10c6ab55bc15179..eec6003be6c8cdde15301fa39a2c5d1bb5ca76b7 100644 (file)
--- a/README.md
+++ b/README.md
@@ -106,6 +106,16 @@ Alternatively, you can use a convenient brew formula:
 This formula includes the ability to interface properly with launchd
 to start `lldpd` at boot.
 
+You can also build a package with:
+
+    make -C osx pkg
+    
+To avoid the package being dependent of the system you built it on,
+you are advised to use the following `./configure` invocation:
+
+    ./configure CC="gcc -arch i386 -arch x86_64" CPP="gcc -E" \
+        --prefix=/usr --sysconfdir=/etc --with-embedded-libevent
+
 Usage
 -----
 
index ac71aac23a93191e8b344089ed99719330b70469..7192ca957887e696d61e100d6ff4cd72ac789d57 100644 (file)
@@ -18,7 +18,9 @@ AC_CONFIG_SRCDIR([src/log.c])
 AC_CONFIG_HEADER([config.h])
 AC_CONFIG_FILES([Makefile src/Makefile src/compat/Makefile src/daemon/Makefile
                          src/lib/Makefile src/lib/lldpctl.pc src/client/Makefile
-                         tests/Makefile])
+                         tests/Makefile
+                          osx/Makefile osx/distribution.xml osx/im.bernat.lldpd.plist
+                          osx/scripts/postinstall osx/scripts/preinstall])
 AC_CONFIG_MACRO_DIR([m4])
 
 # Configure automake
diff --git a/osx/Makefile.am b/osx/Makefile.am
new file mode 100644 (file)
index 0000000..d3805ea
--- /dev/null
@@ -0,0 +1,59 @@
+EXTRA_DIST = resources
+
+if HOST_OS_OSX
+
+# What we need to build the package
+PKGBUILD=/usr/bin/pkgbuild
+PRODUCTBUILD=/usr/bin/productbuild
+requirements:
+       @test -x $(PKGBUILD) || { echo "Needs pkgbuild ($(PKGBUILD))." ; exit 2 ; }
+       @test -x $(PRODUCTBUILD) || { echo "Needs productbuild ($(PRODUCTBUILD))." ; exit 2 ; }
+
+PKG_NAME=@PACKAGE@-@VERSION@.pkg
+PKG_TITLE=@PACKAGE@ @VERSION@
+PKG_DIR=@PACKAGE@-@VERSION@
+
+# Main target is `pkg`
+pkg: requirements ../$(PKG_NAME)
+       @echo "The package has been built in ../$(PKG_NAME)."
+
+# This is the package (to be built with productbuild)
+../$(PKG_NAME): pkg.1/$(PKG_NAME) distribution.xml resources
+       $(PRODUCTBUILD) \
+               --distribution distribution.xml \
+               --resources resources \
+               --package-path pkg.1 \
+               --version @VERSION@ \
+               $@
+
+# This is a component. We only have one. We could have more and
+# provide optional components to be installed.
+pkg.1/$(PKG_NAME): $(PKG_DIR) scripts
+       [ -d pkg.1 ] || mkdir pkg.1
+       $(PKGBUILD) \
+               --root $(PKG_DIR) \
+               --identifier im.bernat.@PACKAGE@.daemon \
+               --version @VERSION@ \
+               --ownership recommended \
+               --scripts scripts \
+               $@
+$(PKG_DIR): stamp-$(PKG_DIR)
+stamp-$(PKG_DIR): im.bernat.lldpd.plist
+       $(MAKE) -C $(top_builddir) install DESTDIR=$(abs_builddir)/$(PKG_DIR)
+       touch $@
+
+# Install launchd plist
+install-data-local:
+       install -m 0755 -d $(DESTDIR)/Library/LaunchDaemons
+       install -m 0644 im.bernat.lldpd.plist $(DESTDIR)/Library/LaunchDaemons
+uninstall-local:
+       rm -rf $(DESTDIR)/Library/LaunchDaemons
+clean-local:
+       rm -rf $(PKG_DIR)
+       rm -f stamp-$(PKG_DIR)
+       rm -rf pkg.1
+       rm -f ../$(PKG_NAME)
+
+.PHONY: pkg requirements
+
+endif
diff --git a/osx/distribution.xml.in b/osx/distribution.xml.in
new file mode 100644 (file)
index 0000000..43088c2
--- /dev/null
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="utf-8" standalone="no"?>
+<!-- The documentation for this file is available here:
+          https://developer.apple.com/library/mac/#documentation/DeveloperTools/Reference/DistributionDefinitionRef/Chapters/Distribution_XML_Ref.html -->
+<installer-gui-script minSpecVersion="1">
+    <title>@PACKAGE@ @VERSION@</title>
+    <organization>im.bernat.@PACKAGE@</organization>
+    <welcome file="Welcome.rtf" mime-type="text/rtf" />
+    <license file="license.txt" mime-type="text/plain" />
+    <pkg-ref id="im.bernat.@PACKAGE@.daemon"/>
+    <domains enable_localSystem="true"/>
+    <options customize="never" require-scripts="true" rootVolumeOnly="true" />
+    <choices-outline>
+        <line choice="im.bernat.@PACKAGE@.daemon"/>
+    </choices-outline>
+    <choice
+        id="im.bernat.@PACKAGE@.daemon"
+        visible="false"
+        title="lldpd daemon"
+        description="The LLDP daemon and its client."
+        start_selected="true">
+      <pkg-ref id="im.bernat.@PACKAGE@.daemon"/>
+    </choice>
+    <pkg-ref
+        id="im.bernat.@PACKAGE@.daemon"
+        version="0"
+        onConclusion="none"
+        auth="root">@PACKAGE@-@VERSION@.pkg</pkg-ref>
+</installer-gui-script>
diff --git a/osx/im.bernat.lldpd.plist.in b/osx/im.bernat.lldpd.plist.in
new file mode 100644 (file)
index 0000000..5b7761e
--- /dev/null
@@ -0,0 +1,14 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
+<plist version="1.0">
+<dict>
+  <key>Label</key>
+  <string>im.bernat.lldpd</string>
+  <key>ProgramArguments</key>
+  <array>
+    <string>@prefix@/sbin/lldpd</string>
+  </array>
+  <key>RunAtLoad</key><true/>
+  <key>KeepAlive</key><true/>
+</dict>
+</plist>
diff --git a/osx/resources/Welcome.rtf b/osx/resources/Welcome.rtf
new file mode 100644 (file)
index 0000000..0e306b5
--- /dev/null
@@ -0,0 +1,10 @@
+{\rtf1\ansi\ansicpg1252\cocoartf1187\cocoasubrtf390
+{\fonttbl\f0\fnil\fcharset0 Menlo-Regular;\f1\fswiss\fcharset0 Helvetica;}
+{\colortbl;\red255\green255\blue255;}
+\paperw11900\paperh16840\margl1440\margr1440\vieww10800\viewh8400\viewkind0
+\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\sa80\pardirnatural
+
+\f0\fs24 \cf0 lldp
+\f1 d is an ISC-licensed implementation of LLDP for various Unixes. It also supports some proprietary protocols.\
+\pard\tx566\tx1133\tx1700\tx2267\tx2834\tx3401\tx3968\tx4535\tx5102\tx5669\tx6236\tx6803\sa40\pardirnatural
+\cf0 LLDP allows you to know exactly on which port is a server (and reciprocally). It is an industry standard protocol designed to supplant proprietary Link-Layer protocols such as EDP or CDP. The goal of LLDP is to provide an inter-vendor compatible mechanism to deliver Link-Layer notifications to adjacent network devices.}
\ No newline at end of file
diff --git a/osx/resources/license.txt b/osx/resources/license.txt
new file mode 100644 (file)
index 0000000..f0616a5
--- /dev/null
@@ -0,0 +1,5 @@
+Copyright (c) 2008-2013 Vincent Bernat <bernat@luffy.cx>
+
+Permission to use, copy, modify, and/or distribute this software for any purpose with or without fee is hereby granted, provided that the above copyright notice and this permission notice appear in all copies.
+
+THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
diff --git a/osx/scripts/postinstall.in b/osx/scripts/postinstall.in
new file mode 100755 (executable)
index 0000000..afca49c
--- /dev/null
@@ -0,0 +1,29 @@
+#!/bin/bash
+
+set -e
+
+user="@PRIVSEP_USER@"
+group="@PRIVSEP_GROUP@"
+
+dscl=/usr/bin/dscl
+$dscl . -read "/Users/${user}" &> /dev/null || {
+    # We need to find a free UID/GID
+    uid=200
+    while $($dscl . -list /Users uid | grep -q "\b${uid}$") || \
+        $($dscl . -list /Users gid | grep -q "\b${uid}$"); do
+        uid=$((${uid} + 1))
+    done
+    $dscl . -create /Groups/${group}
+    $dscl . -create /Groups/${group} PrimaryGroupID ${uid}
+    $dscl . -create /Groups/${group} Password "*"
+    $dscl . -create /Groups/${group} RealName "lldpd privilege separation group"
+    $dscl . -create /Users/${user}
+    $dscl . -create /Users/${user} UserShell /usr/bin/false
+    $dscl . -create /Users/${user} NFSHomeDirectory /var/empty
+    $dscl . -create /Users/${user} PrimaryGroupID ${uid}
+    $dscl . -create /Users/${user} UniqueID ${uid}
+    $dscl . -create /Users/${user} Password "*"
+    $dscl . -create /Users/${user} RealName "lldpd privilege separation user"
+}
+
+/bin/launchctl load "/Library/LaunchDaemons/im.bernat.lldpd.plist"
diff --git a/osx/scripts/preinstall.in b/osx/scripts/preinstall.in
new file mode 100755 (executable)
index 0000000..bb73125
--- /dev/null
@@ -0,0 +1,7 @@
+#!/bin/bash
+
+set -e
+
+if /bin/launchctl list "im.bernat.lldpd" &> /dev/null; then
+    /bin/launchctl unload "/Library/LaunchDaemons/im.bernat.lldpd.plist"
+fi