The best alternative is “makefile” or “cmake”, but here you will create commands in case you don’t want to use them.


For this you must create an alias in the shell configuration file: .bashrc or .zshrc located in the root of your user

inside the file, at the end you must add the following:

alias name_alias='command_bash'

example:

alias java6='export JAVA_HOME=$JAVA_6_HOME'

The directory structure of C is as follows, at the root of your project:

  • src
    • impl
      • .c files
    • headers
      • .h files
  • bin
    • executables files
  • obj
    • .o files

to delete the .o and executables (clean the project)

alias deleteO='find ~/projects/name_project/obj -type f -name "*.o" -delete'
alias deleteBin='find ~/projects/name_project/bin -type f -perm +111 -delete'

To run the above 2 commands in one command (you must use &&):

alias clearfiles='deleteO && deleteBin'

to compile the files (take the .c files as input and the .o files as output):

alias compilefiles='find . -name "*.c" -exec sh -c '\''gcc -c "$1" -o "obj/$(basename "${1%.c}").o"'\'' _ {} \;'

For the changes to take effect you must reload the file with the ‘source’ command:

source location_file

example:

source ~/.zshrc

In this case the zshrc file is invisible with the (.) and is located in the user’s root directory (~)

By typing the alias you just created in a console/terminal/tty, you execute the associated command, you can create functions, use environment variables, etc.

When you restart your PC or open a new console/terminal/tty, the new changes to the shell configuration file (bash, zsh, etc.) are loaded.

The “source” command is to do it manually

For these commands to work in your project you must run them in the root of the project


create the executable

To create the executable you must indicate the .o that you use and in order

alias generateexefiles='gcc obj/a.o obj/b.o obj/c.o obj/main.o -o bin/executable'

you can create a command that does everything together

alias ccc ='clearfiles && compilefiles && generateexefiles'

and you can add another alias that executes the file


some images below:


then to run the executable:

./bin/executable