]> git.ipfire.org Git - thirdparty/lldpd.git/commitdiff
osx: `make pkg` can now build universal binaries
authorVincent Bernat <bernat@luffy.cx>
Tue, 25 Jun 2013 14:21:45 +0000 (16:21 +0200)
committerVincent Bernat <bernat@luffy.cx>
Tue, 25 Jun 2013 14:21:45 +0000 (16:21 +0200)
Next step: compile for another SDK.

README.md
configure.ac
osx/Makefile.am
osx/lipo [new file with mode: 0755]

index 1cac5e270751b0b463e090e02c595b4396d7e407..8cd59a12ac1cee56d8318157bd32559bc5cc2edb 100644 (file)
--- a/README.md
+++ b/README.md
@@ -81,10 +81,12 @@ simpler alternatives:
         brew install https://raw.github.com/vincentbernat/lldpd/master/osx/lldpd.rb
 
  2. Build an OSX installer package which should work on the same
-    version of OS X, on the same architecture:
+    version of OS X (it is important to use a separate build
+    directory):
  
-        ./configure --prefix=/usr --sysconfdir=/etc --with-embedded-libevent
-        make -C osx pkg
+        mkdir build
+        ../configure --prefix=/usr --sysconfdir=/etc --with-embedded-libevent
+        make -C osx pkg ARCHS="i386 x86_64"
 
 If you don't follow the above procedures, you will have to create the
 user/group `_lldpd`. Have a look at how this is done in
index 1f8faa3ac5185dd1d3cdd7954a051a412efa0cc8..948dfdc87eae2b87625990b4a734e82d3fe4b61a 100644 (file)
@@ -20,6 +20,7 @@ AC_CONFIG_FILES([osx/Makefile osx/distribution.xml osx/im.bernat.lldpd.plist])
 AC_CONFIG_FILES([osx/scripts/preinstall], [chmod +x osx/scripts/preinstall])
 AC_CONFIG_FILES([osx/scripts/postinstall], [chmod +x osx/scripts/postinstall])
 AC_CONFIG_MACRO_DIR([m4])
+AC_SUBST([CONFIGURE_ARGS], [$ac_configure_args])
 
 # Configure automake
 AM_INIT_AUTOMAKE([foreign -Wall -Werror])
index d3805eaa14c4dc845b1c820962797189a2f556ef..bb03ec8baa0326ca0922d617194f7bed43c7f8b8 100644 (file)
@@ -1,4 +1,4 @@
-EXTRA_DIST = resources
+EXTRA_DIST = resources lipo
 
 if HOST_OS_OSX
 
@@ -12,6 +12,7 @@ requirements:
 PKG_NAME=@PACKAGE@-@VERSION@.pkg
 PKG_TITLE=@PACKAGE@ @VERSION@
 PKG_DIR=@PACKAGE@-@VERSION@
+ARCHS=@host_cpu@
 
 # Main target is `pkg`
 pkg: requirements ../$(PKG_NAME)
@@ -37,9 +38,22 @@ pkg.1/$(PKG_NAME): $(PKG_DIR) scripts
                --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)
+stamp-$(PKG_DIR): $(ARCHS:%=%/$(PKG_DIR))
+       $(srcdir)/lipo $(PKG_DIR) $^
+       touch $@
+
+pkg_curarch = $(@:stamp-%=%)
+$(ARCHS:%=%/$(PKG_DIR)): %/$(PKG_DIR): stamp-%
+$(ARCHS:%=stamp-%): stamp-%: im.bernat.lldpd.plist
+       [ -d $(pkg_curarch) ] || mkdir -p $(pkg_curarch)
+       (cd $(pkg_curarch) && \
+               $(abs_top_srcdir)/configure @CONFIGURE_ARGS@ \
+                       CC="@CC@ -arch $(pkg_curarch)" \
+                       CPP="@CPP@")
+       (cd $(pkg_curarch) && \
+               $(MAKE) install DESTDIR=$(abs_builddir)/$(pkg_curarch)/$(PKG_DIR))
        touch $@
 
 # Install launchd plist
@@ -49,8 +63,9 @@ install-data-local:
 uninstall-local:
        rm -rf $(DESTDIR)/Library/LaunchDaemons
 clean-local:
+       rm -rf $(ARCHS)
        rm -rf $(PKG_DIR)
-       rm -f stamp-$(PKG_DIR)
+       rm -f stamp-*
        rm -rf pkg.1
        rm -f ../$(PKG_NAME)
 
diff --git a/osx/lipo b/osx/lipo
new file mode 100755 (executable)
index 0000000..b229803
--- /dev/null
+++ b/osx/lipo
@@ -0,0 +1,56 @@
+#!/usr/bin/env python
+
+"""Apply lipo recursively to trees.
+"""
+
+import sys
+import os
+import shutil
+import subprocess
+
+# Parse arguments
+import argparse
+parser = argparse.ArgumentParser(description=sys.modules[__name__].__doc__,
+                                 formatter_class=argparse.RawDescriptionHelpFormatter)
+parser.add_argument("output", help="Output tree")
+parser.add_argument("input", help="Input trees", nargs="+")
+options = parser.parse_args()
+output = options.output
+inputs = options.input
+
+def ismacho(path):
+    """Check if a file is Mach-O"""
+    fnull = open(os.devnull, "w")
+    try:
+        subprocess.check_call(["lipo", "-info", path], stdout=fnull, stderr=fnull)
+    except subprocess.CalledProcessError:
+        return False
+    return True
+
+# Copy
+for root, dirs, files in os.walk(inputs[0]):
+    # Create root directory in output
+    oroot = root[len(inputs[0]):].lstrip("/")
+    oroot = os.path.join(output, oroot)
+    if not os.path.isdir(oroot):
+        os.makedirs(oroot)
+        shutil.copystat(root, oroot)
+
+    # Copy files
+    for f in files:
+        of = os.path.join(oroot, f)
+        f = os.path.join(root, f)
+        if os.path.islink(f):
+            # Symlink
+            linkto = os.readlink(f)
+            os.symlink(linkto, of)
+        elif ismacho(f):
+            sff = [ os.path.join(r, f[len(inputs[0]):].lstrip("/"))
+                    for r in inputs ]
+            args = [ "lipo", "-create", "-output", of ]
+            args.extend(sff)
+            subprocess.check_call(args)
+        else:
+            # Regular file, just copy from the first input directory
+            shutil.copyfile(f, of)
+            shutil.copystat(f, of)