The best, most flexible way to do this is through the build system, using Make or CMake or something similar. But there is a serious learning curve. Now it may be easier to just create a script file to run the same commands that you successfully used from the command line.
I assume you are using a bash shell. You can simply edit the file - name it "compile.bash". In the first line of the file, enter "#! / Bin / bash". This tells the system to interpret this file as a bash script file. Then, on one or more of the following lines, enter the commands that you just indicated in your question, just like you used them before. Save the file. Then run this command from the command line: "chmod + x compile.bash" (without quotes). Make sure the new file is in the directory from which you are compiling, and you can simply type: "compile.bash" instead of the long command line that you used before.
Example file "compile.bash"
source share