Using defines in Makefile.options file as a condition in Makefile variables - c

I am using clearmake and I am trying to do the following:
I have a Makefile.fast.options file that I use in my clearmake command. In there I have a USERFLAGS = -DFAST
and in another options file I don't have -DFAST in there (Makefile.slow.options).
In the actual Makefile, if FAST is defined, I want to set the output binary name to one name, or else I want to set it to another name. (If FAST is defined, I want the output to have .fast in the name, or else I want .slow.)
Is it possible to do this? perhaps I am missing a much easier method for using an options file to determine output file name?
I was also thinking of defining the filename in the makefile options file, seems much easier:
FILENAME = File.Fast
but I want to use the options file to override a definition of FILENAME thats in the makefile itself.. so, if FILENAME is set in the options file use it, or else use the one in the makefile.. is this possible?

You cannot just change the name of the file you build. You have to actually change the name of the target in the rule in the makefile. This means that the target name needs to be variable. The way you choose to make it variable is up to you.
If you're already including different options files based on fast vs. slow, then the simplest and most obvious way is to set the variable in those options files. That's the way I would recommend.
If you want to do it based on the value of USERFLAGS, you could do something like this:
ifeq ($(filter -DFAST,$(USERFLAGS)),-DFAST)
FILENAME = File.fast
else
FILENAME = File.slow
endif
But, this seems more complex and difficult to read and understand (to me).

Related

How to save file in custom place in C

I'm working with C right now. And there's a problem. I don't know how to save a FILE in custom place. When I run *.exe file, it saves them where code is placed. So how to make it save FILEs where I want it to be?(I can input a path)
a FILE is actually a long type that addresses a path on your computer.
Whether you use linux, windows, etc, the common thing about the paths is the idea that there are relative paths or absolute paths.
From what I've understood you probably did use the relative path, and I can guess you didn't specified a path at all, but only the file name.
Notice that a file's name alone is placed relatively to the path of the program you are running.
To fix your problem you might want to give an absolute path (such as "/home/user/" on linux or "C:\Users\user" on windows [pay attention for the escaping backslash]).
You can do it by something like this:
FILE *output = fopen("/home/user/output.txt", "w");
(where "w" means writing permissions to the file at the given path).
Hope this answers your question.

Why Shake dependencies are explicitly `needed`?

I find first example of Shake usage demonstrating a pattern that seems error prone:
contents <- readFileLines $ out -<.> "txt"
need contents
cmd "tar -cf" [out] contents
Why do we need need contents when readFileLines reads them and cmd references them? Is this so we can avoid requiring ApplicativeDo?
I think part of the confusion may be the types/semantics of contents. The file out -<.> "txt" contains a list of filenames, so contents is a list of filenames. When we need contents we are requiring the files themselves be created and depended upon, using the filenames to specify which files. When we pass contents on to cmd we are passing the filenames which tar will use to query the files.
So the key point is that readFileLines doesn't read the files in question, it only reads the filenames out of another file. We have to use need to make sure that using the files is fine, and then we actually use the files in cmd. Another way of looking at the three lines is:
Which files do we want to operate on?
Make sure those files are ready.
Use those files.
Does that make sense? There's no relationship with ApplicativeDo - it's presence wouldn't help us at all.

Batch file to move a number of files, then replace each of them with one file of another type while letting them keep their original name

First off I want to say that
-I didnt ever create a batch file yet, but I am really willing to learn
-I am not even sure if what i want to do is possible with a batch file
What i want to do is the following:
I want to replace a number of files of one file type in a folder each with one and the same file of another file type. In doing this, i want the "replaced" files to keep their original name except for the "replacer" file's extension. I am not talking about file conversion, this is about replacing several different files each with one and the same file, so each of them will look the same later, just with different names and the file extension of the "replacer" file. All of the files inside the folder are to be treated this way, there are no exceptions.
So it looks something like this:
Folder 1 Folder 2
10000000.tga------------->10000000.png (looks like replacer.png)
10000001.tga------------->10000001.png (looks like replacer.png)
10000011.tga------------->10000011.png (looks like replacer.png)
I really hope that my description is sufficiently precise, if not so, I am of course willing to give any information needed. I found parts of what i need (e.g. a loop for files in a folder, an order to replace one file with another file) but I am unsure of how to combine them at all, let alone to achieve what I actually wanted to do.
Any help is greatly appreciated :)
for %%i in (*.tga) do (
copy "replacer.png" "%%~ni.png"
del "%%i"
)
see for /? for details about the %%~.. syntax

How to replace text with current filename in VIM?

I suppose my question in not that clear but let me try to explain it here.
Let's suppose I have opened a file named myfilename.java with the below content
public class test{
}
Now, what I want is to replace test with myfilename. Now to get the filename in vim I used :echo expand('%:r') which gave me myfilename.
Now, my question is how to do I use the above output and replace test with it and map it to a key for future use. What I need is may be something like:
:%s/test/above_output_from_command/g
You need to add \= to tell Vim you're trying to call a function:
:%s/test/\=expand('%:r')/g
See :help sub-replace-expression.
For my application, I ended up using a keybound macro (not sure what the VIM) name for this is) that did the edit I want and simply inserted the filename where I wanted it:
:nmap <F5> 0d$:put =expand('%:p:t')^M0ipackage ^[$a;^[
In my case, I wanted to insert the name of the containint directory instead of the file, so I used:
:nmap <F5> 0d$:put =expand('%:p:h:t')^M0ipackage ^[$a;^[
The 0d$ deletes the contents of the current line, :put =expand('%:p:t')^M inserts the filename, and the remaining commands edit the line around the command to produce something like
package containing_directory;
on the current line.

Vim Keyword Completion

How do I tell the Vim editor about my include files path so that it can auto complete the function names when I press CTRL+N?
For example, I have a C program like below:
#include<stdio.h>
int main()
{
sca // here I press control+N, it does not complete to scanf
}
In your .vimrc, add the paths to your .vimrc:
set path+=/usr/include/**
set path+=/my_include_dir/include
set path+=/my_include_dir/srclib/apr/**
set path+=/my_other_include_dir/srclib/apr-util/**
** means all sub-directories.
* means all contained directories
. means all files in the directory of the found file
+= means prepend to existing path (iirc)
You can check the paths as well by opening your file and then entering
:checkpath
This will give you a list of all included files that are missing. N.B. It doesn't seem to handle preprocessor directives, so you will get some false positives. Entering
:checkpath!
Will give a complete list of found and missing include files.
Also, Important to note there are many completion functions.
^x ^o = "omnicomplete"
^x ^i = "included-files completion"
^x ^f = "path completion"
^x ^l = "Complete this line using one that looks the same"
see
:help ins-completion
for more.
Vim might also know the path already, if the files are in a standard location.
<C-n> uses the 'complete' option and the flag i scans included files. To add i to 'complete':
set complete+=i
you can also get a tags file from the symbols you want completed, which you can use with:
set complete+=t

Resources