makefile convert $(SOURCES) to $(OBJECTS) - path

i have a list of paths to sources in subfolders of /source in $(SOURCES). Paths are like this:
$(SOURCES)=
source/main.cpp
source/subfolder/code.cpp
....
how can i convert all of 'em in this format?
$(OBJECTS)=
obj/main.o
obj/code.o
....
or at least how to automatically create all the missing folders in obj/ and change "source" to "obj" in paths?

Related

CPPCheck: Ignore dirs and all sub dirs from analyses?

I have read the manual at https://cppcheck.sourceforge.io/manual.pdf and have found that I can use -i to ignore a directory. However, in my testing it doesn't seem to ignore the whole subdir. Example, I have a library that has a very long directory path (this is simplified) but I want to ignore everything under the top level
Root
> Lib
>> Lib dir 1
>>> file.c
>> Lib dir 2
>>> file.c
The wording
To ignore certain folders you can use -i. This will skip analysis of source files in
the foo folder.
cppcheck --project=compile_commands.json -ifoo
Suggests that it will skip any files in the specified dir, not any subdirs.
Is there a way to skip the dir and all sub dirs?
The way I had to achieve this was generating a compile_commands.json from cmake then write a python script to exclude anything that matched the filter I wanted to exclude, eg /libA/ will exclude anything under libA

Dockerignore: allow to add only specific extension like *.json from any subfolder

I have a .dockerignore file and I'm trying to allow Docker to upload only *.json files but from any of subfolders.
For example, for the next files structure:
public/readme.md
public/subfolder/a.json
public/subfolder/b.json
public/other/c.json
public/other/file.txt
I'm expecting to see only json files in the image:
public/subfolder/a.json
public/subfolder/b.json
public/other/c.json
Of course they must be located in the same directories as in original source.
I tried several ways but didn't succeed.
UP: I don't know how many subfolders will be created in the public/ directory and how deep will be the directories structure.
I think you can achieve what you want by relying on one such .dockerignore:
public/*
!public/subfolder
public/subfolder/*
!public/other
public/other/*
!**/*.json
The tricky thing is that the first line of this file is public/* but not public nor * (otherwise the !... subsequent lines won't work).
Note also that you may want to automate the generation of one such .dockerignore, to cope with possible tree structure changes.
For example:
gen-dockerignore.sh
#!/usr/bin/env bash
{ echo '*' ; # header of the .dockerignore - to be changed if need be
find public -type d -exec echo -en "!{}\n{}/*\n" \; ;
echo '!**/*.json' ; } > .dockerignore
$ ./gen-dockerignore.sh would output the following file:
.dockerignore
*
!public
public/*
!public/other
public/other/*
!public/subfolder
public/subfolder/*
!**/*.json

tar: unable to include folder but exclude content

I have a project folder with several directories
- archive
- include
- lib
- src
- src/obj (obj is a subdirectory of src)
I would like tar to pack these directories and their contents into a main.tar, then I will the main.tar into the archive directory.
tar cvz \
--exclude="*.obsolete" --exclude="*DS_Store" --exclude="./archive/*" \
-f main.tar \
./archive ./include ./lib ./src
I would like to exclude the contents of the archive directory but still package the empty directory itself. You can see I am also excluding some other stuff from various places, OSX likes to write .DS_Store files everywhere on my filesystem and I occasionally make copies of files and append .obsolete to the end while working on a new version.
Unfortunately, the empty archive directory is not included in main.tar.
According to this thread, my command should work.
How can the files be excluded from archive but the empty directory be packed into the tar file?
edit
The following fails:
--exclude="./archive/*"
The following works:
--exclude="./archive/*.*"
So the whole command is:
tar cvz \
--exclude="*.obsolete" --exclude="*DS_Store" --exclude="./archive/*.*" \
-f main.tar \
./archive ./include ./lib ./src

Tar does not exclude

I use
tar hczf t.tar.gz * --exclude="./test1"
where test1 is the name of a directory to exclude files from being tarred.
Unfortunately, tar still includes those directories. How can I have tar exclude directories?
The * that specifics "all files in the current directory" should be the last item on your cmd-line
tar --exclude="./test1" hczf t.tar.gz *
#--------------------------^-> tarFileName
#------------------------->f (for file)
This illustrates why the --excl... can't go inbetween hczf t.tar.gz.
The f option expects a filename right after it. So we have moved --excl... to the first option.
IHTH

tar --excludes option to exclude only the directory at current working directory, not subdirectories

I want to tar/zip a directory ./ (current working directory) and exclude files in the directory ./vendor, I happened to also have a subdirectory named vendor at ./public/web/vendor, but I want to keep that. I've tried:
tar cfz /private/var/folders/temp/mage6BRQWJ.tar.gz --exclude=vendor/* ./
tar cfz /private/var/folders/temp/mage6BRQWJ.tar.gz --exclude=./vendor/* ./
tar cfz /private/var/folders/temp/mage6BRQWJ.tar.gz --exclude="vendor/*" ./
But these both exclude the subdirectory.
I want to use relative path because I want to exclude all .svn (e.g. example) files from all directories, too.
Is there a way, using relative path , to exclude files in the ./vendor directory but not ./public/web/vendor ?
All you need is the --anchored tag:
GNU tar:
tar cfz mage6BRQWJ.tar.gz --anchored --exclude=vendor *
bsdtar:
bsdtar -czf mage6BRQWJ-1.tar.gz --exclude=^vendor *
That works.

Resources