make tutorial

GNU Make

target thing to be made using rule

depedency target must be made if this is newer than the target

rule linux commands that will produce target

Listing 1: Example makefile (spacing before rule must be a tab)

target: dependency

The GNU Make system will be used by GEOS-Chem to compile the model. To help you understand what make does, we will create a toy make file in your user directory.

1. Open FileZilla

2. Select "Site Manager" from "File"

3. Double click on "HPC" and wait for connection to establish

4. On the right hand panel, verify that the "remote directory" is you home directory (i.e., /home/username)

5. On the right hand panel, right click and select "Create directory"

6. Name the new directory `maketest` (i.e., /home/username/maketest) and click OK

7. Double click on the new `maketest` directory

8. On the right hand panel, right click and select "Create file"

9. Enter `Makefile` and click OK

10. Right click on `Makefile` and choose "View/Edit"

11. Edit the file to look like the code below

Listing 2: maketest/Makefile (spacing before rules must be a tab)

hello.txt: temp.txt


12. Save and close

Line descriptions:

• Line 1 defines a target (“hello.txt”) and a dependency upon “temp.txt”. In plain english, hello.txt can only be created if temp.txt exists and must be recreated if temp.txt is newer than hello.txt

• Line 2 defines a build direction for hello.txt. You can tell it is for hello.txt because it is indented directly beneath hello.txt. In this simple case, temp.txt will be copied to hello.txt

• Line 4 defines a target (“temp.txt”) with no dependency

• Line 5 uses the `echo` command to put the “Hello GEOS-Chem” string on its standard output and the `>` symbol redirects that output into the temp.txt file.

1. Login to HPC via PuTTY

2. Change directories into maketest (`cd maketest`)

3. List the files in that directory (`ls`)

4. Run `make`; you should see the output below.

Listing 3: maketest/Makefile output

echo "Hello GEOS-Chem" > temp.txt

5. List the files in that directory again. What is new?

6. What happens if you run it again? ____________________


cp temp.txt hello.txt

echo "Hello GEOS-Chem" > temp.txt

cp temp.txt hello.txt