How to declare LLVM arguments from within the code? - compilation

I want to compile a module with a specific LLVM argument. I know about the -C llvm-args='..' command line argument to rustc, but I don't want to have to ask whoever deploys the code to remember the command line.
Is there a way to put such arguments in the code (similar to #[link_args(..)])?

Related

Makefile execution properly [duplicate]

I tried to use a make file in code::blocks but I am doing it wrong. I have the version installed with the compilers included. http://sourceforge.net/projects/codeblocks/files/Binaries/10.05/Windows/codeblocks-10.05mingw-setup.exe/download. What do I do with the make file? It starts with:
CC=gcc
best, US
You don't tend to execute the make file itself, rather you execute make, giving it the make file as an argument:
make -f pax.mk
If your make file is actually one of the standard names (like makefile or Makefile), you don't even need to specify it. It'll be picked up by default (if you have more than one of these standard names in your build directory, you better look up the make man page to see which takes precedence).
As paxdiablo said make -f pax.mk would execute the pax.mk makefile, if you directly execute it by typing ./pax.mk, then you would get syntax error.
Also you can just type make if your file name is makefile/Makefile.
Suppose you have two files named makefile and Makefile in the same directory then makefile is executed if make alone is given. You can even pass arguments to makefile.
Check out more about makefile at this Tutorial : Basic understanding of Makefile

Pipe and Redirect Bashcommands doesn't work in cmake [duplicate]

What I want to achieve
I try to set up a toolchain to compile OpenCL applications for Intel FPGAs. Therefore beneath building the C++ based host application I need to invoke the Intel OpenCL offline compiler for OpenCL kernels.
This step should only take place if the cl source file was edited or the resulting binaries are missing. My approach is to add a custom command to invoke the CL compiler and create a custom target that depends on the output generated by this command. The offline Open CL compiler is called aoc and due to the possibility of multiple SDK-Versions present on the system I invoke it with an absolute path that is stored in aocExecutable. This is the relevant part of my CMakeLists.txt
set (CLKernelName "vector_add")
set (CLKernelSourceFile "${PROJECT_SOURCE_DIR}/${CLKernelName}.cl")
set (CLKernelBinary "${PROJECT_BINARY_DIR}/${CLKernelName}.aocx")
add_executable (HostApplication main.cpp)
# ------ a lot of unneccessary details here ------
add_custom_command (OUTPUT "${CLKernelBinary}"
COMMAND "${aocExecutable} -march=emulator ${CLKernelSourceFile} -o ${CLKernelBinary}"
DEPENDS "${CLKernelSourceFile}"
)
add_custom_target (CompileCLSources DEPENDS "${CLKernelBinary}")
add_dependencies (HostApplication CompileCLSources)
What doesn't work
Running this in the CLion IDE under Linux leads to this error:
/bin/sh: 1: /home/me/SDKsAndFrameworks/intelFPGA/18.1/hld/bin/aoc -march=emulator /home/me/CLionProjects/cltest/vector_add.cl -o /home/me/CLionProjects/cltest/cmake-build-debug-openclintelfpgasimulation/vector_add.aocx: not found
The whole command expands correctly, copying it and pasting it into a terminal works without problems, so I'm not sure what the not found error means.
Further Question
Assumed the above problem will be solved, how can I achieve that the custom command is not only invoked if the output file is not present in the build directory but also if the CL source file was edited?
As you can see in the error message, the bash interprets the whole command line
/home/me/SDKsAndFrameworks/intelFPGA/18.1/hld/bin/aoc -march=emulator /home/me/CLionProjects/cltest/vector_add.cl -o /home/me/CLionProjects/cltest/cmake-build-debug-openclintelfpgasimulation/vector_add.aocx
as a single executable.
This is because you wrap COMMAND in your script with double quotes.
Remove these double quotes, so everything will work.
As in many other scripting languages, in CMake double quotes makes the quoted string to be interpreted as a single argument for a function or for a macro.
But in add_custom_command/add_custom_target functions a keyword COMMAND starts a list of arguments, first of which denotes an executable and others - separated parameters for that executable.

how to tell if my C program was invoked via shebang?

I've built a little command interpreter (in C++) which can be invoked either directly, or in a script via shebang (#!). It can take arguments on the command line (which appear as argc/argv in my code).
Trouble is, when invoked via shebang, the script itself gets passed to my program as argument 1. That's problematic; I don't want my command interpreter trying to process the script that it was invoked from. But I can't see any easy way to tell when this is the case.
EDIT: As an example, if I have a script called "test" which starts with #!/usr/local/bin/miniscript, and then invoke it as ./test --help -c -foo, I get 5 arguments in my C code: /usr/local/bin/miniscript, ./test, --help, -c, and -foo. If I invoke it directly, then I get four arguments: /usr/local/bin/miniscript, --help, -c, and -foo
How can I tell when my program was invoked via a shebang, or otherwise know to skip the argument that represents the script it was invoked by?
My question was based on a wrong assumption. I believed that two things were happening when a program was invoked via shebang:
Path to that program was passed as the first argument.
Contents of that program were piped to stdin.
So I was essentially worried about processing the content twice. But only item 1 is true; item 2 does not happen (as pointed out by helpful commenters on my question). So if the C code accepts the name of a file to process as a first argument, and ignores any initial line starting with a shebang, then all is right with the world.

Command line : arguments, options and paramaters

I'm trying to have a better understanding about how command line work
I'm a bit confused when it comes to arguments, options and subcommand
Let's imagine with maven (a java build tool) :
mvn clean install
mvn is the command line program. But what are 'clean' and 'install' ? Are they arguments or subcommands ?
Let's imagine another example :
prog -a arg
prog is the command line program. -a is an option and arg an argument. How do you know if arg is the arguments belonging to the 'prog' or an argument belonging to the option '-a' ?
Thanks
Are they arguments or subcommands
It depends. If the program has a hierarchy in its arguments, they would be sub-commands, like here:
docker image ls
(The docker program has a command/command group image and a sub-command ls.)
If the program takes arguments in order to express a serial execution, they would be just arguments, like here:
mvn clean install
(The mvn program will first execute the clean lifecycle, then execute up to the install phase in the default lifecycle, see here.)
I see that often arguments have a meaningful order, such as with Maven, while options more-commonly can be placed anywhere. For Maven, there's arguments like -D..., -e, -U (to mention a few common ones). They could go anywhere:
mvn -e clean -DskipTests install -Dcheckstyle.skip=true ... et cetera
With other programs the order of options may matter, like find has "tests". They look like options (in the sense that they have -option-notation), although one could argue they are arguments. In other words, it depends.
prog -a arg
How do you know if arg is the arguments belonging to the 'prog' or an argument belonging to the option '-a'
Again, it depends on the definition of the a option. If it doesn't take an argument, it's sometimes called a flag. If it does take an argument, that is part of the specification of the option, and the command-line parser of the program can account for that.
Personally, I learned a lot from building command-line tools using Click. (And by no means an expert.)

Cannot `source` shc-compiled scripts

Is there any way to source (include) compiled script?
I use shc to compile all of my scripts and when I run them from the command line they work OK to start. But when script have to include other two scripts (variables.sh.x and functions.sh.x) it crashes and returns an error, that binary files can not be included.
Is there any way to accomplish this?
including piece of code:
source $(dirname $0)/variables.sh.x
source $(dirname $0)/functions.sh.x
shc does not actually compile scripts. It merely obfuscates them by encrypting and embedding them inside a C program, so it cannot improve performance. The actual shell still interprets and executes the code and is required for the script to run.
If you absolutely must use this tool to obfuscate your code, you will have to combine everything into a single file.

Resources