Created a new Makefrag-user-app helper for building binaries
authorDavide Libenzi <dlibenzi@google.com>
Tue, 15 Dec 2015 23:46:36 +0000 (15:46 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Mon, 21 Dec 2015 17:56:49 +0000 (12:56 -0500)
Created a new Makefrag-user-app helper for building binaries.
It works on a similar line of Makefrag-user-lib, allowing apps to
specify a minimal makefile, and providing clean stdout output.

Signed-off-by: Davide Libenzi <dlibenzi@google.com>
[touched up some comments leftover from Makefrag-user-lib]
Signed-off-by: Barret Rhoden <brho@cs.berkeley.edu>
Makefile
tools/apps/snc/Makefile
user/Makefrag-user-app [new file with mode: 0644]

index bd19cad..b90d8e3 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -417,8 +417,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: ;
@@ -669,16 +670,27 @@ realclean: userclean mrproper doxyclean objclean
 # Bundled apps
 # =========================================================================
 
-PHONY += apps-install
-apps-install: install-libs
+app-dirs = tools/apps/snc
+tagged-app-dirs := $(subst /,__,$(app-dirs))
+app-dirs-install := $(addprefix _install_,$(tagged-app-dirs))
+app-dirs-clean := $(addprefix _clean_,$(tagged-app-dirs))
+
+PHONY += $(app-dirs-install) $(app-dirs-clean)
+
+$(app-dirs-install):
+       @$(MAKE) -C $(patsubst _install_%,%,$(subst __,/,$@)) install
+
+$(app-dirs-clean):
+       @$(MAKE) -C $(patsubst _clean_%,%,$(subst __,/,$@)) clean
+
+PHONY +=  apps-install
+apps-install: $(app-dirs-install)
        @$(call make_as_parent, -C tools/apps/busybox)
-       @$(call make_as_parent, -C tools/apps/snc install)
        @$(call make_as_parent, -C tools/profile/perf install)
 
 PHONY += apps-clean
-apps-clean:
+apps-clean: $(app-dirs-clean)
        @$(call make_as_parent, -C tools/apps/busybox clean)
-       @$(call make_as_parent, -C tools/apps/snc clean)
        @$(call make_as_parent, -C tools/profile/perf clean)
 
 # Cross Compiler
index 2678e98..85eeecd 100644 (file)
@@ -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 (file)
index 0000000..9930594
--- /dev/null
@@ -0,0 +1,60 @@
+# Makefrag for some user apps
+# 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)
+
+$(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)