# common bits used by all libraries
#
-SRC_DIR = $(SRC_PATH)/$(SUBDIR)
-VPATH = $(SRC_DIR)
+# first so "all" becomes default target
+all: all-yes
-#FIXME: This should be in configure/config.mak
-ifeq ($(CONFIG_WIN32),yes)
-LDFLAGS = -Wl,--output-def,$(@:.dll=.def),--out-implib,lib$(SLIBNAME:$(SLIBSUF)=.dll.a)
-endif
+OBJS-$(HAVE_MMX) += $(MMX-OBJS-yes)
-ifeq ($(TARGET_GPROF),yes)
-CFLAGS+=-p
-LDFLAGS+=-p
-endif
+OBJS += $(OBJS-yes)
+FFLIBS := $(FFLIBS-yes) $(FFLIBS)
+TESTPROGS += $(TESTPROGS-yes)
-ifeq ($(TARGET_ARCH_SPARC64),yes)
-CFLAGS+= -mcpu=ultrasparc -mtune=ultrasparc
-endif
+FFEXTRALIBS := $(FFLIBS:%=-l%$(BUILDSUF)) $(EXTRALIBS)
-SRCS = $(OBJS:.o=.c) $(ASM_OBJS:.o=.S) $(CPPOBJS:.o=.cpp)
-OBJS := $(OBJS) $(ASM_OBJS) $(CPPOBJS)
-STATIC_OBJS := $(OBJS) $(STATIC_OBJS)
-SHARED_OBJS := $(OBJS) $(SHARED_OBJS)
+EXAMPLES := $(EXAMPLES:%=$(SUBDIR)%-example$(EXESUF))
+OBJS := $(sort $(OBJS:%=$(SUBDIR)%))
+TESTOBJS := $(TESTOBJS:%=$(SUBDIR)%) $(TESTPROGS:%=$(SUBDIR)%-test.o)
+TESTPROGS := $(TESTPROGS:%=$(SUBDIR)%-test$(EXESUF))
+HOSTOBJS := $(HOSTPROGS:%=$(SUBDIR)%.o)
+HOSTPROGS := $(HOSTPROGS:%=$(SUBDIR)%$(HOSTEXESUF))
+TOOLS += $(TOOLS-yes)
+TOOLOBJS := $(TOOLS:%=tools/%.o)
+TOOLS := $(TOOLS:%=tools/%$(EXESUF))
-all: $(LIB) $(SLIBNAME)
+DEP_LIBS := $(foreach NAME,$(FFLIBS),lib$(NAME)/$($(CONFIG_SHARED:yes=S)LIBNAME))
-$(LIB): $(STATIC_OBJS)
- rm -f $@
- $(AR) rc $@ $^ $(EXTRAOBJS)
- $(RANLIB) $@
+ALLHEADERS := $(subst $(SRC_DIR)/,$(SUBDIR),$(wildcard $(SRC_DIR)/*.h $(SRC_DIR)/$(ARCH)/*.h))
+SKIPHEADERS += $(ARCH_HEADERS:%=$(ARCH)/%) $(SKIPHEADERS-)
+SKIPHEADERS := $(SKIPHEADERS:%=$(SUBDIR)%)
+checkheaders: $(filter-out $(SKIPHEADERS:.h=.ho),$(ALLHEADERS:.h=.ho))
-$(SLIBNAME): $(SHARED_OBJS)
- $(CC) $(SHFLAGS) $(LDFLAGS) -o $@ $^ $(EXTRALIBS) $(EXTRAOBJS)
-ifeq ($(CONFIG_WIN32),yes)
- -lib /machine:i386 /def:$(@:.dll=.def)
-endif
+alltools: $(TOOLS)
-%.o: %.c
- $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
+$(HOSTOBJS): %.o: %.c
+ $(HOSTCC) $(HOSTCFLAGS) -c -o $@ $<
-%.o: %.S
- $(CC) $(CFLAGS) $(LIBOBJFLAGS) -c -o $@ $<
+$(HOSTPROGS): %$(HOSTEXESUF): %.o
+ $(HOSTCC) $(HOSTLDFLAGS) -o $@ $< $(HOSTLIBS)
-# BeOS: remove -Wall to get rid of all the "multibyte constant" warnings
-%.o: %.cpp
- g++ $(subst -Wall,,$(CFLAGS)) -c -o $@ $<
+$(OBJS): | $(sort $(dir $(OBJS)))
+$(HOSTOBJS): | $(sort $(dir $(HOSTOBJS)))
+$(TESTOBJS): | $(sort $(dir $(TESTOBJS)))
+$(TOOLOBJS): | tools
-depend: $(SRCS)
- $(CC) -MM $(CFLAGS) $^ 1>.depend
+OBJDIRS := $(OBJDIRS) $(dir $(OBJS) $(HOSTOBJS) $(TESTOBJS))
-dep: depend
+CLEANSUFFIXES = *.d *.o *~ *.ho *.map *.ver
+DISTCLEANSUFFIXES = *.pc
+LIBSUFFIXES = *.a *.lib *.so *.so.* *.dylib *.dll *.def *.dll.a *.exp
-clean::
- rm -f *.o *.d *~ *.a *.lib *.so *.dylib *.dll \
- *.lib *.def *.dll.a *.exp
-
-distclean: clean
- rm -f .depend
-
-ifeq ($(BUILD_SHARED),yes)
-INSTLIBTARGETS += install-lib-shared
-endif
-ifeq ($(BUILD_STATIC),yes)
-INSTLIBTARGETS += install-lib-static
-endif
-
-install: install-libs install-headers
-
-install-libs: $(INSTLIBTARGETS)
-
-install-lib-shared: $(SLIBNAME)
-ifeq ($(CONFIG_WIN32),yes)
- install $(INSTALLSTRIP) -m 755 $(SLIBNAME) "$(prefix)"
-else
- install $(INSTALLSTRIP) -m 755 $(SLIBNAME) \
- $(libdir)/$(SLIBNAME_WITH_VERSION)
- ln -sf $(SLIBNAME_WITH_VERSION) \
- $(libdir)/$(SLIBNAME_WITH_MAJOR)
- ln -sf $(SLIBNAME_WITH_VERSION) \
- $(libdir)/$(SLIBNAME)
-endif
-
-install-lib-static: $(LIB)
- install -m 644 $(LIB) "$(libdir)"
-
-install-headers:
- install -m 644 $(addprefix "$(SRC_DIR)"/,$(HEADERS)) "$(incdir)"
- install -m 644 $(BUILD_ROOT)/lib$(NAME).pc "$(libdir)/pkgconfig"
-
-#
-# include dependency files if they exist
-#
-ifneq ($(wildcard .depend),)
-include .depend
-endif
+-include $(wildcard $(OBJS:.o=.d) $(TESTOBJS:.o=.d))