akaros/user/Makefrag-user-lib
<<
>>
Prefs
   1# Makefrag for most user libraries
   2# They must set LIBNAME, then include this fragment
   3# e.g.  LIBNAME = parlib
   4
   5ARCH ?= none    # catch bugs
   6SRCDIR ?=
   7INCDIR ?= $(SRCDIR)include
   8OBJDIR ?= $(SRCDIR)obj
   9CFLAGS_USER += $(CFLAGS_USER_LIBS)
  10# DEPLIBS passed in from the top-level Makefile
  11DEPLIBS := $(DEPLIBS)
  12DEPLIBAS = $(patsubst %, $(XCC_TARGET_LIB)/lib%.a, $(DEPLIBS))
  13
  14INCS = -I$(INCDIR)
  15FINALLIB = $(OBJDIR)/lib$(LIBNAME).a
  16FINALLIB-INSTALL = $(XCC_TARGET_LIB)/lib$(LIBNAME).a
  17
  18uc = $(shell echo $(1) | tr a-z A-Z)
  19
  20LIBUCNAME := $(call uc, $(LIBNAME))
  21HEADERS := $(shell find $(INCDIR) -name "*.h")
  22CFILES  := $(wildcard $(SRCDIR)*.c)
  23CFILES  += $(wildcard $(SRCDIR)$(ARCH)/*.c)
  24SFILES  := $(wildcard $(SRCDIR)$(ARCH)/*.S)
  25OBJS    := $(patsubst %.c, $(OBJDIR)/%.o, $(CFILES)) \
  26           $(patsubst %.S, $(OBJDIR)/%.o, $(SFILES))
  27
  28all: $(FINALLIB)
  29        @:
  30
  31$(OBJDIR)/$(ARCH)/%.o: $(SRCDIR)$(ARCH)/%.S $(HEADERS) $(DEPLIBAS)
  32        @echo + as [$(LIBUCNAME)] $<
  33        @mkdir -p $(@D)
  34        $(Q)$(CC) $(CFLAGS_USER) $(INCS) -o $@ -c $<
  35
  36$(OBJDIR)/%.o: $(SRCDIR)%.c $(HEADERS) $(DEPLIBAS)
  37        @echo + cc [$(LIBUCNAME)] $<
  38        @mkdir -p $(@D)
  39        $(Q)$(CC) $(CFLAGS_USER) $(INCS) -o $@ -c $<
  40
  41$(FINALLIB): $(OBJS)
  42        @echo + ar [$(LIBUCNAME)] $@
  43        @mkdir -p $(@D)
  44        $(Q)$(AR) rc $@ $(OBJS)
  45
  46# Allow two different patterns for installing include files
  47$(FINALLIB-INSTALL): $(FINALLIB)
  48        @cp $(FINALLIB) $@
  49        @if [ -d "$(INCDIR)/$(LIBNAME)" ]; then \
  50                rm -rf $(XCC_TARGET_INCLUDE)/$(LIBNAME) ; \
  51                cp -r $(INCDIR)/$(LIBNAME) $(XCC_TARGET_INCLUDE)/ ; \
  52        else \
  53                cp -r $(INCDIR)/*.h $(XCC_TARGET_INCLUDE)/ ; \
  54        fi;
  55
  56install: $(FINALLIB-INSTALL)
  57        @echo > /dev/null
  58
  59clean:
  60        @echo + clean [$(LIBUCNAME)]
  61        $(Q)rm -rf $(FINALLIB)
  62        $(Q)rm -rf $(OBJDIR)
  63