Makefile 1.41 KB
# Makefile for building libm/openlibm library

$(info >>> L-openlibm <<< T=$(TOP) D=$(DSTPATH) I=$(INCPATH) B=$(BLDPATH) CF=$(CFLAGS) F=$(FPUCFG) )

PWD:=$(shell pwd)
SOURCE_DIR?=$(PWD)

EXPHDRS=openlibm_math.h sfmath.h extmath.h
SOURCES=$(wildcard *.c)
OBJS=$(SOURCES:%.c=$(BLDPATH)/%.o)
DISS=$(SOURCES:%.c=$(BLDPATH)/%.dis)
LIBRARY=libm

SFDIR=../softfloat

ifeq ($(TOOL),llvm)
  CC=clang
  TOOLCHAIN=sparc-daiteq-elf
  #CFLAGS=-msoft-float -O3
  CFLAGS+=-target $(TOOLCHAIN) -mcpu=leon2
  # TODO: asm options according to selected type of FPU
  CFLAGS+=-Xassembler --has-fhalf -Xassembler --has-fpack -Xassembler -Aleon
endif
ifeq ($(TOOL),gcc)
  TOOLCHAIN=sparc-gaisler-elf
  CC=$(TOOLCHAIN)-gcc
  CFLAGS+=-mcpu=leon -qbsp=leon2 -mfix-at697f
endif

CFLAGS+=-ffunction-sections -fdata-sections
CFLAGS+=-I. -I$(SFDIR)/source/include
FPUTYPE=-daiteq-fpu-type=$(FPUCFG)

AR=$(TOOLCHAIN)-ar

.PHONY: all clean export


all: export
	@echo "Library is created"

$(BLDPATH):
	@mkdir -p $(BLDPATH)

$(BLDPATH)/$(LIBRARY).a: $(OBJS)
	@$(AR) crs $@ $^

$(BLDPATH)/%.o:%.c
	@$(CC) $(FPUTYPE) $(CFLAGS) -c $< -o $@

$(BLDPATH)/%.dis:$(BLDPATH)/%.o
	@$(TOOLCHAIN)-objdump -S $< > $@

clean:
	rm -rf $(BLDPATH)

export: $(DSTPATH)/$(LIBRARY).a $(DISS) $(EXPHDRS:%=$(INCPATH)/%)
	@echo "Library is exported"

$(DSTPATH)/$(LIBRARY).a: $(BLDPATH) $(BLDPATH)/$(LIBRARY).a
	@cp $(BLDPATH)/$(LIBRARY).a $(DSTPATH)

$(INCPATH)/%: $(SOURCE_DIR)/%
	ln -sf $< $@