I'm exploring ways to improve code module integration and have found interest in using named soft links as opposed to include directories, mainly because that allows the integrator to set a directory name of any imported module to something guaranteed not to collide with the module built or any of its imported modules, as well as keeping imported modules from accidently intercepting eachother. However I'm not sure how to actually accomplish this in a makefile.
Here is the directory hierarchy and expected links:
+---proj1
| +---inc
| | head.h
| |
| \---src
| code.c
|
+---proj2
| +---inc
| | head.h
| |
| \---src
| code.c
|
\---proj3
| Makefile
|
\---src
| code.c
| head.h
|
+---A --> ../../proj1/inc
| head.h
|
\---B --> ../../proj2/inc
head.h
In proj3/src/code.c i would have:
#include "head.h"
#include "A/head.h"
#include "B/head.h"
I think I need some way to run ln -s for each {directory,name} tuple prior to compiling the source, putting the link in the same directory as the source being compiled. Parsing INC=dir1 dir2 is simple enough, but how to represent and run ln -s for each pair/tuple in such a list? Or, if having a whole command in each element (ln -s dir1 localname), how to exec all of them?
Other suggestions would be deeply appreciated.
Something like this?
linkdirs := A B
dir_A := ../proj1/src
dir_B := ../proj2/src
.PHONY: all symlinks
all: symlinks hello
symlinks:
$(eval $(patsubst %,ln -fs $$(dir_%) % &&,$(linkdirs)) true
Related
I have directories structure like,
|
|
------------------------------------
| |
directory 1 directory 2
| |
------------- -------------
| | | |
directory 1.1 directory 1.2 Makefile directory 2.1
|
file.c
In above hierarchy, How to compile file.c using Makefile(resides in directory 2)?
I am trying to find the all the paths in a pattern and I am stuck. This is the structure of the directory
testdir
|-- dir with spaces
| |-- subdir
| | |
| | |-subfile.sh
| |
| +-- 1.sh
| |
| +-- 2.sh
|
+-- dir1
| |
| |
| +-- file.sh
|
+-- test.sh
this is the path pattern i have testdir/**/*
What i want
The output i am trying to get is
-flag testdir/dir\ with\ spaces/1.sh
-flag testdir/dir\ with\ spaces/2.sh
-flag testdir/dir\ with\ spaces/subdir
-flag testdir/dir\ with\ spaces/subdir/subfile.sh
-flag testdir/dir1
-flag testdir/dir1/file.sh
-flag testdir/test.sh
What i tried
pathpattern=testdir/**/*
echo $pathpattern
It prints the following
testdir/dir with spaces/1.sh testdir/dir with spaces/2.sh testdir/dir with spaces/subdir testdir/dir1/file.sh
I tried doing an echo of the path pattern but it didn't return everything.
I also dont know to handle entries that have a space. I tried looping through $pathpattern, but failed to differentiate between a new path and a path that has a space.
This should do it.
printf -- "-flag %q\n" testdir/**/*
However, this looks like probably a very poor way to accomplish ... something. Without knowledge of the actual end goal, it's hard to suggest how to do it properly. Typically, you don't want to produce a variable or string containing file names (let alone commands) and if you do, you shoud probably be using an array instead. But perhaps you simply want
for file in testdir/**/*; do
: ... something with "$file"
done
The array solution would look something like
#!/bin/bash
# ^ sh doesn't have arrays
array=($(printf " -test %q" testdir/**/*))
your --program --call ${array[#]} --more arguments
hi i have a requirement like the following
|
|------bar/
|--file.pl
|---FILE1.FILE2.FILE3.TXT
|---FILE4.FILE5.FILE6.TXT
|
|---subdir1/
| |---file1_file2.log
| |---file2_file1.log
|
|---subdir2/
|---image1_image2.log
|---image2_image1.log
i am using the following command.
tar cvzf bar/ x.tar
and the output i am getting is as follows
|
|------bar/
|--file.pl
|---FILE1.FILE2.FILE3.TXT
|---FILE4.FILE5.FILE6.TXT
|
|---subdir1/
| |---file1_file2.log
| |---file2_file1.log
|
|---subdir2/
|---image1_image2.log
|---image2_image1.log
but i want the output like the following.i want to exclude .pl and i want only x.x.x.TXT and .LOG to be tar.
|
|------bar/
|
|---FILE1.FILE2.FILE3.TXT
|---FILE4.FILE5.FILE6.TXT
|
|---subdir1/
| |---file1_file2.log
| |---file2_file1.log
|
|---subdir2/
|---image1_image2.log
|---image2_image1.log
thanks in advance.
$ tar cvzf x.tar bar/ --exclude=*.pl
From man page:
--exclude=PATTERN
exclude files, given as a PATTERN
Try this.
find ./someDir -name "*.log" -o -name "*.TXT" | tar -cf my_archive -T -
Hi all I'm a bit stuck with a process that on the surface seems like it should be pretty simple, but I'm finding it challenging. It has been a while since I have done much bash scripting so perhaps I'm just rusty.
I am trying to traverse a directory tree and sort files into different subdirectories based on their extension. In each subdirectory I have a series of image files and I want to move all of the files that have the .RAW extension into a new subdir named RAW (create it if it doesn't exist) and leave the remaining files where they are. Oh yeah, and some of the folder and file names contain spaces just to make life more interesting.
The basic operations:
Loop over subdirectories
In each subdir
Check to see if files with the extension .RAW are there
If yes then create a new directory named RAW and move all of the matching files into there
Here is an example to clarify
Dir1
|--subdir 1
| |--file1.jpg
| |--file2.jpg
| |--file3.RAW
| |--file4.RAW
|
|--subdir 2
| |--file1.jpg
| |--file2.jpg
| |--file3.RAW
| |--file4.RAW
The result I want is:
Dir1
|--subdir 1
| |--RAW
| | |--file3.RAW
| | |--file4.RAW
| |
| |--file1.jpg
| |--file2.jpg
|
|--subdir 2
| |--RAW
| | |--file3.RAW
| | |--file4.RAW
| |
| |--file1.jpg
| |--file2.jpg
I started out trying to use a loop like
for dir in */ do cd $dir; mkdir RAW; for files in *.RAW do mv $files ./RAW; done; done
That's not quite what i want though and it doesn't play nicely with spaces in names.
I have played around a bit with find, but can't seem to get that to work. I feel I'm missing an elegant solution here. Any suggestions?
Try this command:
#!/bin/bash
find Dir1 -mindepth 1 -type f -name '*.RAW' | while read -r FILE; do
DIRNAME=${FILE%/*}
mkdir -p "$DIRNAME/RAW" && mv "$FILE" "$DIRNAME/RAW/"
done
I am trying to write a script (preferably in bash) to flatten a java projet directory structure prepending the path to the file. Example:
| src
| org
| apache
| file2.java
| file1.java
would result in:
| src
| org|apache|file2.java
| org|file1.java
The script should be recursive since the directory could have many subfolders.
cd src
for i in $(find . - name '*.java') ; do
echo cp \"$i\" $(echo "$i" | tr / _)
done
if it looks good(might barf if filenames contains spaces), pipe the result to sh