libimg/Makefile

69 lines
1.3 KiB
Makefile

#! /usr/bin/make -f
# libimg Makefile
cflags := -ffreestanding -nostdlib -I.
header := libimg.h
# {target,cflags,lib}-{fx,cg} are provided by libimg.conf
include libimg.conf
# Files
src := $(wildcard src/*.c)
obj-fx := $(src:src/%=build-fx/%.o)
obj-cg := $(src:src/%=build-cg/%.o)
# Compiler paths
define compilerpath
ifneq "$(lib-$1)" ""
prefix-$1 := $$(shell $(target-$1)-gcc -print-search-dirs | grep install | \
sed 's/install: //')
ifeq "$$(prefix-$1)" ""
$$(error "Cannot determine $1 compiler install path")
endif
endif
endef
$(eval $(call compilerpath,fx))
$(eval $(call compilerpath,cg))
#
# Rules
#
all: $(lib-fx) $(lib-cg)
libimg-fx.a: $(obj-fx)
$(target-fx)-ar rcs $@ $^
libimg-cg.a: $(obj-cg)
$(target-cg)-ar rcs $@ $^
build-fx/%.c.o: src/%.c | build-fx/
$(target-fx)-gcc -c $< -o $@ $(cflags) $(cflags-fx) -DFX9860G
build-cg/%.c.o: src/%.c | build-cg/
$(target-cg)-gcc -c $< -o $@ $(cflags) $(cflags-cg) -DFXCG50
clean:
@ rm -rf build-fx build-cg
distclean: clean
@ rm -f $(lib-fx) $(lib-cg)
%/:
@ mkdir -p $@
#
# Installing
#
install:
if [[ ! -z $(lib-fx) ]]; then \
cp $(lib-fx) $(prefix-fx); \
cp $(header) $(prefix-fx)/include; \
fi
if [[ ! -z $(lib-cg) ]]; then \
cp $(lib-cg) $(prefix-cg); \
cp $(header) $(prefix-cg)/include; \
fi
.PRECIOUS: %/
.PHONY: all clean distclean install