axiom_c_runtime = @axiom_c_runtime@
LIBSPAD_SO_TARGET = @LIBSPAD_SO_TARGET@
GMP_WRAP_SO_TARGET = @GMP_WRAP_SO_TARGET@
lisp_flavor=@fricas_lisp_flavor@
SOLIB_FLAGS = @SOLIB_FLAGS@
axiom_c_runtime_extra = @axiom_c_runtime_extra@

core_sources = bsdsignal.c cfuns-c.c sockio-c.c
core_objects = $(core_sources:.c=.$(OBJEXT))
terminal_io_sources = cursor.c edin.c fnct_key.c openpty.c prt.c wct.c
graphics_sources = \
		halloc.c \
		hash.c \
		pixmap.c \
		spadcolors.c \
		util.c \
		XDither.c \
		XShade.c \
		XSpadFill.c

libspad_a_sources = $(foreach comp, \
			$(addsuffix _sources, $(axiom_c_runtime)), \
			$($(comp)))

libspad_a_SOURCES = $(addsuffix .pamphlet,$(libspad_a_sources))

other_sources = cfuns-c.c

other_SOURCES = $(addsuffix .pamphlet,$(other_sources))

unused_sources = emupty.c

libspad_a_objects = $(libspad_a_sources:.c=.$(OBJEXT))

other_objects = $(other_sources:.c=.$(OBJEXT))

pamphlets = Makefile.pamphlet $(libspad_a_SOURCES) $(other_SOURCES)

LIBSPAD_SO = $(axiom_target_libdir)/libspad.so

GMP_WRAP_SO = $(axiom_target_libdir)/gmp_wrap.so

subdir = src/lib/

.PHONY: all all-lib libspad_so
.SUFFIXES:
.SUFFIXES: .o .c .h

all: all-ax

all-ax all-lib: stamp
stamp: libspad.a $(other_objects) $(LIBSPAD_SO_TARGET) $(GMP_WRAP_SO_TARGET)
	rm -f stamp
	$(STAMP) stamp

libspad_so: $(LIBSPAD_SO)

gmp_wrap_so: $(GMP_WRAP_SO)

libspad.a: $(libspad_a_objects)
	$(AR) ru libspad.a $(libspad_a_objects)
	$(RANLIB) libspad.a

ifeq ($(shell uname -m)$(lisp_flavor),x86_64cmucl)
core_objects_32 = $(core_sources:.c=.$(OBJEXT)32)

.PRECIOUS: %.$(OBJEXT)32

%.$(OBJEXT)32: $(srcdir)/%.c $(axiom_c_macros_h)
	$(CC) -g -m32 -fPIC $(CCF) -c $(axiom_includes) $(AXIOM_X11_CFLAGS) $< -o $@

$(LIBSPAD_SO): $(core_objects_32)
	$(CC) -g -m32 $(SOLIB_FLAGS) $(core_objects_32) $(axiom_c_runtime_extra) -o $@
else
$(LIBSPAD_SO): $(core_objects)
	$(CC) -g $(SOLIB_FLAGS) $(core_objects) $(axiom_c_runtime_extra) -o $@

$(GMP_WRAP_SO): $(srcdir)/gmp_wrap.c
	$(CC) -g -fPIC $(SOLIB_FLAGS) $< -o $@
endif

.PRECIOUS: %.$(OBJEXT)

%.$(OBJEXT): $(srcdir)/%.c $(axiom_c_macros_h)
	$(CC) -g -fPIC $(CCF) -c $(axiom_includes) $(AXIOM_X11_CFLAGS) $< -o $@

# This is a support library, so it does not change often and
# we don't need to remove the produced objects in mostlyclean.
# The removal is done by clean.
mostlyclean-local:

clean-local: mostlyclean-local
	-rm -f $(libspad_a_objects) $(other_objects)
	-rm -f libspad.a
	-rm -f stamp

distclean-local: clean-local
