Chapter 35 Automation: test drive make
Before we use make
for real work, we want to prove beyond a shadow of a doubt that it’s installed and findable from RStudio and/or the shell.
35.1 Create a temporary RStudio project
You can delete this project after this test drive, so don’t sweat too much about what you name it or where you put it.
- Create an RStudio project: File > New Project
- Create a new text file: File > New File > Text File
- We are about to write our first
Makefile
!
But first …
35.2 Disable “insert spaces for tab”
Tabs are very meaningful in Makefiles
, so it’s important to make sure your text editor is not “helpfully” but silently converting tabs to spaces.
Here’s how to disable this in RStudio.
- Global setting: Tools > Global Options… > Code > Editing. Make sure “Insert spaces for tab” is unchecked.
- Project-specific setting: Tools > Project Options… > Code Editing. Make sure “Insert spaces for tab” is unchecked.
RStudio can reveal information about the whitespace in a file: RStudio > Preferences… > Code > Display > “Show whitespace characters”. When in doubt, make darn sure your Makefile
is indented with tabs and not spaces!
35.3 Write a toy Makefile
Type or paste this into your new text file. Make sure the indentation before @echo
is always a tab! Save as Makefile
:
35.4 Configure this RStudio project to use make
Select Build > Configure Build Tools… > Build Tools > Project build tools > Makefile.
This will make a new tab and buttons and menus available in RStudio, usually in the upper right-hand pane, similar to the Git stuff.
35.5 Run make
via RStudio
Select Build > Build All (the hammer icon).
The result and any error messages should appear under the Build tab.
Hopefully you will see this:
If you see something like this:
you probably have spaces instead of tabs as indentation. Fix that and try again.
RStudio offers these buttons or menu items to run things from your Makefile
:
- Build All - runs
make all
, as we just saw - Clean All - runs
make clean
- Clean and Rebuild - runs
make clean all
For these menu items to work, your Makefile
needs to have targets named all
and clean
. These non-file targets are called phony targets.
You should be able to select Build > More > Clean All and get this:
You should be able to select Build > More > Clean and Rebuild and get this:
This proves that make
is installed and working from RStudio.
35.6 Run make
from the shell
RStudio only provides access to a very limited bit of make
– it’s even more limited than the RStudio Git client. In the long run, it’s important to be able to run make
from the shell.
- Select Tools > Shell
Run
You should be seeing similar output as you saw in the Build tab of RStudio.
If you are not, are you getting the error message that’s characteristic of a “spaces instead of tabs” problem? Or does it look more like make
or other commands aren’t being found? If the latter, go back to the Windows installation page or reach out to the course staff.