The purpose of this package is to automate come of the basic and repetetive tasks involved in C programming. All the tasks that this pacakge automate are language agnostic and whilst the defaults are C specific you can set them to any statically compiled language.
CC = <compiler set by basic-c-compile-compiler>
INFILE= <file-name>.c
OUTFILE= <file-name>.o
build: %(INFILE)
$(CC) -Wall $(INFILE) -o $(OUTFILE)
clean:
rm -rf *.o
rebuild: clean build
Note: INFILE
can also be a list of files depending on what
basic-c-compile-all-files
is set to.
This pacakge has three entry points: basic-c-compile-file
,
basic-c-compile-makefile
and basic-c-compile-run-c
.
This command initially checks if you want to compile with or without a
Makefile (just press ‘y’ or ‘n’). If you press ‘y’, it will check for
a Makefile in the file’s directory. If there is one present, it will
check for of the form <file-name>.o
. Upon finding one, the package
will run the command make rebuild
. This assumes the Makefile is
structured as expected. If no file is found, then make build
will be
run. If you choose to run without a Makefile,
<compiler> <flags> -o <file-name>.<extension> <file-name>.c
will be run.
<compiler> = basic-c-compiler-compiler
<flags> = basic-c-compile-compiler-flags
<extension> = basic-c-compiler-outfile-extension
This command creates a Makefile in the form shown above.
If the variable basic-c-compile-all-files
is set to “all”, then all
the files in the directory with the .c
extension will be
compiled. If set to “selected” you will be prompted to write a list of
the files to be compiled. The files should be separated by a space. If
basic-c-compile-all-files
is set to anything else, only the current
file will be included.
This command runs the output file <file-name>.<extension
with
./<file-name>.<extension>
.
All customisable setting can be found in the customisation menu (M-x
customize-variable
). They are in the group basic-c-compile
which is
in the tools
section. You can also change them in your init file
with: (setq <variable-name> <variable-value>)
.
Variable | Description | Default |
---|---|---|
basic-c-compile-compiler | Set compiler | “gcc” |
basic-c-compile-all-files | Choose the set of files compiled | “all” |
basic-c-compiler-flags | String of the flags used by the compiler | “-Wall” |
basic-c-coomile-auto-comp | Boolean defining wherer or not to update out-of-date outfiles | t |
basic-c-compile-outfile-extension | String or nil setting the extension added to the outfile | “.o” |
basic-c-compile-make-clean | Command run for make clean | “rm -f *.o” |
This example below is how I have the package setup for me. In my init file I have:
(require basic-c-compile)
(setq basic-c-compiler "gcc-6"
basic-c-compile-all-files nil
basic-c-compile-compiler-flags "-Wall -Werror -std=c11"
The main issue I find with this workflow is for programs that require file redirection because the eshell doesn’t support this. Basically, that’s the only time that I switch to a shell outside of Emacs. Currently, I am working on adding this facility.
Currently when you run basic-c-compile-run-c
it hangs after
basic-c-compile-file
. To get passed this just press enter and it
will continue. I am trying to sort this out though.