Getting libcrypto ar error while compiling OpenSSL for Mac - macos

I have been able to compile a specific version of OpenSSL for iOS devices, and I am now trying to compile for Mac OSX. However, when I run my bash script (provided below) I am getting the following error:
ar r ../../libcrypto.a o_names.o obj_dat.o obj_lib.o obj_err.o obj_xref.o
ar: ../../libcrypto.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: ../../libcrypto.a: Inappropriate file type or format
When I run lipo -info libcrypto.a I get the following result:
Architectures in the fat file: libcrypto.a are: i386 x86_64
This does not make any sense, as my bash script is only configuring OpenSSL for i386 (I was looping to do both, but removed x86_64 once I started getting these problems).
I have tried following the answers for similar SO questions here and here. However, those yielded the same results. Additionally, the Mac installation instructions on the OpenSSL Wiki were of no help either.
My scripts:
Build.sh
projectDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ARCHS=("i386")
FIPS_VERSION="2.0.12"
OPENSSL_VERSION="1.0.2g"
rm -rf openssl* fips*
if [ -d "out" ]; then
rm -rf out
fi
mkdir out
source ./Build-FIPS.sh
cd $projectDir
source ./Build-OpenSSL.sh
Build-OpenSSL.sh
set -e
function main() {
verifyopenssl
for ((i=0; i < ${#ARCHS[#]}; i++))
do
makeopenssl "${ARCHS[i]}"
done
}
function verifyopenssl() {
gpg --verify $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz.asc
tar -zxf $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz
cd openssl-$OPENSSL_VERSION
}
function makeopenssl() {
BUILD_ARCH=$1
SDK_NAME="macosx"
GCC=$(xcrun -sdk ${SDK_NAME} -find gcc)
SDK_PATH=$(xcrun -sdk ${SDK_NAME} --show-sdk-path)
MACHINE="darwin-i386-cc"
# BSD_ARCH="BSD-generic32"
CONFIG_ARGS="$MACHINE \
$BSD_ARCH \
--openssldir=$projectDir/out/openssl_${BUILD_ARCH} \
fips \
--with-fipsdir=${projectDir}/out/fips_${BUILD_ARCH} \
no-idea \
no-cast \
no-seed \
no-md2 \
no-sha0 \
no-whirlpool \
-DL_ENDIAN"
export CC="${GCC} -arch ${BUILD_ARCH}"
export CFLAGS="-isysroot ${SDK_PATH} -I ${projectDir}/out/fips_${BUILD_ARCH}/include"
export LDFLAGS="-arch $BUILD_ARCH"
./Configure ${CONFIG_ARGS}
make depend
make
# make install
# make clean && make dclean
}
main $#

Following #jww's answer, I found that changing the following line (around line 69) in the main Makefile (the one in the root folder) solved the ar linking problem that #jww mentioned:
AR= ar $(ARFLAGS) r to AR= libtool -o
Making this change did get me further along in the process. However, I began having other problems. Further "research" led me to the OpenSSL FAQ page which had a question talking about OpenSSL failing to build on Mac. It pointed me to the PROBLEMS file in the root directory of the OpenSSL source code. That file said that there is a MAC ld problem:
This is really a misfeature in ld, which seems to look for .dylib
libraries along the whole library path before it bothers looking for
.a libraries. This means that -L switches won't matter unless OpenSSL
is built with shared library support.
The workaround may be to change the following lines in apps/Makefile
and test/Makefile:
LIBCRYPTO=-L.. -lcrypto
LIBSSL=-L.. -lssl
to:
LIBCRYPTO=../libcrypto.a
LIBSSL=../libssl.a
With this information, I created a patch file for the root Makefile and the Makefile in the apps folder. I also found that I had to comment out the instructions in the main Makefile and the apps/Makefile to build the openssl binary / executable. This should only be necessary if you want to run make install.
The patch files exists at the same level as the Build.sh script. And after fiddling around with my Build-OpenSSL.sh script I was finally able to get it to build for both i386 and x86_64.
For future reference, I am including the complete contents of the two patch files, and the original two script files below.
Build.sh
#!/bin/bash
#
projectDir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
ARCHS=("i386" "x86_64")
FIPS_VERSION="2.0.12"
OPENSSL_VERSION="1.0.2g"
rm -rf openssl*
if [ -d "out" ]; then
rm -rf out
fi
mkdir out
source ./Build-FIPS.sh
source ./Build-OpenSSL.sh
Build-OpenSSL.sh
#!/bin/bash
#
set -e
function main() {
verifyopenssl
for ((i=0; i < ${#ARCHS[#]}; i++))
do
makeopenssl "${ARCHS[i]}"
done
}
function verifyopenssl() {
gpg --verify $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz.asc
tar -zxf $projectDir/../Source/openssl-$OPENSSL_VERSION.tar.gz
cd openssl-$OPENSSL_VERSION
}
function makeopenssl() {
BUILD_ARCH=$1
SDK_NAME="macosx"
GCC=$(xcrun -sdk ${SDK_NAME} -find gcc)
SDK_PATH=$(xcrun -sdk ${SDK_NAME} --show-sdk-path)
if [[ $BUILD_ARCH = "i386" ]]; then
MACHINE="darwin-i386-cc"
NISTP=""
elif [[ $BUILD_ARCH = "x86_64" ]]; then
MACHINE="darwin64-x86_64-cc"
NISTP="enable-ec_nistp_64_gcc_128"
else
exit
fi
CONFIG_ARGS="$MACHINE \
$NISTP \
--openssldir=$projectDir/out/openssl_${BUILD_ARCH} \
fips \
--with-fipsdir=${projectDir}/out/fips_${BUILD_ARCH} \
no-idea \
no-cast \
no-seed \
no-md2 \
no-sha0 \
no-whirlpool \
-DL_ENDIAN"
./Configure ${CONFIG_ARGS}
patch Makefile < ../MainMake.patch
patch apps/Makefile < ../AppMake.patch
make depend
make build_libcrypto build_libssl
make install_sw
make clean && make dclean
patch -R Makefile < ../MainMake.patch
patch -R apps/Makefile < ../AppMake.patch
}
main $#
AppMake.patch
--- apps/Makefile 2016-03-01 06:36:53.000000000 -0700
+++ ../Makefile 2016-05-06 13:00:16.000000000 -0600
## -26,8 +26,8 ##
DLIBCRYPTO=../libcrypto.a
DLIBSSL=../libssl.a
-LIBCRYPTO=-L.. -lcrypto
-LIBSSL=-L.. -lssl
+LIBCRYPTO=../libcrypto.a
+LIBSSL=../libssl.a
PROGRAM= openssl
## -101,24 +101,24 ##
$(PERL) $(TOP)/util/files.pl Makefile >> $(TOP)/MINFO
install:
- #[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
- #set -e; for i in $(EXE); \
- do \
- (echo installing $$i; \
- cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
- chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
- mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \
- done;
- #set -e; for i in $(SCRIPTS); \
- do \
- (echo installing $$i; \
- cp $$i $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
- chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
- mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i ); \
- done
- #cp openssl.cnf $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
- chmod 644 $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
- mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf
+ # #[ -n "$(INSTALLTOP)" ] # should be set by top Makefile...
+ # #set -e; for i in $(EXE); \
+ # do \
+ # (echo installing $$i; \
+ # cp $$i $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+ # chmod 755 $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new; \
+ # mv -f $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i.new $(INSTALL_PREFIX)$(INSTALLTOP)/bin/$$i ); \
+ # done;
+ # #set -e; for i in $(SCRIPTS); \
+ # do \
+ # (echo installing $$i; \
+ # cp $$i $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
+ # chmod 755 $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new; \
+ # mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i.new $(INSTALL_PREFIX)$(OPENSSLDIR)/misc/$$i ); \
+ # done
+ # #cp openssl.cnf $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
+ # chmod 644 $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new; \
+ # mv -f $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf.new $(INSTALL_PREFIX)$(OPENSSLDIR)/openssl.cnf
tags:
ctags $(SRC)
MainMake.patch
--- Makefile 2016-05-06 13:06:11.000000000 -0600
+++ ../Makefile 2016-05-06 13:06:44.000000000 -0600
## -602,8 +602,8 ##
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libcrypto.pc
cp libssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/libssl.pc
- cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
- chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
+ # cp openssl.pc $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig
+ # chmod 644 $(INSTALL_PREFIX)$(INSTALLTOP)/$(LIBDIR)/pkgconfig/openssl.pc
install_html_docs:
here="`pwd`"; \

ar r ../../libcrypto.a o_names.o obj_dat.o obj_lib.o obj_err.o obj_xref.o
ar: ../../libcrypto.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
ar: ../../libcrypto.a: Inappropriate file type or format
ar, libtool and -arch is the reason the answer says "... supplying -arch x86_64 -arch i386 will result in a build failure because of the way OpenSSL's build system forms commands" at Build Multiarch OpenSSL on OS X.
You need to use Apple's libtool, and stop using ar. Apple's libtool knows about architectures, ar does not.
Another small wrinkle is the makefile does something like this, if I recall correctly. It makes it difficult to simply use Apple's libtool, and stop using ar:
$(AR) $(ARFLAGS) $# ...
In many makefiles you can simply make AR="libtool -o", but this case is different because the command comes out libtool -o r libcrypto.a or similar. I also seem to recall something like make AR="libtool" ARFLAGS="r -o $#" does not work well either.
I used to patch the makefile after config to do it.

Related

how to enable host compilation but not cross compilation on yocto on certain files

I am trying to build gutenprint 5.2.14 for arm platform using yocto project "devtool". During the compile process, I am getting this error for the file "lt-extract-strings" saying cannot binary execute file: Exec format error
Upon looking at the file, it a 32-bit arm-executable.
OpenWRT says to implement this when doing cross-compilation.
define Build/Compile
# Replace the cross-compiled "extract-string" by a shell-script that
# runs the host's own compiled version (gutenprint needs to run this)
(cd $(PKG_BUILD_DIR) && $(MAKE) -C src/xml extract-strings && \
$(RM) src/xml/extract-strings && \
echo '#!/bin/sh' > src/xml/extract-strings && \
echo 'exec $(HOST_BUILD_DIR)/src/xml/extract-strings "$$$$#" ' \
>> src/xml/extract-strings && chmod +x src/xml/extract-strings && cp src/xml/extract-strings /tmp/)
$(call Build/Compile/Default)
endef
the link to the file is here
I tried looking for sources on how to implement this fix above in a yocto recipe but I had no luck finding it. Can someone help me solve this issue ?
Thanks in advance

Make: Can we have directories as a target in GNUmakefile

I am working on GNUmake to create symlink to specific file by parsing whole directory which has a folder which needs to be linked.
Here is my makefile snippet.
TGT_LINK = /lan/test/workspace/build/tools
all_target: release_buid complete_test $(TGT_LINK)
$(TGT_LINK):
if [ ! -d $# ]; then mkdir -p $#; fi
cd $#; \
tar_ln=`\ls -d synopsystcl* | sed 's/synopsys//'`; \
sour_dir=`\ls -d synopsystcl*`; \
if ! [ -e $tar_ln ]; then \
ln -s $sour_dir $tar_ln; \
fi
Directory : /lan/test/workspace/build/tools Contains following content in it
polaris.so link.a dynamic.so kbuild.so README.txt license.txt synopsystcl5.5 build.json
Here i am trying to create symlink with name tcl5.5 pointing to synopsystcl5.5 with my above target $(TGT_LINK) code.
tcl5.5 -> synopsystcl5.5
After successful completion of two targets : release_buid complete_test , build is not proceeding to go for next target $(TGT_LINK) to create symlink. Could you please help whats wrong in code?
I would let make itself to check and recreate symlink as needed, i.e.:
TGT_LINK = /lan/test/workspace/build/tools
all_target: release_buid complete_test symlink
.PHONY: symlink
symlink: $(patsubst $(TGT_LINK)/tcl%, $(TGT_LINK)/synopsystcl%, $(wildcard $(TGT_LINK)/tcl*))
$(TGT_LINK)/synopsystcl%: $(TGT_LINK)/tcl%
set -e; \
cd $(#D); \
rm -f $(#F); \
ln -s $(<F) $(#F)
I would also consider reordering targets if there are dependencies indeed. One should never assume that dependency list is processed left to right; it will also lead to errors when parallel build (-j) is involved. If you have dependencies that something should happen before something else, it should be explicitly stated, e.g.:
all_target: symlink
symlink: complete_test
complete_test: release_buid

How to comment cmake code in ruby

I need to comment a line in this Ruby code (I'm using Atom to edit files ... )
The line is the follow .. -DPROJ4_LIBRARY:FILEPATH=#{prefix_dir}/lib/libproj.so and here you're the code ...
bash 'build-and-install-libgeotiff' do
user "root"
code <<-EOH
cd "/tmp"
tar xzf libgeotiff-#{version}.tar.gz
cd libgeotiff-#{version}
export MAKEFLAGS='-j2'
[ -d build ] || mkdir build
cd build
cmake3 .. \
-DCMAKE_INSTALL_PREFIX=#{prefix_dir} \
-DWITH_JPEG=ON \
-DWITH_ZLIB=ON \
-DWITH_PROJ4=ON \
-DPROJ4_INCLUDE_DIR:PATH=#{prefix_dir}/include \
-DPROJ4_LIBRARY:FILEPATH=#{prefix_dir}/lib/libproj.so
-DPROJ4_LIBRARY:FILEPATH=/usr/lib64/libproj.so
make && make install
EOH
I've tried to use # but it seems not right because my editor put automatically #{} ... here you're the transformed code ...
bash 'build-and-install-libgeotiff' do
user "root"
code <<-EOH
cd "/tmp"
tar xzf libgeotiff-#{version}.tar.gz
cd libgeotiff-#{version}
export MAKEFLAGS='-j2'
[ -d build ] || mkdir build
cd build
cmake3 .. \
-DCMAKE_INSTALL_PREFIX=#{prefix_dir} \
-DWITH_JPEG=ON \
-DWITH_ZLIB=ON \
-DWITH_PROJ4=ON \
-DPROJ4_INCLUDE_DIR:PATH=#{prefix_dir}/include \
#{}-DPROJ4_LIBRARY:FILEPATH=#{prefix_dir}/lib/libproj.so
-DPROJ4_LIBRARY:FILEPATH=/usr/lib64/libproj.so
make && make install
EOH
How may I comment my line in this code?
In Bash, if you comment out something in a sequence of lines joined by \, you comment out everything after the #.
Here's a quick and dirty workaround.
code <<-EOH
cd "/tmp"
tar xzf libgeotiff-#{version}.tar.gz
cd libgeotiff-#{version}
export MAKEFLAGS='-j2'
[ -d build ] || mkdir build
cd build
so_arg="-DPROJ4_LIBRARY:FILEPATH=#{prefix_dir}/lib/libproj.so"
cmake3 .. \
-DCMAKE_INSTALL_PREFIX=#{prefix_dir} \
-DWITH_JPEG=ON \
-DWITH_ZLIB=ON \
-DWITH_PROJ4=ON \
-DPROJ4_INCLUDE_DIR:PATH=#{prefix_dir}/include \
$so_arg \
-DPROJ4_LIBRARY:FILEPATH=/usr/lib64/libproj.so
make && make install
EOH
Now, you can simply sed -i s/so_arg=/\1#/' file to comment it out.

During cppunit make install error for task install-m4DATA appeared

I've been building freedesktop cppunit with mingw
https://www.freedesktop.org/wiki/Software/cppunit/
I've made some fixes to source files and makefiles and been able to
successfully execute commmands:
./autogen.sh
./configure
make
without any errors.
There was a need to set
m4_DATA = m4
instead of value "cppunit.m4" in Makefile.am(there was no such dir in build and it looks like such dir is "m4" dir).
After successful make execution doing
make --debug install
failed with error:
File install-m4DATA not found
from Makefile.am:
m4dir = $(datadir)/aclocal //what is datadir btw?
automake generated Makefile task:
install-m4DATA: $(m4_DATA)
#$(NORMAL_INSTALL) // fails at this line
test -z "$(m4dir)" || $(MKDIR_P) "$(DESTDIR)$(m4dir)"
#list='$(m4_DATA)'; test -n "$(m4dir)" || list=; \
for p in $$list; do \
if test -f "$$p"; then d=; else d="$(srcdir)/"; fi; \
echo "$$d$$p"; \
done | $(am__base_list) | \
while read files; do \
echo " $(INSTALL_DATA) $$files '$(DESTDIR)$(m4dir)'"; \
$(INSTALL_DATA) $$files "$(DESTDIR)$(m4dir)" || exit $$?; \
done
before that task NORMAL_INSTALL is set to:
NORMAL_INSTALL = :
How to fix "make install" execution.
Will it work if i have only mingw envieronment on my PC?
Version is 1.13.2 fresh from git repo.
I also post lines from "make --debug install" output
File 'install-m4DATA' does not exist.
Must remake target 'install-m4DATA'.
test -z "/usr/local/share/aclocal" || /usr/bin/mkdir -p "/usr/local/share/aclocal"
/usr/bin/install -c -m 644 ./m4 '/usr/local/share/aclocal'
Makefile:432: recipe for target 'install-m4DATA' failed
make[2]: Leaving directory 'c:/Users/user/projects/cppunit'
Makefile:799: recipe for target 'install-am' failed
make[1]: Leaving directory 'c:/Users/user/projects/cppunit'
Makefile:479: recipe for target 'install-recursive' failed
It also prints that that script omits directory at line
/usr/bin/install -c -m 644 ./m4 '/usr/local/share/aclocal'
Possibly here must go files from directory but not directory itself.
How to fix it to do that(i'm not familiar with Makefiles and bash)?

Compiling XNU kernel 2050

I'm a bit confused on the best way to compile the latest version of the XNU kernel. I've seen lots of instructions for older kernels that came with Mac OS X 10.4 but the newer sources lack a lot of the things that the instructions contain. Just running make on the XNU kernel source brings a lot of errors about not finding ctfconvert, ctfmerge and ctfdump. Does anyone have a good "howto" to build a new kernel?
A new book by Wiley details the complete set of how-to in chapter 9.
Try this:
#
# Getting C++ filter
#
$ curl http://opensource.apple.com/tarballs/cxxfilt/cxxfilt-9.tar.gz > cxx.tar.gz
$ tar xvf cxx.tar.gz
$ cd cxxfilt-9
$ mkdir -p build obj sym
$ make install RC_ARCHS="i386 x86_64" RC_CFLAGS="-arch i386 -arch x86_64 -pipe" \
RC_OS=macos RC_RELEASE=Lion SRCROOT=$PWD OBJROOT=$PWD/obj \ SYMROOT=$PWD/sym DSTROOT=$PWD/build
#
# Getting DTrace – This is required for ctfconvert, a kernel build tool
#
$ curl http://opensource.apple.com/tarballs/dtrace/dtrace-90.tar.gz > dt.tar.gz
$ tar zxvf dt.tar.gz
$ cd dtrace-90
$ mkdir -p obj sym dst
$ xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge \ ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym \ DSTROOT=$PWD/dst
#
# Getting Kext Tools
#
$ wget http://opensource.apple.com/tarballs/Kext_tools/Kext_tools-180.2.1.tar.gz \ > kt.tar.gz
$ tar xvf kt.tar.gz
$ cd Kext_tools-180.2.1
$ mkdir -p obj sym dst
$ xcodebuild install -target Kextsymboltool -target setsegname \ ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym \
DSTROOT=$PWD/dst
#
# Getting Bootstrap commands – newer versions are available, but would # force xcodebuild
#
$ curl http://opensource.apple.com/tarballs/bootstrap_cmds/bootstrap_cmds-72.tar.gz \ > bc.tar.gz
$ tar zxvf bc.tar.gz
$ cd bootstrap_cmds-84
$ mkdir -p obj sym dst
$ make install RC_ARCHS="i386" RC_CFLAGS="-arch i386 -pipe" RC_OS=macos \
RC_RELEASE=Lion SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst
The tar ball versions are now different (e.g. DTrace is 96, not 90) but this should work to satisfy dependencies. Once you have them, you just run the usual make (make ARCH_CONFIGS=" X86_64" KERNEL_CONFIGS="RELEASE"). You might want to add DEBUG, to get the great debug and trace messages which are disabled by default.
This works with XCode 4.4. Just tried it now, actually.
I don't think this will apply to Lion kernels, which will need a later version of XCode, but the way I got around the ctf* errors while building 10.6.8 kernels, was to use XCode 3.2.*
ctf* binaries are created during the "dtrace" compile.
Just run this script from a directory without any spaces, (eg ~/xnu is perfect). The end result should be a working 10.6.8 kernel. The later (and indeed, earlier) kernels are all simpler than 10.6.8.
#!/usr/bin/env bash
# Builds 10.6.8 kernel - most other builds are easier, this one needs a little patching.
# Script assembled by sfinktah
# Invaluable source: slice - http://www.projectosx.com/forum/lofiversion/index.php/t1922.html
# Note, two (got this down to one) patches necessary to build 10.6.8 - source: http://www.insanelymac.com/forum/index.php?showtopic=261736
# This is automatically applied, but I will detail here:
#
# You will have to do this: (Automated now, but just in case)
# Define CPUFAMILY_INTEL_SANDYBRIDGE in ~/xnu-1504.15.3/osfmk/mach/machine.h
# #define CPUFAMILY_INTEL_SANDYBRIDGE 0x5490b78c
#
# Skipped this step, seemed not to be needed (eventually). Leaving notes in, just in case.
# Add line 1 in ~/xnu-1504.15.3/makedefs/MakeInc.def:
# export BUILD_STABS = 1
#
# You should probaby use a local proxy, since this script makes no effort not to redownload
# existing items. Uncomment this line accordingly.
# export http_proxy=192.168.1.6:3128
export PATH="/usr/local/bin:$PATH"
CURL="curl -O "
echo "Download the build tools source(s)"
KEXT=kext_tools-180.2.1
BOOTSTRAP=bootstrap_cmds-79
DTRACE=dtrace-90
CXXFILT=cxxfilt-9
KERNEL=xnu-1504.15.3
CCTOOLS=cctools-806
# DYLD=dyld-132.13
# LD64=ld64-95.2.12
$CURL http://www.opensource.apple.com/tarballs/cxxfilt/$CXXFILT.tar.gz \
&& $CURL http://www.opensource.apple.com/tarballs/dtrace/$DTRACE.tar.gz \
&& $CURL http://www.opensource.apple.com/tarballs/kext_tools/$KEXT.tar.gz \
&& $CURL http://www.opensource.apple.com/tarballs/bootstrap_cmds/$BOOTSTRAP.tar.gz \
&& $CURL http://www.opensource.apple.com/tarballs/cctools/$CCTOOLS.tar.gz &&
# && # $CURL http://www.opensource.apple.com/tarballs/dyld/$DYLD.tar.gz
# && # $CURL http://www.opensource.apple.com/tarballs/ld64/$LD64.tar.gz
echo "Unpack the tools" \
&&
tar zxf $CXXFILT.tar.gz \
&& tar zxf $DTRACE.tar.gz \
&& tar zxf $KEXT.tar.gz \
&& tar zxf $BOOTSTRAP.tar.gz \
&& tar zxf $CCTOOLS.tar.gz &&
# && # tar zxf $LD64.tar.gz
# && # tar zxf $DYLD.tar.gz
# Copy folder cctools-8xx/include/mach-o/ to /usr/include/mach-o/
sudo cp -a $CCTOOLS/include/mach-o /usr/include/ \
&&
echo "Build cxxfilt" \
&&
cd $CXXFILT \
&& mkdir -p obj sym dst \
&& make install RC_ARCHS="i386 x86_64" RC_CFLAGS="-arch i386 -arch x86_64 -pipe" RC_OS=macos RC_RELEASE=SnowLeopard SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst \
&& sudo ditto $PWD/dst/usr/local /usr/local \
&& cd .. \
&&
echo "Build dtrace" \
&&
cd $DTRACE \
&& mkdir -p obj sym dst \
&& xcodebuild install -target ctfconvert -target ctfdump -target ctfmerge ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst \
&& sudo ditto $PWD/dst/usr/local /usr/local \
&& cd .. \
&&
echo "Build kext_tools" \
&&
cd $KEXT \
&& mkdir -p obj sym dst \
&& xcodebuild install -target kextsymboltool -target setsegname ARCHS="i386 x86_64" SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst \
&& sudo ditto $PWD/dst/usr/local /usr/local \
&& cd .. \
&&
echo "Build bootstrap_cmds" \
&&
cd $BOOTSTRAP \
&& mkdir -p obj sym dst \
&& make install RC_ARCHS="i386" RC_CFLAGS="-arch i386 -pipe" RC_OS=macos RC_RELEASE=SnowLeopard SRCROOT=$PWD OBJROOT=$PWD/obj SYMROOT=$PWD/sym DSTROOT=$PWD/dst \
&& sudo ditto $PWD/dst/usr/local /usr/local \
&& cd .. \
&&
echo "Download the xnu source" \
&&
$CURL http://www.opensource.apple.com/tarballs/xnu/$KERNEL.tar.gz \
&&
echo "Unpack xnu" \
&&
tar zxf $KERNEL.tar.gz \
&&
echo "Build xnu" \
&&
cd $KERNEL \
&& sed -i -e '1s/.*/#define CPUFAMILY_INTEL_SANDYBRIDGE 0x5490b78c \/*/' osfmk/mach/machine.h \
&& make ARCH_CONFIGS="I386 X86_64" KERNEL_CONFIGS="RELEASE" \
&& file BUILD/obj/RELEASE_*/mach_kernel &&
# && # Removing AppleProfileFamily.kext - http://lists.apple.com/archives/darwin-kernel/2009/Dec/msg00000.html
echo "Complete. Remember to remove /System/Library/Extensions/AppleProfileFamily.kext from target." \
|| echo "Failed"
# vim: set ts=180 sts=0 sw=3 noet:

Resources