I am working on a fortran project with many files and libraries. To organize information I created within the working directory three subfolders, call them /code, /obj and /bin.
How can I write a shell script so that I can invoke
gfortran -c $(code)/file1.f90 $(code)/file2.f90 $(code)/file3.f90
gfortran -c -J/$(obj) $(bin)/binary $(obj)/file1.o $(obj)/file2.o $(obj)/file3.o
I know it is a very stupid question but I am not familiar with shell scripting or 'make'. Thank you very much in advance
Related
I'm currently trying to use Gcov and Gcovr from CMake on Windows using MinGW.
Compiling the files with the right flags works like a charm.
However, CLion uses an out-of-source build which Gcov does not understand.
On Linux I used the following to copy all the *.gcda and *.gcno to the CMAKE_SOURCE_DIR from CMAKE_BINARY_DIR subfolders:
set(GCOV_DATA_DIR "${CMAKE_SOURCE_DIR}/gcov_data")
add_custom_target(prepare_coverage
# Copy necessary files to CMAKE_SOURCE_DIR
COMMAND ${CMAKE_COMMAND} -E make_directory ${GCOV_DATA_DIR}
COMMAND find ${CMAKE_BINARY_DIR} -name \"*.gcda\" -o -name \"*.gcno\" | xargs -l -i cp {} "${GCOV_DATA_DIR}"
)
Note that test binaries are executed in CMAKE_BINARY_DIR.
This works pretty well and I can call Gcovr with some additional flags afterwards to get a nice report.
However, on Windows I do not have xargs (I was already supprised that find did work).
To make this CMake command platform-independent I'm looking for a way to make CMake find and copy/move the files during build time (similar to making the directory).
Can anyone tell me if this is possible and how I should do this?
Of course I can always install additional programs or scripts, but I'd rather solve this within CMake instead of having to instruct all the developers to install different tools.
If you don't use CMAKE_RUNTIME_OUTPUT_PATH in your project, then .gcda and .gcno files are created in the directory with executable, so you may compute this directory with $<TARGET_FILE_DIR:tgt> generator-expression.
Because you know names of source files, you may compute absolute paths of all gcov-related files, and generate appropriate copiing commands without find.
Another approach could be writting xargs-like program/script by yourself, shipping it with your project, and using it in COMMAND. So
... but I'd rather solve this within CMake instead of having to instruct all the developers to install different tools.
wouldn't be a problem.
Hi this question seems to be answered but answers don't resolve my problem.
I try to include lua script into executable by copying it into exe
copy -b a.exe+test.lua output.exe
but when i launch output.exe luaL_dofile() cannot find lua script.
I dont want to use any third party apps to achieve this.
Copying files seems to work because Love2D projects works and I copy files in the same way but i treats them as zip archive (for sake of file hierarchy).
You can append a Lua script to your .exe but you'll need some way to load it into your program. The main problem is how to find the Lua script at the end of the .exe. srlua appends a small signature that contains the size of the Lua script so that the program can read the script at the right offset in the .exe file. Fortunately, the Lua API provides a function to load scripts from arbitrary sources. The convenience function luaL_dofile uses that function. You can use the same technique in your own program.
I want to create a .bat file (on windows) that is similar to make on linux!
The ideia is to compile all the .l files and .y files in the folder and then
use the cl (compiler from VS2012) to batch compile all the generated .c files
into .obj and then a final .exe
Is this possible? how can I create this?
all the files in the folder are from the same project and I wanted the .bat file
to accept a name for the final .exe file.
Thank you in advance
You can use nmake in the Visual Studio command prompt just like you used make in linux. There are differences between Gnu Make on linux and Microsoft Nmake but for the simple usage you describe they would be the same. You could even copy over the same Makefile if you are careful.
A simple batch file is fairly straight forward and there are plenty of introductions to batch files available to read. Just as a bash script on linux, a batch file just contains the commands you would have typed at the command prompt, but stored in a file with the *.bat name. For example:
#echo off
flex %1.l
bison %1.y
cl /out:%1.exe %1.tab.c
You have to make sure that the flex library is available to visual studio to get it to link, however.
I can run compile in OSX terminal using g++ -Wall -c pa1.cpp -o pa1. Which creates pa1, so I know my compilation works in terminal but I am having issues with execution. I have tried ./pa1 , ./a.out, pa1 and few others. I believe the issue is with Xcode, yet the fact that my code will compile in terminal and creates an executable makes me unsure. Thought, I would ask here for suggestions before reinstalling Xcode.
Use g++ pa1.cpp -o pa1 and then you'll be able to run your new executable as ./pa1. This require that your whole program is in pa1.cpp. If it is spread in multiple files, you'll have to list all of them on the command-line.
As said in the comments, the -c option means compile, ie. Create an object file that can be passed to the linker to build an executable. If you don't use this option, g++ will first compile any source file, then invoke the linker on all the object files to create an executable named a.out by default (name comes from historical reason).
You can see that the output of your command was not an executable binary but an intermediate object file by using the file util.
I'm new to using Terminal for compiling code. In the following
gcc inputfile.m -o outputfile
./outputfile
What does the ./ mean?
Thanks
./outputfile tells Bash (the program that runs the Terminal) to run the file outputfile which is located in the current directory (./)
Bash can run any file, whether is a compiled file (like you case) or a script.
That is your compiled program. The line ./outputfile is calling the executable you created. It may seem a little strange that you have to do this in your case because you are only using 1 input file, but imagine that you are creating a bigger program with a many files that all need to be compiled together.
gcc inputfile1.m inputfile2.m class1.m class2.m main.m -o outputfile
All those files would be compiled and put into outputfile.