GNU Make Recursive Directory Listing - gnu-make

Is there a way to get the directory path and the paths of all the subdirectories recursively using GNU make without explicitly writing
dirpaths :=
dirpaths +=$(wlidcard L0dir/*)
dirpaths +=$(wlidcard L0dir/*/*)
and so on.
L0dir
├── L1subdir1
│ ├── L2subdir1
│ ├── L2subdir2
│ └── L2subdir3
├── L1subdir2
│ └── L2subdir1
├── L1subdir3
└── L1subdir4
The content of the variable $(dirpaths) should be :
L0dir L0dir/L1subdir1 L0dir/L1subdir1/L2subdir1 L0dir/L1subdir1/L2subdir2 L0dir/L1subdir1/L2subdir3 L0dir/L1subdir2 L0dir/L1subdir2/L2subdir1 L0dir/L1subdir3 L0dir/L1subdir4

You can use something like this:
recurse = $(foreach D,$1,$(wildcard $D/*) $(call recurse,$(patsubst %/.,%,$(wildcard $D/*/.))))
dirpaths := $(call recurse,$(DIR))

Related

Identify Folders in Sub-Folder

I have a working directory with the following content
readdir()
6-element Vector{String}:
"Manifest.toml"
"Project.toml"
"Report"
"main.jl"
"src"
"test.jl"
I can identify folders here:
filter(isdir, readdir())
2-element Vector{String}:
"Report"
"src"
And I can show the content of the sub-folder Report:
readdir("Report/")
3-element Vector{String}:
"jl_ACKKIu"
"jl_zfa8Ys"
"test.pdf"
So, why can I not identify folders in the sub-folder?
filter(isdir, readdir("Report/"))
String[]
readdir contains paths relative to the input directory and isdir then interprets these paths as relative to the current working directory (see pwd).
Since Julia 1.4 you can pass join=true as a keyword argument to readdir, such that the returned paths are joined with the input path:
shell> tree .
.
├── DirectoryB
│   ├── DirectoryC
│   └── FileB
└── FileA
2 directories, 2 files
julia> readdir("DirectoryB")
2-element Vector{String}:
"DirectoryC"
"FileB"
julia> readdir("DirectoryB"; join=true)
2-element Vector{String}:
"DirectoryB/DirectoryC"
"DirectoryB/FileB"
julia> filter(isdir, ans)
1-element Vector{String}:
"DirectoryB/DirectoryC"

Gpr file, do not include all directory in source

There is my project.gpr file :
project Test is
Project_Source_Dirs := ("Dir1")
& ("src")
& ("../../lib_all");
for Object_Dir is "lib";
for Main use ("Main_file.adb");
for Languages use ("Ada");
for Source_Dirs use Project_Source_Dirs & project'Object_Dir;
-- [...]
end Test;
There is my "../../lib_all" folder :
lib_all
|- file1.adb
|- file1.ads
|- file2.adb
|- file2.ads
|- file3.adb
|- file3.ads
|- file4.adb
|- file4.ads
I only want to use file3, how can I modify my .gpr file to not compile all other files each time ?
You can use Source_Files or Excluded_Source_Files settings, as described here: https://docs.adacore.com/gprbuild-docs/html/gprbuild_ug/gnat_project_manager.html#source-files-and-directories
But I think, the easier way could be simply moving unneeded files to separated directory and adding that directory with its content on demand (based on variables, etc.).

Create folder based on filename

I have a question how to create a new folder based on part of the filename and also move directly the corresponding files to the new folder. Below you will find the structure of my directory with some examples. In both D0 and D1 folders you will find Weather and Day folder that contains .TIF files. What I would like is that inside the brightfield and FITC folders folders are created that are based partially on the filename. For example if the file contains s2, then a folder S2 is created with the file that has S2 in his name.
Currently the situation
main Directory
|
|___ Experiment
├── D0
├── Weather
|__ D0_PM_flow__Weather 100 - CAM_s3_t5.TIF
|__ D0_PM_flow__Weather 100 - CAM_s3_t5.TIF
│ └── Temperature
└── D1
├── Weather
└── Temperature
What I would like:
main Directory
|
|___ Experiment
├── D0
├── Weather
|__ S1
| D0_PM_flow__Weather 100.txt
|__ S2
|D0_PM_flow__Weather 100.txt
│ └── Temperature
└── D1
├── Weather
└── Temperature
I can do this manually with the code below, but that takes a lot of time. Is there a more convenient way to do this more automatically? For convenience I only showed 3 files in the D0/Weather folder, but there are also files in the D0/Temperature folder, D1/Weather and D1/Temperature where I also want to create folders such as S1,S2 etc.. Furthermore, some folders have only three groups, so S1- S3, while other groups have S1- S6.
Recycling some code:
library(stringr)
#Get all files
path <- 'C:/temp/test'
files <- list.files(path= path, recursive = TRUE)
move.file <- function(filename) {
(fromdir <- dirname(filename))
(filebase <- basename(filename))
dir.match <- toupper(str_extract(filename,'_[Ss][0-9]+_'))
if (isTRUE(nchar(dir.match)>0)) {
dir.match <- substr(dir.match,2,nchar(dir.match)-1)
# File not in right directory
if (basename(fromdir)!=dir.match) {
dir.create(file.path(path,fromdir,dir.match),showWarnings = F)
file.rename(from = file.path(path,filename),
to = file.path(path,fromdir,dir.match,filebase))
}
} else {F}
}
lapply(files, move.file)

How to name a Sass file containing only #import statements

How should one name a Sass file that has the sole purpose of importing other Sass files?
Are there any rules or general "industry standards" that apply to this?
Let's suppose we have the following file structure:
sass/
|-- global/
| `-- file.sass
`-- vendor/
`-- bootstrap/
|-- variables.sass
`-- mixins.sass
and file.sass under global/ contains only
#import "../vendor/bootstrap/variables";
#import "../vendor/bootstrap/mixins";
How should file.sass be named?
Is it bootstrap.sass or bootstrap-loader.sass? Or something else?
I couldn't find any relevant post or documentation that addresses this matter except this Stack Overflow thread:
Sass #Import rules and naming which is somewhat similar but it doesn't cover my question.
Please support your answer with arguments / examples if possible.
The primary CSS/Sass file is usually called main.scss/main.css or style.scss/style.css.
Citing thesassyway.com here's how the structure looks like:
stylesheets/
|
|-- modules/ # Common modules
| |-- _all.scss # Include to get all modules
| |-- _utility.scss # Module name
| |-- _colors.scss # Etc...
| ...
|
|-- partials/ # Partials
| |-- _base.sass # imports for all mixins + global project variables
| |-- _buttons.scss # buttons
| |-- _figures.scss # figures
| |-- _grids.scss # grids
| |-- _typography.scss # typography
| |-- _reset.scss # reset
| ...
|
|-- vendor/ # CSS or Sass from other projects
| |-- _colorpicker.scss
| |-- _jquery.ui.core.scss
| ...
|
`-- main.scss # primary Sass file
In an enterprise-level project where multiple sub-projects are bundled you can name and divide your primary file into different files and name them after each project.
stylesheets/
|
|-- admin/ # Admin sub-project
| |-- modules/
| |-- partials/
| `-- _base.scss
|
|-- account/ # Account sub-project
| |-- modules/
| |-- partials/
| `-- _base.scss
|
|-- site/ # Site sub-project
| |-- modules/
| |-- partials/
| `-- _base.scss
|
|-- vendor/ # CSS or Sass from other projects
| |-- _colorpicker-1.1.scss
| |-- _jquery.ui.core-1.9.1.scss
| ...
|
|-- admin.scss # Primary stylesheets for each project
|-- account.scss
`-- site.scss
It would all depend on how you intend to compile your scss in the project, and how the workflow of the project works.
Typically you would use "Partial" scss files for anything that you don't want compiling separately.
A partial is simply a Sass file named with a leading underscore. You might name it something like _partial.scss. The underscore lets Sass know that the file is only a partial file and that it should not be generated into a CSS file. Sass partials are used with the #import directive. Source: https://sass-lang.com/guide
A basic typical workflow inside a project may look like the follow.. (Depending on how much scope the project has):
Src (Folder)
-- JS (Folder)
--Scss (Folder)
-- Components (Folder)
-- _button.scss
-- _animation.scss
-- Pages Folder
-- cms (Folder)
-- _about.scss
-- _contact.scss
-- _components.scss
-- _source.scss
-- default.scss
Inside _source.scss:
Import all cms page partials/other..
#import
'pages/cms/button',
'pages/cms/animation';
Note: You do not need to use an underscore before the file names in this import.
Inside _components.scss:
Import all partial component files.. (Same as source)
You would then import these into a file which you want to be compiled.. (No underscore file name):
default.scss:
#import
'components';
#import
'source';
I hope this answers your question.

Prevent unix tree from displaying back-slash before spaces

I use the command tree very often in command line (in Mac) and the tree structure of my current directory is listed as follows:
└── A\ File\ with\ Space.mp4
Is there an option to avoid displaying those back slashes?
My tree command has a -N option to print non printable chars as is.
tree -N
.
├── a dirname with spaces
└── myscript.sh
Otherwise, you could use printf and xargs:
tree | xargs -L 1 -I xxxx printf "%s\n" xxxx
.
├── a dirname with spaces
└── myscript.sh
Special chars in names are going to break it or display surprising result: \n ' " * etc.

Resources