1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# This is the makefile for fill_array
# You are free to copy/adapt this code
# Remember the file should be named exactly "Makefile", no file extension

# syntax for a rule
#<target>: <dependencies>
#   <command>
#   <command>

# syntax for variable
#NAME=VALUE
#invoke using $(NAME)

# Variables
NAME=fill_array
EXECUTABLE=test_$(NAME)
MAIN_FILE=$(EXECUTABLE).c
SRC_FILE=$(NAME).c
OBJ_FILES=$(NAME).o $(EXECUTABLE).o
HEADER_FILES=$(NAME).h miniunit.h clog.h
HELLo_MSG="Hello"
CFLAGS=-std=c11 -g -Wall -Wshadow --pedantic -Wvla -Werror

# compiles our executable test_fill_array using object files
# runs the linker step of compiling
$(EXECUTABLE): $(OBJ_FILES)
    gcc $(OBJ_FILES) -o $(EXECUTABLE) $(CFLAGS)

# compiles fill_array.c into an object file
# runs the preprocessor and the compiler steps of compiling
$(NAME).o: $(SRC_FILE) $(HEADER_FILES)
    gcc -c $(SRC_FILE) $(CFLAGS)

# compiles test_fill_array.c into an object file
$(EXECUTABLE).o: $(MAIN_FILE) $(HEADER_FILES)
    gcc -c $(MAIN_FILE) $(CFLAGS)

# compiles test_fill_array then runs it
run: $(EXECUTABLE) 
    ./$(EXECUTABLE)

cleanrun: clean run

# removes all files produced by this makefile
clean:
    rm -f *.o
    rm -f $(EXECUTABLE) 

# prints out Hello
# because sometimes we need a computer to tell us hello
hello:
    echo $(HELLO_MESSAGE)

.PHONY: clean hello run cleanrun

© Copyright 2022 Alexander J. Quinn         This content is protected and may not be shared, uploaded, or distributed.