Include path in makefile to include subdirectories - makefile

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.

Related

knit Rmarkdown moderncv to pdf using makefile with sty file in subdirectory

I am using the moderncv class to create a CV in Rmarkdown. In order to make the cv reproducible out of the box I have included the .cls and .sty files in the root directory. However, in an effort to keep the root directory uncluttered I would prefer to keep all the moderncv related files in a subdirectory (assets/tex/). I am able to access the .cls file using a relative path in the yaml front matter, but I am not able to access the .sty files unless they are in the root directory.
Searching previous questions on stackoverflow I learned the following: (1) keeping .cls and .sty files in nested directories is not recommended. I understand this and would like to do it anyway so that other people can fork my project and be able to knit the cv without having to deal with finding their texmk folder. (2) the solution to my problem seems to involve setting the TEXINPUTS using a Makefile (see this thread and another thread)
I am not very good with Makefiles, but I have managed to get one working that will knit my .Rmd file to pdf without problems, so long as the .sty files are still in root. This is what it looks like currently:
PDF_FILE=my_cv.pdf
all : $(PDF_FILE)
echo All files are now up to date
clean :
rm -f $(PDF_FILE)
%.pdf : %.Rmd
Rscript -e 'rmarkdown::render("$<")'
My understanding is that I can set the TEXINPUTS using:
export TEXINPUTS=".:./assets/tex:"
Where "assets/tex" represents the subdirectory where the .sty files are located. I do not know how to incorporate the above code into my makefile so that the .sty files are recognized in the subdirectories and my .Rmd is knit to PDF. In its current state, I get the following error if I remove the .sty files from root and put then in the aforementioned subdirectory:
! LaTeX Error: Command \fax already defined.
Or name \end... illegal, see p.192 of the manual.
which I assume is occurring because the moderncv class needs---and cannot locate---the relevant .sty files.
You could try to define the environment variable in the make rule:
%.pdf : %.Rmd
export TEXINPUTS=".:./assets/tex:"
Rscript -e 'rmarkdown::render("$<")'
Or you could set the environment variable in a set-up chunk in your Rmd file:
```{r setup, include = FALSE}
Sys.setenv(TEXINPUTS=".:./assets/tex:")
```
Note: Not tested due to lack of minimal example.

How to include a directory of files with RST and Sphinx

I am trying to write documentation and want and have multiply files used by multiple toc trees. Previously I used an empty file with .. include:: <isonum.txt> however, this does not work for multiply files in a directory with sub directories. Another solution I have used was to use a relative file path to the index file I am linking to. However this messes up the sphinx nav tree. So my question is how to include a directory of files with RST and Sphinx?
It can't be done, unfortunately.
The toctree directive has a glob option, which you would use like so:
.. toctree::
:glob:
generated/*
But this option is not available in the include directive.
Maybe start an issue for it?
Perhaps indicate the start and end of the section where the files should go with a comment (.. START_GLOB_INCLUDE etc), and then have a build pre-process step that finds the files you want and rewrites that section of the master file.

gitignore file pattern not working

I have dynamic directory structure like,
dependency
a
b
c
d e
f
g
h
I want to ignore all files under dependency folder recursively except .xml files.
I am using below pattern to achieve the same.
dependencies/**
!dependencies/**/*.xml
But it seems it's not working for me. It's ignoring all the files but accepting only .xml files which are directly inside the dependency folder, not recursively. :(
I am using below environment.
OS : Windows 7(64 bit)
Git : 2.6.1.windows.1
Can anyone help me?
This should work:
You ignore everything but white-list the parent folders.
Then you can white-list files.
dependencies
!dependencies/**/
!dependencies/**/*.xml
As I mentioned in "How do I add files without dots in them (all extension-less files) to the gitignore file?", there is mainly one rule to remember with .gitignore:
It is not possible to re-include a file if a parent directory of that file is excluded.
That means, when you exclude everything ('*'), you have to white-list folders, before being able to white-list files.
Check if this is working with git check-ignore -v -- afile to see if it is ignored (and by which rule) or not.

How to get QMake to copy large data files only if they are updated

I have some large data files that need to be copied from source folders to build folders during our Qmake/QtCreator build. Since they are large, I only want the copy to happen for new/changed files. And I'd really like to avoid listing them all specifically in the project file. Here's what I've tried:
This attempt at copying data files fails because the DemoData folder is the target. Therefore the copy is not performed if files within the folder are added or changed. Only if the folder does not exist.
DemoData.commands = $$COPY_CMD $${SRC_DATA_DIR}DemoData $${BLD_DATA_DIR}DemoData
DemoData.target += $${BLD_DATA_DIR}DemoData
PRE_TARGETDEPS += $${BLD_DATA_DIR}DemoData
QMAKE_EXTRA_TARGETS += DemoData
This approach fails because the DemoData.target item is not expected to have a list of multiple items. QMake puts the list in quotes in the generated makefile so it becomes one target.
DemoData.commands = $$COPY_CMD $${SRC_DATA_DIR}DemoData $${BLD_DATA_DIR}DemoData
DEMO_DATA_FILES = $$files($${SRC_DATA_DIR}DemoData/*)
for(FILE, DEMO_DATA_FILES){
DemoData.target += $${BLD_DATA_DIR}DemoData\\$$basename(FILE)
PRE_TARGETDEPS += $${BLD_DATA_DIR}DemoData\\$$basename(FILE)
}
QMAKE_EXTRA_TARGETS += DemoData
This attempt fails because (AFAICT) QMake does not support variable names contained in other variables. It seems to be more of a one level substitution. A makefile is generated, but the DemoDataX targets all have no command lines. All attempts to display the contents of the 'commands' field generate syntax errors.
DEMO_DATA_FILES = $$files($${SRC_DATA_DIR}DemoData/*)
DEMO_DATA_NAME = DemoData
for(FILE, DEMO_DATA_FILES){
$${DEMO_DATA_NAME}.target = $${FILE}
$${DEMO_DATA_NAME}.commands = $$COPY_CMD $${FILE} $${BLD_DATA_DIR}DemoData
PRE_TARGETDEPS += $${FILE}
QMAKE_EXTRA_TARGETS += $${DEMO_DATA_NAME}
DEMO_DATA_NAME = $${DEMO_DATA_NAME}X
}
This approach works, but with two shortcomings. The minor one is that a separate 'make install' step must be performed. The major one is that the files are always copied unconditionally. Since our data files are large, this is unacceptable timewise.
DemoData.path = $${BLD_DATA_DIR}DemoData
DemoData.files = $${SRC_DATA_DIR}DemoData/*
INSTALLS += DemoData
Is there a way to do this, or am I left with some sort of external script or manually generated/maintained makefile?
Use QMAKE_EXTRA_COMPILES feature.
# list your files in this variable.
# Masks are available with $$files functions but
# if your set of files changes (files added or removed)
# your have to re-run qmake after that explicitly, not just make
MYFILES = $$files($${PWD}/files/*.*)
copy_files.name = copy large files
copy_files.input = MYFILES
# change datafiles to a directory you want to put the files to
copy_files.output = $${OUT_PWD}/datafiles/${QMAKE_FILE_BASE}${QMAKE_FILE_EXT}
copy_files.commands = ${COPY_FILE} ${QMAKE_FILE_IN} ${QMAKE_FILE_OUT}
copy_files.CONFIG += no_link target_predeps
QMAKE_EXTRA_COMPILERS += copy_files
Add your big files to MYFILES variable. For each file a rule will be generated in Makefile that copies file to specified directory (datafiles in the example). Original file will be listed as a dependecy in the rule (this is default qmake behaviour) so copy will occur only when original file is fresher than existing copy. Generated rules are listed as dependencies in the target file rule (copy_files.CONFIG += target_predeps) so copying will occur on every build automatically.
The only caveat is this: if your set of files is dynamic (files are added or removed) you can use masks as in my example but you have to be careful to execute qmake after changing the set. Be aware that Qt Creator builds projects by launching make, not qmake. The most simple way to ensure that qmake will be launched is to modify .pro file.
For those who can read Russian there is more info about QMAKE_EXTRA_COMPILERS here
Do you need the script to be cross platform? I personally wouldn't use the copy command, but robocopy on Windows and rsync on Mac/Linux.
win32: $${DEMO_DATA_NAME}.commands = robocopy $${SRC_DIR} $${DST_DIR} $${FILE} /MIR /XO
!win32: $${DEMO_DATA_NAME}.commands = rsync -aru $${FILE} $${BLD_DATA_DIR}
I'm not really sure what you want to copy here, but you get the idea, you can adapt the files and/or directories.
Robocopy parameters are described here.
/MIR Mirrors a directory tree
/XO Excludes older files.
Rsync parameters are described here.
-a Archive
-r Recursive
-u Update only when the source is newer
As a side note if you don't want to run this make install command, you can set this extra target as a dependency to the project that needs these files: theProjectNeedingThoseFiles.depends += DemoData.

How to specify relative paths in .vsprops file

Is there any way to specify in .vsprops file paths relative to .vsprops file directory?
For example, I have the followind directory stucture:
largesolution.sln
a/a.vcproj
b/c/c.vcproj
common/common.vsprops
Both a.vcproj and c.vcproj include common.vsprops, and I want to add some macro or set include directory relative to common folder regardless the solution directory both projects are included to. I've tried using $(InputDir) in .vsprops file, but it seems this macro is expanded as directory containing .vcproj, not .vsprops file.
Setting absolute paths or setting global include path in Visual C++ Directories is not a solution because different developers have different location of the source tree root. Setting paths relative to $(SolutionDir) does not suit because it is useful to have smaller solutions containig some subset ob projects (for example, a.vcproj only) somewhere outside main sources tree.
Of course, setting include directory in a.vcproj to $(ProjectDir)..\common works fine, but the result to be achieved is only including .vsprops and having paths set correctly.
You can use MSBuildThisFileDirectory macro.
For example:
You set Include Directories to "$(MSBuildThisFileDirectory)\include;$(IncludePath)" in common.props.
See http://msdn.microsoft.com/en-us/library/vstudio/ms164309.aspx for details.
Tested with MSVS2012 and MSVS2013.

Resources