#! /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) all-fx: $(lib-fx) all-cg: $(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) $(DESTDIR)$(PREFIX-fx); \ cp $(header) $(DESTDIR)$(PREFIX-fx)/include; \ fi if [[ ! -z $(lib-cg) ]]; then \ cp $(lib-cg) $(DESTDIR)$(PREFIX-cg); \ cp $(header) $(DESTDIR)$(PREFIX-cg)/include; \ fi .PRECIOUS: %/ .PHONY: all all-fx all-cg clean distclean install