I'm working on a project with a few directories with my makefile one level above all of them. When I update and of the code/header files and re-make, it says 'Nothing to be done for 'all''. Is there a way to force make to check all of the directories and therefore realise that some components have to be remade? Cheers
Jack
You could forcibly enter the sub-directories each time:
SUBDIRS = dir1 dir2
.PHONY: all
all: subdirs final_target
.PHONY: subdirs
subdirs:
for d in $(SUBDIRS); do $(MAKE) -C $$d; done
.PHONY: final_target
final_target:
echo "Do something here..."
This scheme, to enter all sub-directories, are actually very common.
Related
I have several projects in a directory and I want to write a Makefile to build any subset or all of these projects. Each project is in a folder named after itself, which contains a Makefile.
How do I execute these Makefiles?
Here is what I tried:
# Define the project names
PROJECT_NAMES := \
Project_1 \
Project_2 \
Project_3
# Define default behaviour
default: all
# Rule to build all projects
all:
$(foreach project, $(PROJECT_NAMES), $(CURRENT_PROJECT))
# Rule to build single project
.PHONY $(CURRENT_PROJECT)
$(CURRENT_PROJECT):
$(MAKE) -C $(CURRENT_PROJECT) make
I think this question might have gone for something similar, but it was not answered:
How to make a Makefile call another Makefile rules?
Instead of passing arguments, prerequisites/dependencies should be used. Here is how I solved it:
# Define the project names
PROJECT_NAMES := \
Project_1 \
Project_2 \
Project_3
# Define default behaviour
default: all
# Rule to build all projects now depends on building individual projects
all: $(foreach project, $(PROJECT_NAMES), $(project)_build)
# Rule to build a single project
.PHONY: Project_%
Project_%:
#echo "****** Building $(subst _build,,$#) ******"
#$(MAKE) -C $(subst _build,,$#) all
When called without parameters, all projects are built. Any combination of individual projects can be built by simply passing the project names to the makefile such as:
make Project_1 Project_3
I am doing a project which is growing pretty fast and manually compiles the project is getting to much work. Therefore i want a makefile to automize this process. I makefile should only compile all the files from the src directory (and all those files in subfolders).
Project directory is as follows:
-src
--files.cpp
--files.h
--|-dirA
---|-aa.cpp
---|-aa.h
---|-ab.cpp
---|-ab.h
--|-dirB
---|-ba.cpp
---|-ba.h
---|-bb.cpp
---|-bb.h
and a main.cpp in the root directory
So far my makefile gets all the cpp files from the src folder:
SRC_DIR ?= ./src
OBJ_DIR := ./obj
SRC_FILES := $(shell find $(SRC_DIRS) -name '*.cpp')
I'm not sure how to continue from this.
I am new to CDT and I am trying to generate the makefile automatically. I notice that it include three files that doesn't exist at all, makefile.init, makefile.defs, makefile.targets.
Just wondering, what do they do? and why are they there?
################################################################################
# Automatically-generated file. Do not edit!
################################################################################
-include ../makefile.init
RM := rm -rf
# All of the sources participating in the build are defined here
-include sources.mk
-include subdir.mk
-include objects.mk
#Other codes
-include ../makefile.defs
# Add inputs and outputs from these tool invocations to the build variables
#Other codes
-include ../makefile.targets
The three includes are intended for your sake.
If you need to compile something proprietary manually, or copy files or anything you can come up with before the main program is compiled, you create the file makefile.init in the source directory and put your makefile-stuff in here.
The same applies to the other files just at other times in the compile chain.
Given this Makefile snippet:
TARGETS = ${SHARED_LIB_A} ${SHARED_LIB_B}
.PHONY: subdirs $(SUBDIRS)
subdirs: $(SUBDIRS)
$(SUBDIRS):
$(MAKE) -C $#
all: $(TARGETS)
I want to modify this Makefile so that TARGETS get built after the PHONY target is run. Ie. TARGETS depends on the code in SUBDIRS being built - TARGETS needs to be run after SUBDIRS. Right now the way this works is that the PHONY target gets run (the subdirs are built), but not the all target (unless I specifically run it like 'make all' - but I want to avoid doing that if possible, I just want to run 'make' and have it build the subdirectories and then build TARGETS.
First, you should have all as the first rule, not the last one. Unless you specify a specific target on the make command line, it will run the first target in the makefile (here, subdirs).
Second, you should declare subdirs as a prerequisite of $(TARGETS); that will ensure that they are not built until after subdirs is complete:
all: $(TARGETS)
$(TARGETS): subdirs
Now, because subdirs is PHONY it means that $(TARGETS) will always be considered out of date and always be built, even if invoking subdirs didn't change any files. However, there's no other alternative as you've written your makefile here, because make cannot know what files (created by the submakes) you want to use to see if the library is out of date.
Alternatively you can specify that subdirs is an order-only prerequisite:
$(TARGETS): | subdirs
I have a program that draws the Earth and it uses the following code to read the texture file:
Images::RGBImage surfaceImage;
surfaceImage=Images::readImageFile("",Vrui::openFile("/home/rodrtu/Desktop/SolarSystem/land_shallow_topo_2048.png"));`
The way I have it set up it only works on my desktop, but I want other people to have access to my program files and pictures, and be able to get the program working on their computer. What should I use instead of using "/home/rodrtu/Desktop/SolarSystem/land_shallow_topo_2048.png"
If I add a folder to the same place as my .cpp file, should I make changes to my makefile?
Here is my makefile
VRUI_MAKEDIR := /opt/local/Vrui-2.6/share/make
ifdef DEBUG
VRUI_MAKEDIR := $(VRUI_MAKEDIR)/debug
endif
INSTALLDIR := $(shell pwd)
# Set resource directory: I added this images folder to the same place as my
# .cpp file, but it still doesn't work
RESOURCEDIR = images
########################################################################
########################################################################
# Include definitions for the system environment and system-provided
# packages
include $(VRUI_MAKEDIR)/SystemDefinitions
include $(VRUI_MAKEDIR)/Packages.System
include $(VRUI_MAKEDIR)/Configuration.Vrui
include $(VRUI_MAKEDIR)/Packages.Vrui
# Set installation directory structure:
BININSTALLDIR = $(INSTALLDIR)/$(EXEDIR)
RESOURCEINSTALLDIR = $(INSTALLDIR)/$(RESOURCEDIR)
########################################################################
########################################################################
PACKAGES = MYVRUI
########################################################################
########################################################################
ALL = $(EXEDIR)/NewPlanet
.PHONY: all
all: $(ALL)
########################################################################
#'make clean'
########################################################################
.PHONY: extraclean
extraclean:
.PHONY: extrasqueakyclean
extrasqueakyclean:
# Include basic makefile
include $(VRUI_MAKEDIR)/BasicMakefile
########################################################################
########################################################################
$(EXEDIR)/NewPlanet: $(OBJDIR)/NewPlanet.o $(OBJDIR)/drawShape.o
You should use relative path like Beta suggested. Put a "data" folder on the same folder than your executable and use :
Vrui::openFile("./data/land_shallow_topo_2048.png")
File opening should be relative to the program directory, so you could create a sub directory inside your source dir for pictures. Make sure to let the user know where to place these pictures however,
g-dev#g$ mkdir dat
g-dev#g$ mv pic.jpg dat/pic.jpg
then in source:
::readImageFile("", Vrui::openFile("pic.jpg")
adding the directory in CMake:
include_directories ("${PROJECT_SOURCE_DIR/dat}")
adding the directory in VS:
here
(make sure you're using provided MSVS macros for your file path $(ProjectDir) or $(SolutionDir) )