Example Usage

Using GNU Make on z/OS

To give you an idea of how GNU Make can be used, let's consider a simple example. Imagine you have a project that consists of several source code files, and you want to build an executable file from them. You can use GNU Make to automate the process of compiling and linking the source code files into an executable file. Here is an example of a simple "Makefile" that can be used to build an executable file called "myprogram" from three source code files "main.c", "module1.c", and "module2.c".

CC=clang # modify to the compiler of your choosing

myprogram: main.o module1.o module2.o
     $(CC) -o myprogram main.o module1.o module2.o

main.o: main.c
     $(CC) -c main.c

module1.o: module1.c
     $(CC) -c module1.c

module2.o: module2.c
     $(CC) -c module2.c

The first line of the "Makefile" specifies the target file to be built, in this case, "myprogram".

The next lines specify the dependencies of the target file and the commands that need to be executed to build the target file.

In this case, the clang command is used to compile and link the source code files into an executable file. To build the executable file, you can simply run the command gmake in the same directory as the "Makefile". This will execute the commands specified in the "Makefile" and build the executable file.

This is just one example of how GNU Make can be used to automate the process of building software projects. With GNU Make, you can also automate tasks such as cleaning up build files, running tests, and generating documentation.

Example source code for main.c:

#include <stdio.h>
#include "module1.h"
#include "module2.h"

int main() {
    printf("Hello, World!\n");
    print_module1();
    print_module2();
    return 0;
}

Example source code for module1.c:

#include <stdio.h>

void print_module1() {
    printf("This is module 1\n");
}

Example source code for module2.c:

#include <stdio.h>

void print_module2() {
    printf("This is module 2\n");
}

To build the project, open a terminal and navigate to the directory where the "Makefile" and the source code files are located.

Then, run the gmake command. This will execute the commands specified in the "Makefile" and build the executable file "myprogram".

For example, assuming you are in the same directory where the files are located, type:

gmake

If the build is successful, you should see the executable file "myprogram" in the same directory. You can then run the program by using:

./myprogram

This will execute the program and you should see the output:

Hello, World! This is module 1 This is module 2

You can also use the command gmake clean to clean up any object files and executable files that were generated during the build process.