2009-06-04 Vladimir Serbinenko <phcoder@gmail.com>

Check if compiler is apple cc

	* Makefile.in (ASFLAGS): new variable
	(TARGET_ASFLAGS): likewise
	(TARGET_MODULE_FORMAT): likewise
	(TARGET_APPLE_CC): likewise
	(OBJCONV): likewise
	(TARGET_IMG_CFLAGS): likewise
	(TARGET_CPPFLAGS): add includedir
	* configure.ac: call grub_apple_cc and grub_apple_target_cc
	(TARGET_IMG_LDFLAGS): Add -Wl,-Ttext,. All users updated
	Check for linker script only if compiler isn't Apple's CC
	(TARGET_MODULE_FORMAT): set
	(TARGET_APPLE_CC): likewise
	(TARGET_ASFLAGS): likewise
	(ASFLAGS): likewise
	Check for objcopy only if compiler isn't Apple's CC
	Check for BSS symbol only if compiler isn't Apple's CC
	* genmk.rb: adapt nm options if we use Apple's utils
	* aclocal.m4 (grub_apple_cc): new test
	(grub_apple_target_cc): likewise
This commit is contained in:
phcoder 2009-06-04 19:53:52 +00:00
parent fb14123e01
commit 2b167a7218
6 changed files with 133 additions and 35 deletions

View File

@ -1,3 +1,27 @@
2009-06-04 Vladimir Serbinenko <phcoder@gmail.com>
Check if compiler is apple cc
* Makefile.in (ASFLAGS): new variable
(TARGET_ASFLAGS): likewise
(TARGET_MODULE_FORMAT): likewise
(TARGET_APPLE_CC): likewise
(OBJCONV): likewise
(TARGET_IMG_CFLAGS): likewise
(TARGET_CPPFLAGS): add includedir
* configure.ac: call grub_apple_cc and grub_apple_target_cc
(TARGET_IMG_LDFLAGS): Add -Wl,-Ttext,. All users updated
Check for linker script only if compiler isn't Apple's CC
(TARGET_MODULE_FORMAT): set
(TARGET_APPLE_CC): likewise
(TARGET_ASFLAGS): likewise
(ASFLAGS): likewise
Check for objcopy only if compiler isn't Apple's CC
Check for BSS symbol only if compiler isn't Apple's CC
* genmk.rb: adapt nm options if we use Apple's utils
* aclocal.m4 (grub_apple_cc): new test
(grub_apple_target_cc): likewise
2009-06-04 Vladimir Serbinenko <phcoder@gmail.com>
Simplify sed expressions and improve awk

View File

@ -64,16 +64,22 @@ mkinstalldirs = $(srcdir)/mkinstalldirs
CC = @CC@
CFLAGS = @CFLAGS@
ASFLAGS = @ASFLAGS@
LDFLAGS = @LDFLAGS@
CPPFLAGS = @CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include -Wall -W \
-DGRUB_LIBDIR=\"$(pkglibdir)\"
TARGET_CC = @TARGET_CC@
TARGET_CFLAGS = @TARGET_CFLAGS@
TARGET_ASFLAGS = @TARGET_ASFLAGS@
TARGET_MODULE_FORMAT = @TARGET_MODULE_FORMAT@
TARGET_APPLE_CC = @TARGET_APPLE_CC@
OBJCONV = @OBJCONV@
TARGET_CPPFLAGS = @TARGET_CPPFLAGS@ -I$(builddir) -I$(builddir)/include -I$(srcdir)/include \
-Wall -W
TARGET_LDFLAGS = @TARGET_LDFLAGS@
TARGET_IMG_LDSCRIPT = @TARGET_IMG_LDSCRIPT@
TARGET_IMG_LDFLAGS = @TARGET_IMG_LDFLAGS@
TARGET_IMG_CFLAGS = @TARGET_IMG_CFLAGS@
TARGET_OBJ2ELF = @TARGET_OBJ2ELF@
EXEEXT = @EXEEXT@
OBJCOPY = @OBJCOPY@
@ -186,8 +192,12 @@ build_env.mk: Makefile
(\
echo "TARGET_CC=$(TARGET_CC)" ; \
echo "TARGET_CFLAGS=$(TARGET_CFLAGS)" ; \
echo "TARGET_CPPFLAGS=$(TARGET_CPPFLAGS) -I$(pkglibdir)" ; \
echo "TARGET_ASFLAGS=$(TARGET_ASFLAGS)" ; \
echo "TARGET_CPPFLAGS=$(TARGET_CPPFLAGS) -I$(pkglibdir) -I$(includedir)" ; \
echo "STRIP=$(STRIP)" ; \
echo "OBJCONV=$(OBJCONV)" ; \
echo "TARGET_MODULE_FORMAT=$(TARGET_MODULE_FORMAT)" ; \
echo "TARGET_APPLE_CC=$(TARGET_APPLE_CC)" ; \
echo "COMMON_ASFLAGS=$(COMMON_ASFLAGS)" ; \
echo "COMMON_CFLAGS=$(COMMON_CFLAGS)" ; \
echo "COMMON_LDFLAGS=$(COMMON_LDFLAGS)"\

30
aclocal.m4 vendored
View File

@ -156,6 +156,36 @@ rm -f conftest*])
AC_MSG_RESULT([$grub_cv_i386_asm_addr32])])
dnl check if our compiler is apple cc
dnl because it requires numerous workarounds
AC_DEFUN(grub_apple_cc,
[AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([whether our compiler is apple cc])
AC_CACHE_VAL(grub_cv_apple_cc,
[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
grub_cv_apple_cc=yes
else
grub_cv_apple_cc=no
fi
])
AC_MSG_RESULT([$grub_cv_apple_cc])])
dnl check if our target compiler is apple cc
dnl because it requires numerous workarounds
AC_DEFUN(grub_apple_target_cc,
[AC_REQUIRE([AC_PROG_CC])
AC_MSG_CHECKING([whether our target compiler is apple cc])
AC_CACHE_VAL(grub_cv_apple_target_cc,
[if $CC -v 2>&1 | grep "Apple Inc." > /dev/null; then
grub_cv_apple_target_cc=yes
else
grub_cv_apple_target_cc=no
fi
])
AC_MSG_RESULT([$grub_cv_apple_target_cc])])
dnl Later versions of GAS requires that addr32 and data32 prefixes
dnl appear in the same lines as the instructions they modify, while

View File

@ -16,31 +16,31 @@ pkglib_IMAGES = boot.img diskboot.img kernel.img pxeboot.img lnxboot.img \
# For boot.img.
boot_img_SOURCES = boot/i386/pc/boot.S
boot_img_ASFLAGS = $(COMMON_ASFLAGS)
boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00
boot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)7C00
boot_img_FORMAT = binary
# For pxeboot.img
pxeboot_img_SOURCES = boot/i386/pc/pxeboot.S
pxeboot_img_ASFLAGS = $(COMMON_ASFLAGS)
pxeboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00
pxeboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)7C00
pxeboot_img_FORMAT = binary
# For diskboot.img.
diskboot_img_SOURCES = boot/i386/pc/diskboot.S
diskboot_img_ASFLAGS = $(COMMON_ASFLAGS)
diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,8000
diskboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)8000
diskboot_img_FORMAT = binary
# For lnxboot.img.
lnxboot_img_SOURCES = boot/i386/pc/lnxboot.S
lnxboot_img_ASFLAGS = $(COMMON_ASFLAGS)
lnxboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,6000
lnxboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)6000
lnxboot_img_FORMAT = binary
# For cdboot.img.
cdboot_img_SOURCES = boot/i386/pc/cdboot.S
cdboot_img_ASFLAGS = $(COMMON_ASFLAGS)
cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,7C00
cdboot_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)7C00
cdboot_img_FORMAT = binary
# For kernel.img.
@ -63,9 +63,9 @@ kernel_img_HEADERS = boot.h cache.h device.h disk.h dl.h elf.h elfload.h \
machine/biosdisk.h machine/boot.h machine/console.h machine/init.h \
machine/memory.h machine/loader.h machine/vga.h machine/vbe.h \
machine/kernel.h machine/pxe.h i386/pit.h list.h handler.h command.h
kernel_img_CFLAGS = $(COMMON_CFLAGS)
kernel_img_CFLAGS = $(COMMON_CFLAGS) $(TARGET_IMG_CFLAGS)
kernel_img_ASFLAGS = $(COMMON_ASFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS) -Wl,-Ttext,$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
kernel_img_LDFLAGS = $(COMMON_LDFLAGS) $(TARGET_IMG_LDFLAGS)$(GRUB_MEMORY_MACHINE_LINK_ADDR) $(COMMON_CFLAGS)
kernel_img_FORMAT = binary
MOSTLYCLEANFILES += symlist.c kernel_syms.lst

View File

@ -167,6 +167,11 @@ AC_C_BIGENDIAN
AC_CHECK_SIZEOF(void *)
AC_CHECK_SIZEOF(long)
grub_apple_cc
if test x$grub_cv_apple_cc == xyes ; then
CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
ASFLAGS="$ASFLAGS -DAPPLE_CC=1"
fi
if test "x$host_m32" = x1; then
# Force 32-bit mode.
CFLAGS="$CFLAGS -m32"
@ -206,31 +211,6 @@ AC_CHECK_FUNCS(posix_memalign memalign asprintf)
# Check for target programs.
#
# Use linker script if present, otherwise use builtin -N script.
AC_MSG_CHECKING([for option to link raw image])
if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT}"
TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
else
TARGET_IMG_LDSCRIPT=
TARGET_IMG_LDFLAGS='-Wl,-N'
TARGET_IMG_LDFLAGS_AC='-Wl,-N'
fi
AC_SUBST(TARGET_IMG_LDSCRIPT)
AC_SUBST(TARGET_IMG_LDFLAGS)
AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
# For platforms where ELF is not the default link format.
AC_MSG_CHECKING([for command to convert module to ELF format])
case "${host_os}" in
cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
*) ;;
esac
AC_SUBST(TARGET_OBJ2ELF)
AC_MSG_RESULT([$TARGET_OBJ2ELF])
# Find tools for the target.
if test "x$target_alias" != x && test "x$host_alias" != "x$target_alias"; then
tmp_ac_tool_prefix="$ac_tool_prefix"
@ -287,7 +267,7 @@ if test "x$TARGET_CFLAGS" = x; then
# Force no alignment to save space on i386.
if test "x$target_cpu" = xi386; then
AC_CACHE_CHECK([whether -falign-loops works], [grub_cv_cc_falign_loop], [
CFLAGS="-falign-loops=1"
CFLAGS="$CFLAGS -falign-loops=1"
AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[]], [[]])],
[grub_cv_cc_falign_loop=yes],
[grub_cv_cc_falign_loop=no])
@ -301,16 +281,59 @@ if test "x$TARGET_CFLAGS" = x; then
fi
fi
grub_apple_target_cc
if test x$grub_cv_apple_target_cc == xyes ; then
TARGET_CFLAGS="$TARGET_CFLAGS -DAPPLE_CC=1 -fnested-functions"
CFLAGS="$CFLAGS -DAPPLE_CC=1 -fnested-functions"
TARGET_ASFLAGS="$TARGET_ASFLAGS -DAPPLE_CC=1"
TARGET_APPLE_CC=1
TARGET_IMG_LDSCRIPT=
TARGET_IMG_CFLAGS="-static"
TARGET_IMG_LDFLAGS='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
TARGET_IMG_LDFLAGS_AC='-nostdlib -static -Wl,-preload -Wl,-segalign,20 -Wl,-image_base,'
else
TARGET_APPLE_CC=0
# Use linker script if present, otherwise use builtin -N script.
AC_MSG_CHECKING([for option to link raw image])
if test -f "${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"; then
TARGET_IMG_LDSCRIPT='$(top_srcdir)'"/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
TARGET_IMG_LDFLAGS="-Wl,-T${TARGET_IMG_LDSCRIPT} -Wl,-Ttext,"
TARGET_IMG_LDFLAGS_AC="-Wl,-T${srcdir}/conf/${target_cpu}-${platform}-${host_os}-img-ld.sc"
else
TARGET_IMG_LDSCRIPT=
TARGET_IMG_LDFLAGS='-Wl,-N -Wl,-Ttext,'
TARGET_IMG_LDFLAGS_AC='-Wl,-N -Wl,-Ttext,'
fi
TARGET_IMG_CFLAGS=
fi
AC_SUBST(TARGET_IMG_LDSCRIPT)
AC_SUBST(TARGET_IMG_LDFLAGS)
AC_SUBST(TARGET_IMG_CFLAGS)
AC_MSG_RESULT([$TARGET_IMG_LDFLAGS_AC])
# For platforms where ELF is not the default link format.
AC_MSG_CHECKING([for command to convert module to ELF format])
case "${host_os}" in
cygwin) TARGET_OBJ2ELF='grub-pe2elf' ;;
*) ;;
esac
AC_SUBST(TARGET_OBJ2ELF)
AC_MSG_RESULT([$TARGET_OBJ2ELF])
if test "x$target_m32" = x1; then
# Force 32-bit mode.
TARGET_CFLAGS="$TARGET_CFLAGS -m32"
TARGET_LDFLAGS="$TARGET_LDFLAGS -m32"
TARGET_MODULE_FORMAT="elf32"
fi
if test "x$target_m64" = x1; then
# Force 64-bit mode.
TARGET_CFLAGS="$TARGET_CFLAGS -m64"
TARGET_LDFLAGS="$TARGET_LDFLAGS -m64"
TARGET_MODULE_FORMAT="elf64"
fi
if test "$target_cpu"-"$platform" = x86_64-efi; then
@ -361,6 +384,9 @@ if test x"$sap_possible" = xyes; then
fi
AC_SUBST(TARGET_CFLAGS)
AC_SUBST(TARGET_MODULE_FORMAT)
AC_SUBST(TARGET_APPLE_CC)
AC_SUBST(TARGET_ASFLAGS)
AC_SUBST(TARGET_CPPFLAGS)
AC_SUBST(TARGET_LDFLAGS)
@ -375,7 +401,9 @@ AC_CHECK_FUNCS(__bswapsi2 __bswapdi2)
# Defined in aclocal.m4.
grub_PROG_TARGET_CC
if test "x$TARGET_APPLE_CC" != x1 ; then
grub_PROG_OBJCOPY_ABSOLUTE
fi
grub_PROG_LD_BUILD_ID_NONE
grub_ASM_USCORE
if test "x$target_cpu" = xi386; then
@ -383,7 +411,7 @@ if test "x$target_cpu" = xi386; then
# Check symbols provided by linker script.
CFLAGS="$TARGET_CFLAGS -nostdlib $TARGET_IMG_LDFLAGS_AC -Wl,-Ttext,8000,--defsym,___main=0x8100"
fi
if test "x$platform" = xpc; then
if test "x$platform" = xpc && test "x$TARGET_APPLE_CC" != x1 ; then
grub_CHECK_BSS_START_SYMBOL
grub_CHECK_END_SYMBOL
fi
@ -482,6 +510,7 @@ AC_ARG_ENABLE([efiemu],
[AS_HELP_STRING([--enable-efiemu],
[build and install the efiemu runtimes])])
AC_SUBST([enable_efiemu])
AC_SUBST(ASFLAGS)
# Output files.
grub_CHECK_LINK_DIR

View File

@ -129,8 +129,13 @@ UNDSYMFILES += #{undsym}
sh $(srcdir)/genmodsrc.sh '#{mod_name}' $< > $@ || (rm -f $@; exit 1)
ifneq ($(#{prefix}_EXPORTS),no)
ifneq ($(TARGET_APPLE_CC),1)
#{defsym}: #{pre_obj}
$(NM) -g --defined-only -P -p $< | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
else
#{defsym}: #{pre_obj}
$(NM) -g -P -p $< | grep -E '^[a-zA-Z0-9_]* [TDS]' | sed 's/^\\([^ ]*\\).*/\\1 #{mod_name}/' > $@
endif
endif
#{undsym}: #{pre_obj}