Concatenation of foldername and filenames in nmake - makefile

I have a Makefile for Nmake containing a list of files in a macro:
MYSRCFILES1=myfolder\file1.svg myfolder\file2.svg ... myfolder\file99.svg
and a second one just like this:
MYSRCFILES2=myfolder2\file1.svg myfolder2\file2.svg ... myfolder2\file99.svg
What I am trying is to avoid duplication of the list of files, and to avoid duplication of the folder names, something like this:
MYSRCFILES0=file1.svg file2.svg file3.svg
MYSRCFILES1="prepend 'myfolder\' to each element of $(MYSRCFILES0)"
MYSRCFILES2="prepend 'myfolder2\' to each element of $(MYSRCFILES0)"
Digging myself through the documentation of Nmake I haven't found a solution so far. Any idea how to accomplish this?

Finally found a solution for my problem, it's not perfect since I have to add a .\ to every file but that seems to be ok in my case:
MYSRCFILES0=.\file1.svg .\file2.svg .\file3.svg ...
MYSRCFILES1=$(MYSRCFILES0:.\=myfolder\)
MYSRCFILES2=$(MYSRCFILES0:.\=myfolder2\)
does the trick.

Is Nmake simillar to make? You can use patsubst ("pattern substitute string") function like this:
MYSRCFILES0=.\file1.svg .\file2.svg .\file3.svg ...
MYSRCFILES1=$(patsubst %,myFolder/%,MYSRCFILES0)
MYSRCFILES2=$(patsubst %,myFolder2/%,MYSRCFILES0)

Related

Is there a way to compile Pascal program and put the generated files in a specific folder?

So I am trying to compile Pascal programs and everything is find; however, I would like to put the generated files after each compilation is a separated folder. I am looking of something like this: fpc "Destination Folder" "program.pas".
Thanks
From Alphabetical listing of command line options
-FE<x> Set exe/unit output path to <x>
-FU<x> Set unit output path to <x>, overrides -FE
So something like fpc program.pas -FEc:\output should work. I don't have fpc installed so I cannot verify. If you try it and get errors that you can't work through post them.
This one works for me:
fpc hello.pas -o"Web/hello.cgi"
I was using ubuntu, notice there is no space between the argument -o and the beginning of the path "Web/..."

Can ack be coerced into searching a complicated project

ack is a great tool for searching, especially if everything you want to find is in nested directories below a top project dir.
I'd like to search a number of different directory trees, in order to search my whole project.
I could do something like this (there are 5 or 6 more directories I'd include):
ack sometext . ../../Libraries/CMSIS/Device/ST/STM32F4xx/ ../../Libraries/CMSIS/
I've also tried doing it via the makefile, where I'd make ack a phony target, invoking ack on the directories Makefile knows about. This works, but the syntax to invoke it is unfortunate:
gmake ack SVAL=sometext
where in the Makefile:
ack:
$(ACK) $(SVAL) $(LIB_DIRS) $(DEVICE_DIRS) $(OTHER_PROJECT_DIRS)
Ideally, there would be something I could embed in the .ackrc to define the directories that ack searches. Anyone have a favorite way to use ack to search a complicated project directory structure?
Since ack can do what I want, with a complicated command line. My best answer to date is to embed it in a bash script, so I would type:
./pack foobar
To search my entire project for foobar.
The script pack would look like this:
#!/bin/bash
CONTEXT=-C1
c:/bin/ack $CONTEXT $* . ../../Libraries/CMSIS/Device/ST/STM32F4xx/ \
../../Libraries/CMSIS/
Still would prefer a .ackrc solution.
Sack: wrapper for grep, ack and/or ag (silver searcher)
http://sampsonchen.com/sack/
Can switch your `search environment' using pre-set profiles, sets up the CL flags and preset target (MULTIPLE) top-level starting-point directorieS

How do I get the directory where the executable is located?

I got the filename like this:
_TCHAR filename[_MAX_PATH];
GetModuleFileName(NULL,filename,sizeof(filename));
How do I remove the filename from this full path? Should I use regex?
You can use the Windows shell API function PathRemoveFileSpec to do this. Example usage is listed on the linked page.
Since you use VS++, you can use:
_splitpath and _wsplitpath functions to break apart path

How do you perform an action over each file using make?

Let's say I have this:
FILES = c:/file.c c:/another_file.c
and I want to do something to each of the files. For example, I'd like to apply cygpath to each of the files. How can I do that? I would like a solution based on an external program, instead of a built-in make function please.
Your question is unclear. If you mean you want to get at the cygpath'd path names, use something like:
CYG_FILES := $(shell cygpath $(FILES))

Makefile: ignore prerequisite if does not exist

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.

Resources