Skip to content

Emacs package to create a Makefile, compile and run a C file

Notifications You must be signed in to change notification settings

nick96/basic-c-compile

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Basic C compile

http://melpa.org/packages/basic-c-compile-badge.svg https://img.shields.io/github/license/mashape/apistatus.svg https://travis-ci.org/nick96/basic-c-compile.svg?branch=master https://coveralls.io/repos/nick96/basic-c-compile/badge.svg

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.

basic-c-compile-file

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

basic-c-compile-makefile

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.

basic-c-compile-run-c

This command runs the output file <file-name>.<extension with ./<file-name>.<extension>.

Settings

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>).

VariableDescriptionDefault
basic-c-compile-compilerSet compiler“gcc”
basic-c-compile-all-filesChoose the set of files compiled“all”
basic-c-compiler-flagsString of the flags used by the compiler“-Wall”
basic-c-coomile-auto-compBoolean defining wherer or not to update out-of-date outfilest
basic-c-compile-outfile-extensionString or nil setting the extension added to the outfile“.o”
basic-c-compile-make-cleanCommand run for make clean“rm -f *.o”

Example usage

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.

Issues

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.

About

Emacs package to create a Makefile, compile and run a C file

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •