For now I only used it for snc. Plan to use it for perf as well.
Did not touch kprof2perf, as it is going away in the perf branch.


https://github.com/brho/akaros/compare/master...dlibenzi:makefrag_user_app

The following changes since commit c8a6943551e4eb433c058e258bca0a99e713d581:

  Rename backtrace_kframe -> backtrace_hwtf [2/2] (2015-12-10 11:26:40
-0500)

are available in the git repository at:

  [email protected]:dlibenzi/akaros makefrag_user_app

for you to fetch changes up to 8b262d2dde201f186115e7bfddd09d59df1aed7f:

  Created a new Makefrag-user-app helper for building binaries (2015-12-15
15:46:36 -0800)

----------------------------------------------------------------
Davide Libenzi (1):
      Created a new Makefrag-user-app helper for building binaries

 Makefile                |  7 +++---
 tools/apps/snc/Makefile | 41 ++-------------------------------
 user/Makefrag-user-app  | 61
+++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 67 insertions(+), 42 deletions(-)
 create mode 100644 user/Makefrag-user-app

diff --git a/Makefile b/Makefile
index 8defe95..d0de66f 100644
--- a/Makefile
+++ b/Makefile
@@ -404,8 +404,9 @@ kfs-paths := kern/kfs
 endif

 FIRST_KFS_PATH = $(firstword $(kfs-paths))
+ABS_KFS_PATH = $(abspath $(FIRST_KFS_PATH))

-export OBJDIR FIRST_KFS_PATH
+export OBJDIR FIRST_KFS_PATH ABS_KFS_PATH

 # Avoiding implicit rules
 $(srctree)/Makelocal: ;
@@ -659,13 +660,13 @@ PHONY += apps-install
 apps-install:
  @$(call make_as_parent, -C tools/apps/busybox)
  @$(call make_as_parent, -C tools/profile/kprof2perf install)
- @$(call make_as_parent, -C tools/apps/snc install)
+ @$(MAKE) -C tools/apps/snc DEPLIBS="$^" && $(MAKE) -C tools/apps/snc
install

 PHONY += apps-clean
 apps-clean:
  @$(call make_as_parent, -C tools/apps/busybox clean)
  @$(call make_as_parent, -C tools/profile/kprof2perf clean)
- @$(call make_as_parent, -C tools/apps/snc clean)
+ @$(MAKE) -C tools/apps/snc clean

 # Cross Compiler
 # =========================================================================
diff --git a/tools/apps/snc/Makefile b/tools/apps/snc/Makefile
index 2678e98..85eeecd 100644
--- a/tools/apps/snc/Makefile
+++ b/tools/apps/snc/Makefile
@@ -1,39 +1,2 @@
-# Do not:
-# o  use make's built-in rules and variables
-#    (this increases performance and avoids hard-to-debug behaviour);
-# o  print "Entering directory ...";
-MAKEFLAGS += -rR --no-print-directory
-
-# Overrides
-BUILDDIR ?= $(shell pwd)
-AKAROS_ROOT ?= $(BUILDDIR)/../../..
-MAKE_JOBS ?= 4
-KFS_ROOT ?= $(AKAROS_ROOT)/kern/kfs
-
-XCC = $(CROSS_COMPILE)gcc
-
-
-PHONY := all
-all: snc
-
-
-PHONY += snc
-snc: snc.c
- @$(XCC) $(ROS_CFLAGS) $(ROS_LDFLAGS) -o snc snc.c
-
-
-PHONY += install
-install: all
- @cp snc $(KFS_ROOT)/bin/snc
-
-
-PHONY += clean
-clean:
- @rm -f snc
-
-
-PHONY += mrproper
-mrproper: clean
-
-
-.PHONY: $(PHONY)
+APPNAME = snc
+include ../../../user/Makefrag-user-app
diff --git a/user/Makefrag-user-app b/user/Makefrag-user-app
new file mode 100644
index 0000000..64dac87
--- /dev/null
+++ b/user/Makefrag-user-app
@@ -0,0 +1,61 @@
+# Makefrag for most user libraries
+# They must set APPNAME, then include this fragment
+# e.g.  APPNAME = perf
+
+ARCH ?= none # catch bugs
+SRCDIR ?=
+INCDIR = $(shell if [ -d "$(SRCDIR)include" ]; then echo
"$(SRCDIR)include";\
+ else echo -n ""; fi)
+
+OBJDIR ?= $(SRCDIR)obj
+# DEPLIBS passed in from the top-level Makefile
+DEPLIBS := $(DEPLIBS)
+DEPLIBAS = $(patsubst %, $(XCC_TARGET_LIB)/lib%.a, $(DEPLIBS))
+
+ifneq ($(INCDIR),)
+ INCS = -I$(INCDIR)
+endif
+
+FINALAPP = $(OBJDIR)/$(APPNAME)
+FINALAPP-INSTALL = $(ABS_KFS_PATH)/bin/$(APPNAME)
+
+uc = $(shell echo $(1) | tr a-z A-Z)
+
+APPUCNAME := $(call uc, $(APPNAME))
+HEADERS := $(shell find $(INCDIR) -name "*.h")
+CFILES  := $(wildcard $(SRCDIR)*.c)
+CFILES  += $(wildcard $(SRCDIR)$(ARCH)/*.c)
+SFILES  := $(wildcard $(SRCDIR)$(ARCH)/*.S)
+OBJS    := $(patsubst %.c, $(OBJDIR)/%.o, $(CFILES)) \
+           $(patsubst %.S, $(OBJDIR)/%.o, $(SFILES))
+
+all: $(FINALAPP)
+ @:
+
+$(OBJDIR)/$(ARCH)/%.o: $(SRCDIR)$(ARCH)/%.S $(HEADERS) $(DEPLIBAS)
+ @echo + as [$(APPUCNAME)] $<
+ @mkdir -p $(@D)
+ $(Q)$(CC) $(CFLAGS_USER) $(INCS) -o $@ -c $<
+
+$(OBJDIR)/%.o: $(SRCDIR)%.c $(HEADERS) $(DEPLIBAS)
+ @echo + cc [$(APPUCNAME)] $<
+ @mkdir -p $(@D)
+ $(Q)$(CC) $(CFLAGS_USER) $(INCS) -o $@ -c $<
+
+$(FINALAPP): $(OBJS)
+ @echo + ld [$(APPUCNAME)] $@
+ @mkdir -p $(@D)
+ $(Q)$(CC) -o $@ $(OBJS) $(DEPLIBAS)
+
+# Allow three different patterns for installing include files
+$(FINALAPP-INSTALL): $(FINALAPP)
+ @echo + in [$(APPUCNAME)] $< $@
+ @cp $< $@
+
+install: $(FINALAPP-INSTALL)
+ @echo > /dev/null
+
+clean:
+ @echo + clean [$(APPUCNAME)]
+ $(Q)rm -rf $(FINALAPP)
+ $(Q)rm -rf $(OBJDIR)

-- 
You received this message because you are subscribed to the Google Groups 
"Akaros" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to