view src/makefile.inc @ 70:1e1c6feb7d83

fix build initcode
author anatofuz
date Tue, 30 Jul 2019 18:00:52 +0900
parents 58ec26c64601
children
line wrap: on
line source

# Cross-compiling (e.g., on Mac OS X, install arm-none-eabi-gcc with MacPorts)

CROSSCOMPILE := arm-linux-gnu-

CPU = armv8
#CC = /usr/local/cbclang/bin/clang
AS = $(CROSSCOMPILE)as
LD = $(CROSSCOMPILE)ld
OBJCOPY = $(CROSSCOMPILE)objcopy
OBJDUMP = $(CROSSCOMPILE)objdump

# CFLAGS = -march=${CPU} -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -Werror -I. -g -O0
CFLAGS = -target ${CPU}-none-eabi -I /net/open/Linux/arm/gcc-arm-none-eabi-7-2017-q4-major/arm-none-eabi/include/ /net/open/Linux/arm/gcc-arm-none-eabi-7-2017-q4-major/lib/gcc/arm-none-eabi/7.2.1/include-fixed/ -fno-pic -static -fno-builtin -fno-strict-aliasing -Wall -I. -g -O0
LDFLAGS = -L.
# ASFLAGS = -march=${CPU}
ASFLAGS = -target ${CPU}-none-eabi

#LIBGCC = $(shell $(gcc) -print-libgcc-file-name)
LIBGCC = /net/open/Linux/arm/gcc-arm-none-eabi-7-2017-q4-major/lib/gcc/arm-none-eabi/7.2.1/libgcc.a 

# host compiler
 HOSTCC_preferred = gcc
#HOSTCC_preferred = /usr/local/cbclang/bin/clang
define get_hostcc
    $(if $(shell which $(HOSTCC_preferred)),$(HOSTCC_preferred),"cc")
endef
HOSTCC := $(call get_hostcc)

# general rules
quiet-command = $(if $(V),$1,$(if $(2),@echo $2 && $1, @$1))

LINK_BIN = $(call quiet-command,$(LD) $(LDFLAGS) \
	-T $(1) -o $(2) $(3) $(LIBS) -b binary $(4), "  LINK     $(TARGET_DIR)$@")

LINK_INIT = $(call quiet-command,$(LD) $(LDFLAGS) \
	$(1) -o $@.out $<, "  LINK     $(TARGET_DIR)$@")
OBJCOPY_INIT = $(call quiet-command,$(OBJCOPY) \
	-S -O binary --prefix-symbols="_binary_$@" $@.out $@, "  OBJCOPY  $(TARGET_DIR)$@")

build-directory = $(shell mkdir -p build build/device build/lib)

build/%.o: %.c
	$(call build-directory)
	$(call quiet-command,$(CC) $(CFLAGS) \
		-c -o $@ $<,"  CC       $(TARGET_DIR)$@")

build/%.o: %.cbc
	$(call build-directory)
	$(call quiet-command,$(CC) $(CFLAGS) \
		-c -o $@ $<,"  CC       $(TARGET_DIR)$@")

AS_WITH = $(call quiet-command,$(CC) $(ASFLAGS) \
		$(1) -c -o $@ $<,"  AS       $(TARGET_DIR)$@")

build/%.o: %.S
	$(call build-directory)
	$(call AS_WITH, )