Changeset 1476 for trunk


Ignore:
Timestamp:
Dec 20, 2011, 1:51:44 AM (3 years ago)
Author:
hailfinger
Message:

Cross-compilation fixes

Switch from host OS detection to target OS detection.
Complain about unknown target OS/architecture.
Disable annoying format string warnings on DJGPP.

Native and cross-compilation now usually just require setting CC.
Examples:
make CC=i586-pc-msdosdjgpp-gcc
make CC="clang -m64"
make CC=i686-w64-mingw32-gcc

Tested for a boatload of native and cross compilation configurations.

There is a new target "make libpayload" in case you don't want to
specify all tools by hand.

Signed-off-by: Carl-Daniel Hailfinger <c-d.hailfinger.devel.2006@…>
Acked-by: David Hendricks <dhendrix@…>

Location:
trunk
Files:
1 added
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/Makefile

    r1459 r1476  
    3838endif 
    3939 
    40 # FIXME We have to differentiate between host and target OS architecture. 
    41 OS_ARCH ?= $(shell uname) 
    42 ifneq ($(OS_ARCH), SunOS) 
     40# HOST_OS is only used to work around local toolchain issues. 
     41HOST_OS ?= $(shell uname) 
     42ifeq ($(HOST_OS), MINGW32_NT-5.1) 
     43# Explicitly set CC = gcc on MinGW, otherwise: "cc: command not found". 
     44CC = gcc 
     45endif 
     46ifneq ($(HOST_OS), SunOS) 
    4347STRIP_ARGS = -s 
    4448endif 
    45 ifeq ($(OS_ARCH), Darwin) 
     49 
     50# Determine the destination processor architecture. 
     51# IMPORTANT: The following line must be placed before TARGET_OS is ever used 
     52# (of course), but should come after any lines setting CC because the line 
     53# below uses CC itself. 
     54override TARGET_OS := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E os.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"')) 
     55 
     56ifeq ($(TARGET_OS), Darwin) 
    4657CPPFLAGS += -I/opt/local/include -I/usr/local/include 
    4758# DirectHW framework can be found in the DirectHW library. 
    4859LDFLAGS += -framework IOKit -framework DirectHW -L/opt/local/lib -L/usr/local/lib 
    4960endif 
    50 ifeq ($(OS_ARCH), FreeBSD) 
     61ifeq ($(TARGET_OS), FreeBSD) 
    5162CPPFLAGS += -I/usr/local/include 
    5263LDFLAGS += -L/usr/local/lib 
    5364endif 
    54 ifeq ($(OS_ARCH), OpenBSD) 
     65ifeq ($(TARGET_OS), OpenBSD) 
    5566CPPFLAGS += -I/usr/local/include 
    5667LDFLAGS += -L/usr/local/lib 
    5768endif 
    58 ifeq ($(OS_ARCH), DOS) 
     69ifeq ($(TARGET_OS), DOS) 
    5970EXEC_SUFFIX := .exe 
    6071CPPFLAGS += -I../libgetopt -I../libpci/include 
     72# DJGPP has odd uint*_t definitions which cause lots of format string warnings. 
     73CPPFLAGS += -Wno-format 
    6174# FIXME Check if we can achieve the same effect with -L../libgetopt -lgetopt 
    6275LIBS += ../libgetopt/libgetopt.a 
     
    8598endif 
    8699 
    87 ifeq ($(OS_ARCH), MINGW32_NT-5.1) 
    88 # Explicitly set CC = gcc on MinGW, otherwise: "cc: command not found". 
    89 CC = gcc 
     100# FIXME: Should we check for Cygwin/MSVC as well? 
     101ifeq ($(TARGET_OS), MinGW) 
     102EXEC_SUFFIX := .exe 
    90103# MinGW doesn't have the ffs() function, but we can use gcc's __builtin_ffs(). 
    91104CFLAGS += -Dffs=__builtin_ffs 
     
    167180endif 
    168181 
    169 ifeq ($(OS_ARCH), libpayload) 
    170 CC:=CC=i386-elf-gcc lpgcc 
    171 AR:=i386-elf-ar 
    172 RANLIB:=i386-elf-ranlib 
     182ifeq ($(TARGET_OS), libpayload) 
    173183CPPFLAGS += -DSTANDALONE 
    174184ifeq ($(CONFIG_DUMMY), yes) 
     
    203213# IMPORTANT: The following line must be placed before ARCH is ever used 
    204214# (of course), but should come after any lines setting CC because the line 
    205 # below uses CC itself. In some cases we set CC based on OS_ARCH, see above. 
    206 override ARCH := $(strip $(shell LC_ALL=C $(CC) -E arch.h 2>/dev/null | grep -v '^\#')) 
    207  
    208 ifeq ($(ARCH), "ppc") 
     215# below uses CC itself. 
     216override ARCH := $(strip $(shell LC_ALL=C $(CC) $(CPPFLAGS) -E arch.h 2>/dev/null | grep -v '^\#' | grep '"' | cut -f 2 -d'"')) 
     217 
     218ifeq ($(ARCH), ppc) 
    209219# There's no PCI port I/O support on PPC/PowerPC, yet. 
    210220ifeq ($(CONFIG_NIC3COM), yes) 
     
    349359FEATURE_CFLAGS += -D'CONFIG_INTERNAL=1' 
    350360PROGRAMMER_OBJS += processor_enable.o chipset_enable.o board_enable.o cbtable.o dmi.o internal.o 
    351 ifeq ($(ARCH),"x86") 
     361ifeq ($(ARCH), x86) 
    352362PROGRAMMER_OBJS += it87spi.o it85spi.o sb600spi.o wbsio_spi.o mcp6x_spi.o 
    353363PROGRAMMER_OBJS += ichspi.o ich_descriptors.o 
     
    477487 
    478488ifeq ($(NEED_NET), yes) 
    479 ifeq ($(OS_ARCH), SunOS) 
     489ifeq ($(TARGET_OS), SunOS) 
    480490LIBS += -lsocket 
    481491endif 
     
    486496FEATURE_CFLAGS += -D'NEED_PCI=1' 
    487497PROGRAMMER_OBJS += pcidev.o physmap.o hwaccess.o 
    488 ifeq ($(OS_ARCH), NetBSD) 
     498ifeq ($(TARGET_OS), NetBSD) 
    489499# The libpci we want is called libpciutils on NetBSD and needs NetBSD libpci. 
    490500LIBS += -lpciutils -lpci 
     
    492502LIBS += -l$(shell uname -p) 
    493503else 
    494 ifeq ($(OS_ARCH), DOS) 
     504ifeq ($(TARGET_OS), DOS) 
    495505# FIXME There needs to be a better way to do this 
    496506LIBS += ../libpci/lib/libpci.a 
    497507else 
    498508LIBS += -lpci 
    499 ifeq ($(OS_ARCH), OpenBSD) 
     509ifeq ($(TARGET_OS), OpenBSD) 
    500510# For (i386|amd64)_iopl(2). 
    501511LIBS += -l$(shell uname -m) 
     
    565575                rm -f .test.c .test$(EXEC_SUFFIX); exit 1) 
    566576        @rm -f .test.c .test$(EXEC_SUFFIX) 
    567         @printf "ARCH is " 
     577        @printf "Target arch is " 
    568578        @# FreeBSD wc will output extraneous whitespace. 
    569         @echo $(ARCH)|wc -l|grep -q '^[[:blank:]]*1[[:blank:]]*$$' ||   \ 
     579        @echo $(ARCH)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' ||   \ 
    570580                ( echo "unknown. Aborting."; exit 1) 
    571581        @printf "%s\n" '$(ARCH)' 
     582        @printf "Target OS is " 
     583        @# FreeBSD wc will output extraneous whitespace. 
     584        @echo $(TARGET_OS)|wc -w|grep -q '^[[:blank:]]*1[[:blank:]]*$$' ||      \ 
     585                ( echo "unknown. Aborting."; exit 1) 
     586        @printf "%s\n" '$(TARGET_OS)' 
    572587 
    573588define LIBPCI_TEST 
     
    685700 
    686701djgpp-dos: clean 
    687         make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip WARNERROR=no OS_ARCH=DOS 
     702        make CC=i586-pc-msdosdjgpp-gcc STRIP=i586-pc-msdosdjgpp-strip 
     703libpayload: clean 
     704        make CC="CC=i386-elf-gcc lpgcc" AR=i386-elf-ar RANLIB=i386-elf-ranlib 
    688705 
    689706.PHONY: all clean distclean compiler pciutils features export tarball dos featuresavailable 
Note: See TracChangeset for help on using the changeset viewer.