mail archive of the barebox mailing list
 help / color / mirror / Atom feed
From: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
To: barebox@lists.infradead.org
Subject: [PATCH 03/20] kbuild: add application (app) target
Date: Wed,  6 Mar 2013 10:29:32 +0100	[thread overview]
Message-ID: <1362562189-17783-3-git-send-email-plagnioj@jcrosoft.com> (raw)
In-Reply-To: <1362562189-17783-1-git-send-email-plagnioj@jcrosoft.com>

This will allow to link compiled object (app-y) to the built-in-app.o across the source
tree that will be finally link to the applications (app-final-y).

Now we compile the source %.c in app-%.o and provide -D__APP__
so we can known in the source when it's compile for barebox or pbl or app.

Signed-off-by: Jean-Christophe PLAGNIOL-VILLARD <plagnioj@jcrosoft.com>
---
 Makefile               |    5 +++-
 scripts/Makefile.build |   78 +++++++++++++++++++++++++++++++++++++++++++++---
 scripts/Makefile.lib   |   23 ++++++++++++--
 3 files changed, 99 insertions(+), 7 deletions(-)

diff --git a/Makefile b/Makefile
index 4df6464..110f7aa 100644
--- a/Makefile
+++ b/Makefile
@@ -493,6 +493,7 @@ barebox-alldirs	:= $(sort $(barebox-dirs) $(patsubst %/,%,$(filter %/, \
 		     $(core-n) $(core-) $(drivers-n) $(drivers-) \
 		     $(net-n)  $(net-)  $(libs-n)    $(libs-))))
 
+app-common-y	:= $(patsubst %/, %/built-in-app.o, $(common-y))
 pbl-common-y	:= $(patsubst %/, %/built-in-pbl.o, $(common-y))
 common-y	:= $(patsubst %/, %/built-in.o, $(common-y))
 
@@ -523,6 +524,8 @@ common-y	:= $(patsubst %/, %/built-in.o, $(common-y))
 # System.map is generated to document addresses of all kernel symbols
 
 barebox-common := $(common-y)
+barebox-app-common := $(app-common-y)
+export barebox-app-common
 barebox-pbl-common := $(pbl-common-y)
 export barebox-pbl-common
 barebox-all    := $(barebox-common)
@@ -733,7 +736,7 @@ barebox.srec: barebox
 
 # The actual objects are generated when descending,
 # make sure no implicit rule kicks in
-$(sort $(barebox-head) $(barebox-common) ) $(barebox-lds) $(barebox-pbl-common): $(barebox-dirs) ;
+$(sort $(barebox-head) $(barebox-common) ) $(barebox-lds) $(barebox-pbl-common) $(barebox-app-common): $(barebox-dirs) ;
 
 # Handle descending into subdirectories listed in $(barebox-dirs)
 # Preset locale variables to speed up the build process. Limit locale
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index a95bbe4..600d1f7 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -15,6 +15,8 @@ obj-m :=
 lib-y :=
 lib-m :=
 pbl-y :=
+app-y :=
+app-final-y :=
 always :=
 targets :=
 subdir-y :=
@@ -98,7 +100,7 @@ ifneq ($(strip $(lib-y) $(lib-m) $(lib-n) $(lib-)),)
 lib-target := $(obj)/lib.a
 endif
 
-ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(lib-target) $(pbl-y)),)
+ifneq ($(strip $(obj-y) $(obj-m) $(obj-n) $(obj-) $(lib-target) $(pbl-y) $(app-y)),)
 builtin-target := $(obj)/built-in.o
 endif
 
@@ -108,11 +110,23 @@ pbl-target := $(obj)/built-in-pbl.o
 endif
 endif
 
+ifeq ($(CONFIG_APPLICATIONS), y)
+ifneq ($(strip $(app-y) $(builtin-target)),)
+app-target := $(obj)/built-in-app.o
+endif
+
+ifneq ($(strip $(app-final-y)),)
+app-final-target := $(addprefix $(obj)/,$(app-final-y))
+app-final-bin-target := $(addsuffix .app,$(app-final-bin-target))
+endif
+
+endif
+
 # We keep a list of all modules in $(MODVERDIR)
 
-__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(pbl-target) $(extra-y)) \
+__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(pbl-target) $(app-target) $(extra-y)) \
 	 $(if $(KBUILD_MODULES),$(obj-m)) \
-	 $(subdir-ym) $(always)
+	 $(subdir-ym) $(always) $(app-final-target) $(app-final-bin-target)
 	@:
 
 # Linus' kernel sanity checking tool
@@ -185,10 +199,12 @@ cmd_cc_symtypes_c	   = \
 
 quiet_cmd_cc_o_c = CC $(quiet_modtag)  $@
 quiet_cmd_pbl_cc_o_c = PBLCC   $@
+quiet_cmd_app_cc_o_c = APPCC   $@
 
 ifndef CONFIG_MODVERSIONS
 cmd_cc_o_c = $(CC) $(c_flags) -c -o $@ $<
 cmd_pbl_cc_o_c = $(CC) -D__PBL__ $(c_flags) $(PBL_CPPFLAGS) -c -o $@ $<
+cmd_app_cc_o_c = $(CC) -D__APP__ $(APP_CPPFLAGS) $(app_c_flags) -c -o $@ $<
 
 else
 # When module versioning is enabled the following steps are executed:
@@ -239,8 +255,23 @@ define rule_pbl_cc_o_c
 	mv -f $(dot-target).tmp $(dot-target).cmd
 endef
 
+define rule_app_cc_o_c
+	$(call echo-cmd,checksrc) $(cmd_checksrc)			  \
+	$(call echo-cmd,app_cc_o_c) $(cmd_app_cc_o_c);			  \
+	$(cmd_modversions)						  \
+	scripts/basic/fixdep $(depfile) $@ '$(call make-cmd,app_cc__o_c)' >    \
+	                                              $(dot-target).tmp;  \
+	rm -f $(depfile);						  \
+	mv -f $(dot-target).tmp $(dot-target).cmd
+
+endef
+
 # Built-in and composite module parts
 
+app-%.o: %.c FORCE
+	$(call cmd,force_checksrc)
+	$(call if_changed_rule,app_cc_o_c)
+
 pbl-%.o: %.c FORCE
 	$(call cmd,force_checksrc)
 	$(call if_changed_rule,pbl_cc_o_c)
@@ -284,13 +315,19 @@ cmd_as_o_S       = $(CC) $(a_flags) -c -o $@ $<
 quiet_cmd_pbl_as_o_S = PBLAS   $@
 cmd_pbl_as_o_S       = $(CC) -D__PBL__ $(a_flags) $(PBL_CPPFLAGS) -c -o $@ $<
 
+quiet_cmd_app_as_o_S = APPAS   $@
+cmd_app_as_o_S       = $(CC) -D__APP__ $(app_a_flags) $(APP_CPPFLAGS) -c -o $@ $<
+
+app-%.o: %.S FORCE
+	$(call if_changed_dep,app_as_o_S)
+
 pbl-%.o: %.S FORCE
 	$(call if_changed_dep,pbl_as_o_S)
 
 %.o: %.S FORCE
 	$(call if_changed_dep,as_o_S)
 
-targets += $(real-objs-y) $(real-objs-m) $(lib-y) $(pbl-y)
+targets += $(real-objs-y) $(real-objs-m) $(lib-y) $(pbl-y) $(app-y)
 targets += $(extra-y) $(MAKECMDGOALS) $(always)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
@@ -336,6 +373,39 @@ $(pbl-target): $(pbl-y) FORCE
 targets += $(pbl-target)
 endif # pbl-target
 
+ifdef app-target
+quiet_cmd_app_link_o_target = APPLD   $@
+# If the list of objects to link is empty, just create an empty built-in-app.o
+cmd_app_link_o_target = $(if $(strip $(app-y)),\
+		      $(LD) $(app_ld_flags) -r -o $@ $(filter $(app-y), $^),\
+		      rm -f $@; $(AR) rcs $@)
+
+$(app-target): $(app-y) FORCE
+	$(call if_changed,app_link_o_target)
+targets += $(app-target)
+endif # app-target
+
+ifdef app-final-target
+quiet_cmd_app_final_ld = APPLD   $@
+cmd_app_final_ld = $(LD) $(LDFLAGS) $(LDFLAGS_apps) -o $@ \
+	-T $(apps-lds) \
+	--start-group $(filter-out $(apps-lds) $(barebox-app-common) FORCE ,$^) \
+	$(barebox-app-common) --end-group $(APP_LDFLAGS) \
+	$(filter-out $(apps-lds) $^ $(barebox-app-common) FORCE ,$^)
+
+$(app-final-target): $(obj)/built-in-app.o FORCE
+	$(call if_changed,app_final_ld)
+
+%.app: % FORCE
+	$(call if_changed,objcopy)
+	$(Q)$(kecho) '  Barebox Apps: $@ is ready'
+
+$(app-final-bin-target):	$(app-final-target) FORCE
+
+targets += $(app-final-target)
+targets += $(app-final-bin-target)
+endif # app-target
+
 #
 # Rule to compile a set of .o files into one .a file
 #
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 7bb769b..90bf72b 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -40,6 +40,17 @@ pbl-y		+= $(__pbl-y)
 
 pbl-y		:= $(sort $(patsubst %/, %/built-in-pbl.o, $(pbl-y)))
 
+# for non dirs add app- prefix to the target
+# so we recompile the source with custom flags and custom quiet
+__app-y		:= $(notdir $(app-y))
+app-y		:= $(patsubst %.o,app-%.o,$(__app-y))
+# add subdir from $(obj-y) and $(pbl-y)too so we do not need to have the dir define in
+# both $(obj-y) and $(pbl-y) and $(app-y)
+__app-y		:= $(filter-out $(app-y), $(filter %/, $(sort $(obj-y) $(pbl-y))))
+app-y		+= $(__app-y)
+
+app-y		:= $(sort $(patsubst %/, %/built-in-app.o, $(app-y)))
+
 __subdir-y	:= $(patsubst %/,%,$(filter %/, $(obj-y)))
 subdir-y	+= $(__subdir-y)
 __subdir-m	:= $(patsubst %/,%,$(filter %/, $(obj-m)))
@@ -65,9 +76,11 @@ multi-objs   := $(multi-objs-y) $(multi-objs-m)
 
 # $(subdir-obj-y) is the list of objects in $(obj-y) which uses dir/ to
 # tell kbuild to descend
-__subdir-obj-y := $(filter %/built-in-pbl.o, $(pbl-y))
+__subdir-pbl-y := $(filter %/built-in-pbl.o, $(pbl-y))
+__subdir-app-y := $(filter %/built-in-app.o, $(app-y))
 subdir-obj-y := $(filter %/built-in.o, $(obj-y))
-subdir-obj-y += $(__subdir-obj-y)
+subdir-obj-y += $(__subdir-pbl-y)
+subdir-obj-y += $(__subdir-app-y)
 
 # $(obj-dirs) is a list of directories that contain object files
 obj-dirs := $(dir $(multi-objs) $(subdir-obj-y))
@@ -85,6 +98,7 @@ obj-y		:= $(addprefix $(obj)/,$(obj-y))
 obj-m		:= $(addprefix $(obj)/,$(obj-m))
 lib-y		:= $(addprefix $(obj)/,$(lib-y))
 pbl-y		:= $(addprefix $(obj)/,$(pbl-y))
+app-y		:= $(addprefix $(obj)/,$(app-y))
 subdir-obj-y	:= $(addprefix $(obj)/,$(subdir-obj-y))
 real-objs-y	:= $(addprefix $(obj)/,$(real-objs-y))
 real-objs-m	:= $(addprefix $(obj)/,$(real-objs-m))
@@ -141,6 +155,11 @@ ___cpp_flags      = -Wp,-MD,$(depfile) $(NOSTDINC_FLAGS) $(__cpp_flags)
 
 ___ld_flags       = $(LDFLAGS) $(EXTRA_LDFLAGS)
 
+app_c_flags     = $(APPINCLUDE) $(___c_flags)
+app_a_flags     = $(APPINCLUDE) -D__ASSEMBLY__ $(___a_flags)
+app_cpp_flags   = $(APPINCLUDE) $(___cpp_flags)
+app_ld_flags    = $(___ld_flags)
+
 c_flags        = $(LINUXINCLUDE) $(___c_flags)
 a_flags        = $(LINUXINCLUDE) $(AFLAGS_LINUXINCLUDE) $(___a_flags)
 cpp_flags      = $(LINUXINCLUDE) $(___cpp_flags)
-- 
1.7.10.4


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

  parent reply	other threads:[~2013-03-06  9:34 UTC|newest]

Thread overview: 31+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-03-06  9:26 [RFC PATCH 00/20] introduce application support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29 ` [PATCH 01/20] Makefile: x_flags prepare for apps support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 02/20] tlsf_malloc: drop duplicate include Jean-Christophe PLAGNIOL-VILLARD
2013-03-07  7:37     ` Sascha Hauer
2013-03-06  9:29   ` Jean-Christophe PLAGNIOL-VILLARD [this message]
2013-03-06  9:29   ` [PATCH 04/20] Introduce application (app) support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 05/20] app: Introduce libc support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 06/20] app: add some utils Jean-Christophe PLAGNIOL-VILLARD
2013-03-06 21:21     ` Sascha Hauer
2013-03-06 21:34       ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-07  7:45         ` Sascha Hauer
2013-03-07  9:17           ` Alexander Aring
2013-03-06  9:29   ` [PATCH 07/20] app: Introduce example application Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 08/20] filetype: add barebox arm application Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 09/20] arm: add application support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:59     ` Alexander Shiyan
2013-03-06 10:13       ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 10/20] app: printf: use HelenOS verison with wide char support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 11/20] app: printf: add version from contiki Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 12/20] app: add tinycurses support Jean-Christophe PLAGNIOL-VILLARD
2013-03-06 11:31     ` Sascha Hauer
2013-03-06 13:04       ` Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 13/20] app: curses: add pdcurses Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 14/20] app: add test curses Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 15/20] app: pdcurses: add libmenu Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 16/20] app: pdcurses: add libform Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 17/20] app: curses: add menu example Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 18/20] app: curses: add panel example Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 19/20] app: curses: add form example Jean-Christophe PLAGNIOL-VILLARD
2013-03-06  9:29   ` [PATCH 20/20] highbank: enable application support Jean-Christophe PLAGNIOL-VILLARD
2013-03-07  7:36 ` [RFC PATCH 00/20] introduce " Sascha Hauer

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1362562189-17783-3-git-send-email-plagnioj@jcrosoft.com \
    --to=plagnioj@jcrosoft.com \
    --cc=barebox@lists.infradead.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox