From: Vincent Bernat Date: Sun, 23 Jun 2013 21:26:05 +0000 (+0200) Subject: osx: add a target to build an OSX package X-Git-Tag: 0.7.6~25 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=b708297cbab99c3e577bcac7d3cd620fc6777419;p=thirdparty%2Flldpd.git osx: add a target to build an OSX package 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. --- diff --git a/.gitignore b/.gitignore index ea514246..1455fd19 100644 --- a/.gitignore +++ b/.gitignore @@ -30,7 +30,7 @@ /src/compat/Makefile.in /src/Makefile.in /tests/Makefile.in -/man/Makefile.in +/osx/Makefile.in /ar-lib # cscope diff --git a/Makefile.am b/Makefile.am index 23c55f37..fde6c029 100644 --- a/Makefile.am +++ b/Makefile.am @@ -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 9f906261..2f7dbb39 100644 --- 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. diff --git a/README.md b/README.md index a0056ec7..eec6003b 100644 --- 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 ----- diff --git a/configure.ac b/configure.ac index ac71aac2..7192ca95 100644 --- a/configure.ac +++ b/configure.ac @@ -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 index 00000000..d3805eaa --- /dev/null +++ b/osx/Makefile.am @@ -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 index 00000000..43088c21 --- /dev/null +++ b/osx/distribution.xml.in @@ -0,0 +1,28 @@ + + + + @PACKAGE@ @VERSION@ + im.bernat.@PACKAGE@ + + + + + + + + + + + + @PACKAGE@-@VERSION@.pkg + diff --git a/osx/im.bernat.lldpd.plist.in b/osx/im.bernat.lldpd.plist.in new file mode 100644 index 00000000..5b7761e6 --- /dev/null +++ b/osx/im.bernat.lldpd.plist.in @@ -0,0 +1,14 @@ + + + + + Label + im.bernat.lldpd + ProgramArguments + + @prefix@/sbin/lldpd + + RunAtLoad + KeepAlive + + diff --git a/osx/resources/Welcome.rtf b/osx/resources/Welcome.rtf new file mode 100644 index 00000000..0e306b5a --- /dev/null +++ b/osx/resources/Welcome.rtf @@ -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 index 00000000..f0616a52 --- /dev/null +++ b/osx/resources/license.txt @@ -0,0 +1,5 @@ +Copyright (c) 2008-2013 Vincent Bernat + +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 index 00000000..afca49c8 --- /dev/null +++ b/osx/scripts/postinstall.in @@ -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 index 00000000..bb73125d --- /dev/null +++ b/osx/scripts/preinstall.in @@ -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