From 1f77bfff9608f97996bffdb28dabec4e787631f6 Mon Sep 17 00:00:00 2001 From: Felix Fietkau Date: Thu, 7 Mar 2013 17:32:29 +0000 Subject: [PATCH] build: BSD compile fixes following patch allows to build images for Qemu ARM on OpenBSD 5.2 amd64 and FreeBSD 9.1 amd64. Mostly small pieces of code changes to get things right on the specific platform. Updated the README to describe better, which tools on the host are required. Added some kind of prepare scripts to install needed tools on BSD via packages. Signed-off-by: Waldemar Brodkorb SVN-Revision: 35900 --- README | 4 +-- include/host-build.mk | 2 +- include/host.mk | 3 +++ include/prereq-build.mk | 8 +++--- .../patches/004-use_env_for_bash.patch | 9 +++++++ scripts/freebsd.sh | 1 + scripts/openbsd.sh | 24 +++++++++++++++++ tools/Makefile | 12 ++++++--- .../patches/003-openbsd-compat.patch | 24 +++++++++++++++++ .../patches/004-freebsd-compat.patch | 13 ++++++++++ tools/include/endian.h | 5 ++++ tools/include/getline.h | 2 +- tools/mkimage/patches/020-openbsd_fixes.patch | 19 ++++++++++++++ tools/patch/Makefile | 18 +++++++++++++ tools/quilt/Makefile | 6 +---- .../patches/180-openbsd_compat.patch | 26 +++++++++++++++++++ tools/yaffs2/patches/110-openbsd-compat.patch | 14 ++++++++++ 17 files changed, 173 insertions(+), 17 deletions(-) create mode 100644 package/mac80211/patches/004-use_env_for_bash.patch create mode 100644 scripts/freebsd.sh create mode 100644 scripts/openbsd.sh create mode 100644 tools/e2fsprogs/patches/003-openbsd-compat.patch create mode 100644 tools/e2fsprogs/patches/004-freebsd-compat.patch create mode 100644 tools/mkimage/patches/020-openbsd_fixes.patch create mode 100644 tools/patch/Makefile create mode 100644 tools/squashfs4/patches/180-openbsd_compat.patch create mode 100644 tools/yaffs2/patches/110-openbsd-compat.patch diff --git a/README b/README index 9301fe456e..32e698d34e 100644 --- a/README +++ b/README @@ -3,8 +3,8 @@ This is the buildsystem for the OpenWrt Linux distribution. Please use "make menuconfig" to configure your appreciated configuration for the toolchain and firmware. -You need to have installed gcc, binutils, patch, bzip2, flex, -make, gettext, pkg-config, unzip, libz-dev and libc headers. +You need to have installed gcc, binutils, bzip2, flex, python, perl +make, find, grep, diff, unzip, gawk, getopt, libz-dev and libc headers. Run "./scripts/feeds update -a" to get all the latest package definitions defined in feeds.conf / feeds.conf.default respectively diff --git a/include/host-build.mk b/include/host-build.mk index 320e74ee47..126671a0b3 100644 --- a/include/host-build.mk +++ b/include/host-build.mk @@ -71,7 +71,7 @@ HOST_CONFIGURE_ARGS = \ HOST_MAKE_FLAGS = -HOST_CONFIGURE_CMD = ./configure +HOST_CONFIGURE_CMD = $(BASH) ./configure ifneq ($(HOST_OS),Darwin) ifeq ($(CONFIG_BUILD_STATIC_TOOLS),y) diff --git a/include/host.mk b/include/host.mk index 9b8a32b672..b44c1bf1ac 100644 --- a/include/host.mk +++ b/include/host.mk @@ -62,6 +62,9 @@ $(TMP_DIR)/.host.mk: $(TOPDIR)/include/host.mk PATCH=`which gpatch 2>/dev/null`; \ [ -n "$$PATCH" -a -x "$$PATCH" ] || PATCH=`which patch 2>/dev/null`; \ echo "PATCH:=$$PATCH" >> $@; \ + PYTHON=`which python2.7 2>/dev/null`; \ + [ -n "$$PYTHON" -a -x "$$PYTHON" ] || PYTHON=`which python 2>/dev/null`; \ + echo "PYTHON:=$$PYTHON" >> $@; \ ) endif diff --git a/include/prereq-build.mk b/include/prereq-build.mk index c7d59f1202..59ea7ef9a7 100644 --- a/include/prereq-build.mk +++ b/include/prereq-build.mk @@ -39,6 +39,8 @@ $(eval $(call Require,case-sensitive-fs, \ )) define Require/getopt + gnugetopt --help 2>&1 | grep long >/dev/null || \ + /usr/local/bin/getopt --help 2>&1 | grep long >/dev/null || \ getopt --help 2>&1 | grep long >/dev/null endef $(eval $(call Require,getopt, \ @@ -134,15 +136,11 @@ $(eval $(call RequireCommand,bzip2, \ Please install bzip2. \ )) -$(eval $(call RequireCommand,patch, \ - Please install patch. \ -)) - $(eval $(call RequireCommand,perl, \ Please install perl. \ )) -$(eval $(call RequireCommand,python, \ +$(eval $(call RequireCommand,$(PYTHON), \ Please install python. \ )) diff --git a/package/mac80211/patches/004-use_env_for_bash.patch b/package/mac80211/patches/004-use_env_for_bash.patch new file mode 100644 index 0000000000..889191d37e --- /dev/null +++ b/package/mac80211/patches/004-use_env_for_bash.patch @@ -0,0 +1,9 @@ +diff -Nur compat-wireless-2013-02-22.orig/compat/scripts/gen-compat-config.sh compat-wireless-2013-02-22/compat/scripts/gen-compat-config.sh +--- compat-wireless-2013-02-22.orig/compat/scripts/gen-compat-config.sh 2012-12-20 15:14:36.000000000 +0100 ++++ compat-wireless-2013-02-22/compat/scripts/gen-compat-config.sh 2013-03-07 17:27:04.000000000 +0100 +@@ -1,4 +1,4 @@ +-#!/bin/bash ++#!/usr/bin/env bash + # Copyright 2012 Luis R. Rodriguez + # Copyright 2012 Hauke Mehrtens + # diff --git a/scripts/freebsd.sh b/scripts/freebsd.sh new file mode 100644 index 0000000000..3107861ff8 --- /dev/null +++ b/scripts/freebsd.sh @@ -0,0 +1 @@ +env PACKAGESITE=ftp://ftp.freebsd.org/pub/FreeBSD/ports/amd64/packages-9.0-release/All/ pkg_add -r gmake-3.82.tbz bash-4.1.11.tbz python27-2.7.2_3.tbz gtar-1.26.tbz findutils-4.5.10_2.tbz coreutils-8.12.tbz getopt-1.1.4_2.tbz wget-1.13.4_1.tbz gnugrep-2.9.tbz gawk-4.0.0.tbz diff --git a/scripts/openbsd.sh b/scripts/openbsd.sh new file mode 100644 index 0000000000..dc9f4f7780 --- /dev/null +++ b/scripts/openbsd.sh @@ -0,0 +1,24 @@ +#!/bin/sh +ver=$(uname -r) +arch=$(uname -m) +echo "Preparing OpenBSD $arch $ver for OpenWrt" +PKG_PATH="http://ftp.openbsd.org/pub/OpenBSD/${ver}/packages/${arch}/" +export PKG_PATH +pkg_add -v gmake +pkg_add -v findutils +pkg_add -v coreutils +pkg_add -v gdiff +pkg_add -v rsync-- +pkg_add -v git +pkg_add -v bash +pkg_add -v unzip +pkg_add -v wget +pkg_add -v gtar-- +pkg_add -v ggrep +pkg_add -v gawk +pkg_add -v gsed +pkg_add -v xz +pkg_add -v apr-util-- +pkg_add -v cyrus-sasl-- +pkg_add -v subversion +pkg_add -v gnugetopt diff --git a/tools/Makefile b/tools/Makefile index d922c5364c..1d65e50ba9 100644 --- a/tools/Makefile +++ b/tools/Makefile @@ -15,7 +15,7 @@ tools-y += gmp mpfr mpc libelf endif tools-y += m4 libtool autoconf automake flex bison pkg-config sed mklibs tools-y += sstrip ipkg-utils genext2fs e2fsprogs mtd-utils mkimage -tools-y += firmware-utils patch-image quilt yaffs2 flock padjffs2 +tools-y += firmware-utils patch-image patch quilt yaffs2 flock padjffs2 tools-y += mm-macros xorg-macros xfce-macros missing-macros xz cmake scons tools-$(CONFIG_TARGET_orion_generic) += wrt350nv2-builder upslug2 tools-$(CONFIG_powerpc) += upx @@ -119,6 +119,8 @@ $(STAGING_DIR_HOST)/bin/stat: $(STAGING_DIR)/.prepared ln -s `which stat` $@; \ elif gstat --version > /dev/null 2>&1; then \ ln -s `which gstat` $@; \ + elif gnustat --version > /dev/null 2>&1; then \ + ln -s `which gnustat` $@; \ else \ echo "GNU stat not found"; \ false; \ @@ -128,10 +130,14 @@ $(eval $(call PrepareCommand,find,gfind find)) $(eval $(call PrepareCommand,md5sum,gmd5sum md5sum $(SCRIPT_DIR)/md5sum)) $(eval $(call PrepareCommand,cp,gcp cp)) $(eval $(call PrepareCommand,seq,gseq seq)) -$(eval $(call PrepareCommand,python,python2 python)) +$(eval $(call PrepareCommand,python,python2 python2.7 python)) $(eval $(call PrepareCommand,awk,gawk awk)) +$(eval $(call PrepareCommand,getopt,gnugetopt /usr/local/bin/getopt getopt)) +$(eval $(call PrepareCommand,grep,ggrep grep)) +$(eval $(call PrepareCommand,tar,gtar tar)) +$(eval $(call PrepareCommand,diff,gdiff diff)) -$(curdir)/cmddeps = $(patsubst %,$(STAGING_DIR_HOST)/bin/%,find md5sum cp stat seq python awk) +$(curdir)/cmddeps = $(patsubst %,$(STAGING_DIR_HOST)/bin/%,find md5sum cp stat seq python awk getopt grep tar diff) $(curdir)//prepare = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared $($(curdir)/cmddeps) $(curdir)//compile = $(STAGING_DIR)/.prepared $(STAGING_DIR_HOST)/.prepared $($(curdir)/cmddeps) diff --git a/tools/e2fsprogs/patches/003-openbsd-compat.patch b/tools/e2fsprogs/patches/003-openbsd-compat.patch new file mode 100644 index 0000000000..1f7cdca0e5 --- /dev/null +++ b/tools/e2fsprogs/patches/003-openbsd-compat.patch @@ -0,0 +1,24 @@ +diff -Nur e2fsprogs-1.42.7.orig/lib/blkid/getsize.c e2fsprogs-1.42.7/lib/blkid/getsize.c +--- e2fsprogs-1.42.7.orig/lib/blkid/getsize.c Fri Nov 30 03:40:18 2012 ++++ e2fsprogs-1.42.7/lib/blkid/getsize.c Thu Mar 7 14:21:59 2013 +@@ -26,6 +26,9 @@ + #include + #ifdef HAVE_SYS_IOCTL_H + #include ++#ifdef __OpenBSD__ ++#include ++#endif + #endif + #ifdef HAVE_LINUX_FD_H + #include +diff -Nur e2fsprogs-1.42.7.orig/lib/quota/mkquota.c e2fsprogs-1.42.7/lib/quota/mkquota.c +--- e2fsprogs-1.42.7.orig/lib/quota/mkquota.c Wed Jan 2 01:47:20 2013 ++++ e2fsprogs-1.42.7/lib/quota/mkquota.c Thu Mar 7 14:21:59 2013 +@@ -8,6 +8,7 @@ + #include + #include + #include ++#include + #include + #include + diff --git a/tools/e2fsprogs/patches/004-freebsd-compat.patch b/tools/e2fsprogs/patches/004-freebsd-compat.patch new file mode 100644 index 0000000000..5eff49999e --- /dev/null +++ b/tools/e2fsprogs/patches/004-freebsd-compat.patch @@ -0,0 +1,13 @@ +diff -Nur e2fsprogs-1.42.7.orig/lib/ext2fs/tdb.c e2fsprogs-1.42.7/lib/ext2fs/tdb.c +--- e2fsprogs-1.42.7.orig/lib/ext2fs/tdb.c 2012-07-06 15:37:27.000000000 +0200 ++++ e2fsprogs-1.42.7/lib/ext2fs/tdb.c 2013-03-07 14:54:59.000000000 +0100 +@@ -56,7 +56,9 @@ + #include + #endif + #include ++#ifndef __FreeBSD__ + #include ++#endif + #include + + #ifdef HAVE_SYS_MMAN_H diff --git a/tools/include/endian.h b/tools/include/endian.h index 0f17b41da7..bba70abd83 100644 --- a/tools/include/endian.h +++ b/tools/include/endian.h @@ -15,6 +15,11 @@ #define bswap_16(x) bswap16(x) #define bswap_32(x) bswap32(x) #define bswap_64(x) bswap64(x) +#elif defined(__OpenBSD__) +#include +#define bswap_16(x) __swap16(x) +#define bswap_32(x) __swap32(x) +#define bswap_64(x) __swap64(x) #else #include #define bswap_16(x) swap16(x) diff --git a/tools/include/getline.h b/tools/include/getline.h index 02df6c2f79..3ac21715b8 100644 --- a/tools/include/getline.h +++ b/tools/include/getline.h @@ -32,7 +32,7 @@ #include #include -#if !defined(__linux__) && !(defined(__APPLE__) && __DARWIN_C_LEVEL >= 200809L) +#if !defined(__linux__) && !defined(__OpenBSD__) && !(defined(__APPLE__) && __DARWIN_C_LEVEL >= 200809L) /* * Emulate glibc getline() via BSD fgetln(). * Note that outsize is not changed unless memory is allocated. diff --git a/tools/mkimage/patches/020-openbsd_fixes.patch b/tools/mkimage/patches/020-openbsd_fixes.patch new file mode 100644 index 0000000000..31ee38f66e --- /dev/null +++ b/tools/mkimage/patches/020-openbsd_fixes.patch @@ -0,0 +1,19 @@ +diff -Nur u-boot-2012.04.01.orig/tools/mkimage.c u-boot-2012.04.01/tools/mkimage.c +--- u-boot-2012.04.01.orig/tools/mkimage.c Wed Apr 25 15:22:50 2012 ++++ u-boot-2012.04.01/tools/mkimage.c Wed Mar 6 17:09:29 2013 +@@ -449,6 +449,7 @@ + #if defined(_POSIX_SYNCHRONIZED_IO) && \ + !defined(__sun__) && \ + !defined(__FreeBSD__) && \ ++ !defined(__OpenBSD__) && \ + !defined(__APPLE__) + (void) fdatasync (ifd); + #else +@@ -492,6 +493,7 @@ + #if defined(_POSIX_SYNCHRONIZED_IO) && \ + !defined(__sun__) && \ + !defined(__FreeBSD__) && \ ++ !defined(__OpenBSD__) && \ + !defined(__APPLE__) + (void) fdatasync (ifd); + #else diff --git a/tools/patch/Makefile b/tools/patch/Makefile new file mode 100644 index 0000000000..def8299095 --- /dev/null +++ b/tools/patch/Makefile @@ -0,0 +1,18 @@ +# +# Copyright (C) 2013 OpenWrt.org +# +# This is free software, licensed under the GNU General Public License v2. +# See /LICENSE for more information. +# +include $(TOPDIR)/rules.mk + +PKG_NAME:=patch +PKG_VERSION:=2.7.1 + +PKG_SOURCE:=$(PKG_NAME)-$(PKG_VERSION).tar.xz +PKG_SOURCE_URL:=ftp://ftp.gnu.org/gnu/patch +PKG_MD5SUM:=e9ae5393426d3ad783a300a338c09b72 + +include $(INCLUDE_DIR)/host-build.mk + +$(eval $(call HostBuild)) diff --git a/tools/quilt/Makefile b/tools/quilt/Makefile index 510d8f6fd5..541e656aff 100644 --- a/tools/quilt/Makefile +++ b/tools/quilt/Makefile @@ -15,12 +15,8 @@ PKG_MD5SUM:=f77adda60039ffa753f3c584a286f12b include $(INCLUDE_DIR)/host-build.mk -GETOPT:=$(shell which getopt) - HOST_CONFIGURE_ARGS += \ - --with-patch=$(PATCH) \ - --with-find=$(FIND) \ - --with-getopt=$(GETOPT) + --with-find=$(FIND) define Host/Configure cd $(HOST_BUILD_DIR) && autoconf diff --git a/tools/squashfs4/patches/180-openbsd_compat.patch b/tools/squashfs4/patches/180-openbsd_compat.patch new file mode 100644 index 0000000000..6d7a857a05 --- /dev/null +++ b/tools/squashfs4/patches/180-openbsd_compat.patch @@ -0,0 +1,26 @@ +diff -Nur squashfs4.2.orig/squashfs-tools/mksquashfs.c squashfs4.2/squashfs-tools/mksquashfs.c +--- squashfs4.2.orig/squashfs-tools/mksquashfs.c Tue Mar 5 16:20:49 2013 ++++ squashfs4.2/squashfs-tools/mksquashfs.c Tue Mar 5 16:25:10 2013 +@@ -32,6 +32,9 @@ + #include + #include + #include ++#if defined(__OpenBSD__) ++#include ++#endif + #include + #include + #include +diff -Nur squashfs4.2.orig/squashfs-tools/unsquashfs.h squashfs4.2/squashfs-tools/unsquashfs.h +--- squashfs4.2.orig/squashfs-tools/unsquashfs.h Tue Mar 5 16:20:49 2013 ++++ squashfs4.2/squashfs-tools/unsquashfs.h Tue Mar 5 16:25:57 2013 +@@ -25,6 +25,9 @@ + #define TRUE 1 + #define FALSE 0 + #include ++#if defined(__OpenBSD__) ++#include ++#endif + #include + #include + #include diff --git a/tools/yaffs2/patches/110-openbsd-compat.patch b/tools/yaffs2/patches/110-openbsd-compat.patch new file mode 100644 index 0000000000..cfafc1ca7e --- /dev/null +++ b/tools/yaffs2/patches/110-openbsd-compat.patch @@ -0,0 +1,14 @@ +diff -Nur yaffs2_android.orig/yaffs2/yaffs_guts.h yaffs2_android/yaffs2/yaffs_guts.h +--- yaffs2_android.orig/yaffs2/yaffs_guts.h Sun Feb 15 16:23:50 2009 ++++ yaffs2_android/yaffs2/yaffs_guts.h Tue Mar 5 15:45:21 2013 +@@ -823,6 +823,10 @@ + int yaffs_SetAttributes(yaffs_Object * obj, struct iattr *attr); + int yaffs_GetAttributes(yaffs_Object * obj, struct iattr *attr); + ++#if defined(__OpenBSD__) ++#define loff_t off_t ++#endif ++ + /* File operations */ + int yaffs_ReadDataFromFile(yaffs_Object * obj, __u8 * buffer, loff_t offset, + int nBytes); -- 2.30.2