I know how to change the file-extensions:
JS_MINIFIED = $(patsubst %.js,%-min.js,$(JS_FILES))
or
JS_MINIFIED = $(JS_FILES:.js=-min.js)
But what if I want to change the actual folder. e.g. dump everything in a "temp" folder?
I don't quite know what you mean. Do you mean that for every file in JS_FILES, regardless of its path, you want to put it into "temp"? So "foo/bar/biz.js" goes to "temp/biz.js", and "one/two/three.js" goes to "temp/three.js"? Then maybe:
JS_MINIFIED = $(addprefix temp/,$(notdir $(JS_FILES)))
Or do you want to preserve the same structure but prefix it with "temp"? So "foo/bar/biz.js" goes to "temp/foo/bar/biz.js", and "one/two/three.js" goes to "temp/one/two/three.js"? Then just:
JS_MINIFIED = $(addprefix temp/,$(JS_FILES))
Related
I have written a makefile which has pretty complicated dependency, and executes with multiple jobs in parallel (make -j100 for example). I am trying to find a way to print all the current running target names. Any idea? Thanks in advance.
If what you want is a kind of command that you can run from time to time while make is running, and that shows all currently executing recipes, you could slightly modify your recipes such that they first create a temporary file with the name of the target, do whatever they are supposed to do and delete the temporary file. Listing these temporary files anytime will then show you the currently executing recipes.
Example if all targets are located under the directory from which make is called (or sub-directories of it):
TAGSDIR := .tags
MKTAG = mkdir -p "$(TAGSDIR)/$(#D)" && touch "$(TAGSDIR)/$#"
RMTAG = rm -f "$(TAGSDIR)/$#"
<target>: <prerequisites>
#$(MKTAG)
<regular recipe>
#$(RMTAG)
And list all files under .tags to get the names of all currently running recipes. Example with find:
find .tags -type f -printf '%P\n'
You could even encapsulate this in an infinite loop and refresh the list e.g. every second:
while true; do clear; find -type f -printf '%P\n'; sleep 1; done
EDIT
Andreas noticed that this works only if the targets are all located under the directory from which make is called. If a target is ../foobar, for instance, the temporary tag file would be .tags/../foobar, which is not what we want.
Andreas suggests to substitute .. with \.\. and / with \/. We could maybe find a way to do something like this under GNU/Linux and macOS (but not exactly, you cannot have a slash in a file name) but there could still be other issues under Windows (C:, backslashes...).
We could also store the name of the target in a text file and use mktemp or an equivalent to generate the text file with a unique name. But we would then need a way to propagate this unique name from MKTAG to RMTAG. This is doable with a shell variable and a one-line recipe (or the .ONESHELL special target) but not very nice.
As you use GNU make we could also use abspath and create temporary files named $(TAGSDIR)/$(abspath $#) but I do not know what abspath does under Windows with drive letters, nor do I know if you can name a file something\c:\something under Windows...
So, if your targets are not all located under the directory from which make is called, the best is to use another solution.
I want to write a make file to compile my source code. I have to put in my make file the includes paths but i have a lot of folders with source codes.
In make file i have a list with all .c files like this :
__MDA_SRC = \
$(__VIEWPATH)\f_03\test\mda\src\mda.c
now i need to find out the path of this file.
I tried this one :
__PATHS_FEATURE = \
$(dir $(__MDA_SRC ))
__INCLUDE_PATHES := \
-I$(__PATHS_FEATURE)
but i have an error F100: cannot open ...bla bla..
i supposed that the problem is on the path, because the path is extructed with the last backslash like:
..\..\..\..\..\f_03\test\mda\src\
How could i have the path without the last backslash like this :
..\..\..\..\..\f_02\hydraulic\btc\src
That seems unlikely to be the problem to me but you can remove it with
$(__PATHS_FEATURE:\=)
or
$(patsubst %\,%,$(__PATHS_FEATURE))
This may not work for your problem since your path is not absolute, however the 'abspath' and 'realpath' indirectly do what you are looking for. 'realpath' will remove the last forward slash as well as any . .. or repeated /
pathwslash=/dirs/and/more/dirs/
path=$(realpath $(pathwslash))
echo $(path) # /dirs/and/more/dirs
Here is some documentation for some other functions that may be helpful: https://www.gnu.org/software/make/manual/html_node/File-Name-Functions.html
I have a directory which internal contains sub directories. I want to include the parent directory as include path in make file for header files. Is there a syntax so that all the sub directories are searched for the header files.
[EDIT] Posting the question in more detail
There are three sub folders in a parent folder
parentFolder/child1
parentFolder/child2
parentFolder/child3
There are header files in each all subfolders
Using -I option in makefile for header file path, i have to use
HEADER_PATH += -I./parentFolder
HEADER_PATH += -I./parentFolder/child1
HEADER_PATH += -I./parentFolder/child2
HEADER_PATH += -I./parentFolder/child3
Is there any way I can mention only the parent folder , but the search for header files will happen in all the subfolders also
http://www.gnu.org/software/make/manual/html_node/Recursion.html
Setup variable in first makefile and export it for sub-dirs. If you want to be able to invoke make in subdirs manually - i suppose best way to achieve this is either using configure-like systems to generate paths for you, or setting global variable (e.g. YOURPROJECT_DIR) in .profile or .bashrc and using it in makefiles.
I would like to see better solutions since i've encountered quite the same problem some time ago.
I have a series of images saved in a folder, and I have written a short program to open two of these image files, concatenate them (preferably vertically, although for now I am trying horizontally), then save this new image to the same folder. This is what I have written so far:
function concatentateImages
%this is the folder where the original images are located path='/home/packremote/SharedDocuments/Amina/zEXAMPLE/';
file1 = strcat(cr45e__ch_21', '.pdf');
[image1,map1] = imread(graph1);
file2 = strcat('cr45f__ch_24', '.jpg');
[image2,map2] = imread(graph2);
image1 = ind2rgb(image1,map1);
image2 = ind2rgb(image2,map2);
image3 = cat(2,image1,image2);
%this is the directory where I want to save the new images
dircase=('/home/packremote/SharedDocuments/Amina/zEXAMPLE/');
nombrejpg=strcat(dircase, 'test', jpgext)
saveas(f, nombrejpg, 'jpg')
fclose('all');
However, I keep getting an error that my files do not exist, though I am certain the names are copied correctly.
I am currently using jpg files, but the format can be easily converted.
Any input on how to fix this error, or a nicer way of preforming this task is greatly appreciated!
Cheers,
Amina
Replace
[image1,map1] = imread(graph1);
and
[image2,map2] = imread(graph2);
by
[image1,map1] = imread(file1);
and
[image2,map2] = imread(file2);
Also check that you are in the right working directory.
In addition to the answer by #Simon, you also need to change
file1 = strcat(cr45e__ch_21', '.pdf');
to
file1 = strcat('cr45e__ch_21', '.pdf');
I.e. you forgot a '. Also your function doesn't seem to include a definition of jpgext. I expect you want a line like
jpgext = '.jpg';
Lastly, mostly a coding practice issue, but you might want to switch to using fullfile to build your full file path.
Also, instead of worrying about being in the correct working directory, if you use full paths you save yourself from having to keep track of what directory you're in.
SO I would suggest:
dir1 ='/home/packremote/SharedDocuments/Amina/zEXAMPLE/';
file1 = fullfile(dir1, 'cr45e__ch_21.pdf');
etc
Is there any way to say that if prerequisite for the given target doesn't exist then ignore that target?
For instance, I have the following set of folders
chrome_src_folders := $(chrome_src_folder)/content/* \
$(chrome_src_folder)/locale/* $(chrome_src_folder)/skin/*
This is where I use it
$(jar_path): $(chrome_src_folders)
zip -urq $(jar_path) $(chrome_src_folders)
Basically skin or locale may very well not be there, which will give me a nice error.
How to avoid that error and make the chrome_src_folders mandatory? or should I filter somehow chrome_src_folders and leave only those which exist?
There's more than one way to do this; the simplest is to filter the list using wildcard
chrome_src_folders := $(wildcard $(chrome_src_folder)/content/* \
$(chrome_src_folder)/locale/* $(chrome_src_folder)/skin/*)
Two thoughts; Since the skin and locale folders are optional, do you need to call them about as dependencies? Let the build commands take care of them if they need to. So something like:
chrome_content_folder := $(chrome_src_folder)/content/*
chrome_content_optional := $(chrome_src_folder)/locale/* $(chrome_src_folder)/skin/*
$(jar_path): $(chrome_content_folder)
zip -urq $(jar_path) $(chrome_content_folder) $(chrome_content_optional)
If you have to have the right folders on the dependency line, so you catch errors, I would write some macros that define when and how you require them. Then update your targets accordingly to only require those directories when you know they are required.