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