Coder Social home page Coder Social logo

SUBDIRS question about nonrec-make HOT 6 CLOSED

aostruszka avatar aostruszka commented on May 20, 2024
SUBDIRS question

from nonrec-make.

Comments (6)

xulfir avatar xulfir commented on May 20, 2024

Looks like the problem was that SUBDIRS_TGTS would only be included if there wasn't a TARGETS specified for the current directory. The patch below solved the problem for me. I'm not sure if it will break anything else, though.

diff --git a/mk/footer.mk b/mk/footer.mk
index ad6cdae..1aec6c7 100644
--- a/mk/footer.mk
+++ b/mk/footer.mk
@@ -73,11 +73,8 @@ $(foreach tgt,$(filter-out $(AUTO_TGTS),$(TARGETS_$(d))),$(eval $(call tgt_rule,
 # dir_$(d) - see below)
 tree_$(d) : $(call subtree_tgts,$(d))

-# If the directory is just for grouping its targets will be targets from
-# all subdirectories
-ifeq ($(strip $(TARGETS_$(d))),)
-TARGETS_$(d) := $(SUBDIRS_TGTS)
-endif
+# Include targets from all subdirectories
+TARGETS_$(d) := $(SUBDIRS_TGTS) $(TARGETS_$(d))

 # This is a default rule - see Makefile
 dir_$(d) : $(TARGETS_$(d))

from nonrec-make.

aostruszka avatar aostruszka commented on May 20, 2024

This is by "design".
By default simple make should build only targets from directory where it was invoked - any targets from subdirectories should be built only if they are dependencies of targets from this directory.
To build all subtree targets as of now you can run in shell: "make tree_$(pwd)"
This should build all targets from given subtree even if they are not dependencies. However your comment caused me to check this and I will change current implementation since it can be done better as the clean_tree is. Moreover I will add a shortcut in Makefile so that simple "make tree" will be enough for what you need.

Best regards
Andrzej

PS. The part that you have changed is for the case where you split code over couple subdirectories. Then in the parent you can have Rules.mk with only "SUBDIRS ..." line and targets of this parent will be all targets from its subdirs.

from nonrec-make.

xulfir avatar xulfir commented on May 20, 2024

Thanks for explaining, Andrzej. I was assuming the SUBDIRS were being used as a means to collect all of the Rules.mk and targets to be built.

This brings up another question: If I wanted to explicitly call out goodbye as a build target (but keep the same directory layout), what would you recommend? This seems a bit tricky since TARGETS need to be relative to the OBJDIR, right? I tried adding ../goodbye/$(OBJDIR)/goodbye to ex3\Rules.mk's TARGETS, but I get an error because ex3/obj/../goodbye/obj/goodbye and ex3/goodbye/obj/goodbye aren't the same to make. The cleanest way I can think of is to put ex3/goodbye in the SUBDIRS of the parent directory's Rules (Rules.top in this case).

from nonrec-make.

aostruszka avatar aostruszka commented on May 20, 2024

If you want to call out compilation of only 'goodbye' then there are basically two choices. BTW I intended to point you to wiki pages on that, but ... it turns out that some part of [[Basic Concepts]] got lost when I moved from google to github. It is fixed now (points 5&6) and you might want to read it again.

  1. "make /full/path/to/goodbye/including/objdirs" - not very convenient unless you define in shell some variable that will hold the full path. However this will not survive beyond your current shell instance so my preference would be to ...
  2. Add an alias in Rules.mk in ex3 directory
    • e.g. "tests : dir_$(d)"
    • or "goodbye : $(OBJPATH)/goodbye"

Since you've indicated that this was meant to be some unit test the first case would cause "make tests" to build all targets from ex3 directory. Second case is just an alias for one particular test and with it you can just issue "make goodbye".

HTH
Andrzej

PS. I've uploaded new commit (50b724b) with this "tree" target, so I'm closing this "issue" :)

from nonrec-make.

aostruszka avatar aostruszka commented on May 20, 2024

Xulfir
I just thought that my answer might not be what you were looking for.
It depends on what you've meant by "I wanted to explicitly call out goodbye as a build target".
If by "call out" you've meant having ability to specify goodbye as a target during make invocation then the above answer should help. However if by "call out" you've meant using goodbye as e.g. some dependency inside Rules.mk then if this is in parents directory Rules.mk simple SUBDIRS_TGTS or TARGETS_$(subdir) should work. However if you want to refer to just one of the targets or using full path is inconvenient then using alias should be sufficient e.g. in ex3/Rules.mk just have
GB := $(OBJPATH)/goodbye
and you can use this variable.
This has some gotchas though so let me know if this answers your needs.
Best regards
Andrzej

from nonrec-make.

xulfir avatar xulfir commented on May 20, 2024

Thanks again, Andrzej. This has been very helpful. It is clear you've put a lot of thought into this project. I'm very glad you have shared it.
Cheers,
Xulfir

from nonrec-make.

Related Issues (19)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.