My Notes on Makefiles

April 16, 2021 - Reading time: 3 minutes

Stuff I use most

Output Functions

  • $(info ...) - Print out some info message
  • $(warning ...) - Print out a warning
  • $(error ...) - Print out an error and STOP

Defines

  • D = something - Set D equal to 'something' every time D is used (expand every time)
  • D := something - Set D equal to 'something' once (expand only once. non-recursive)
  • D ?= something - Set D equal to 'something' only if not already set

Functions

  • $(shell ) - Run 'command' in a shell and return output

  • $(call var,arg,arg,...) - Call a function, var, with args.

    call example call example: reverse = $(2) $(1) D = $(call reverse,a,b) # D will contain 'b a'

  • $(filter pat,text) - Filter 'text' by 'pat'

    filter example filter example: D = a.h a.c b.h b.c CFiles = $(filter %.c,$(D)) # CFiles will contain 'a.c b.c' only

  • $(if ,,) - If 'cond' is non-empty string, do 'then'...

  • $(or arg,arg,...) - Return first non-empty arg or empty string

  • $(and arg,arg,...) - Return empty string or last non-empty arg

List Functions

  • $(sort ) - Sort list
  • $(firstword list) - Return first item in space-separated list
  • $(lastword list) - Return last item in space-separated list
  • $(word nth,list) - Return 1-based nth word in list
  • $(words list) - Return the number of words in space-separated list
  • $(wordlist start,end,list) - Return words from start to end in list

Directory/Path/File Functions

  • $(abspath ...) - Get absolute path of a file and don't check for existence
  • $(realpath ...) - Get real path of a file and return empty string if it doesn't exist
  • $(wildcard ) - Get list of files matching 'pattern'

Create/Append to File

  • $(file >$(log),stuff) - Write 'stuff' to log file

More stuff


Push an Existing Project into GitHub

April 8, 2021 - Reading time: ~1 minute

I always forget these steps so noting them here. This does assume that an empty repo is first created on GitHub.

  • git init # initialize directory to be a new git repo
  • git add . # add files
  • git commit -m "Initial Commit" # commit the files
  • git remote add origin # add the GitHub repo as the remote
  • git remote -v # verify addition
  • git push origin master # push commit to master branch on GitHub

Useful Vim Settings Without Plugins

April 5, 2021 - Reading time: ~1 minute

Here are some settings that I use in Vim to make it useful without having to install a ton of plugins.

File Search

" Vim File Search Settings
set path+=** set wildmenu

Setting the path variable will allow Vim to search subdirectories and turn on tab completion.

Setting the wildmenu will show a list of matching files in a popup line when tab completion is used.

Once these two are set, you can use :find with tab and * to autocomplete and wildcard-match files.

Tag Jumping

" Vim Tag Jumping
command! MakeTags !ctags -R .

To use this, ctags must be installed. When this command is issued, a tags file is created. Then, you can use ^] to jump to a tag that's under the cursor. Use g^] for an ambiguous tag search. Use ^t to jump back to where you were. Issue the command as needed to update the tags file. (^ means the control key.)

Autocomplete

To autocomplete words while typing, use control x to start the autocomplete.

Then use control n for local completes (from within the file), control f for file name completes, and control ] for tag completes.


Categories