Last active
December 9, 2022 02:31
-
-
Save doitian/4978329 to your computer and use it in GitHub Desktop.
Forward Makefile to subdirectory `build`
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # List targets defined in this file | |
| TARGETS_SELF := cmake | |
| # Exclude targets defined in this file | |
| TARGETS_OTHER := $(filter-out $(TARGETS_SELF), $(MAKECMDGOALS)) | |
| # Call all targets using `Makefile` in build directory in one `make` command. It | |
| # can depend on targets defined in this file, e.g., depending on a target to | |
| # create the Makefile. | |
| # | |
| # If no targets are specified, use the dummy `all` target | |
| $(or $(lastword $(TARGETS_OTHER)),all): | |
| $(MAKE) -C build $(TARGETS_OTHER) | |
| .PHONY: $(TARGETS_OTHER) all | |
| # Do nothing for all targets but last. Also quiet the message "Noting to be done on xxx" | |
| $(filter-out $(lastword $(TARGETS_OTHER)), $(TARGETS_OTHER)): | |
| @cd . | |
| cmake: | |
| cd build && cmake ../src | |
| .PHONY: cmake |
Author
Very useful, thanks! Unfortunately it relies on GNU make features. Do you happen to know a version that achieves the same thing with BSD make?
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Say your Makefile is in
build, but you want to callmakein top directory without specifying-C