|
1 |
| -# --- constants |
| 1 | +#============================== |
| 2 | +# Gavin Lyons 12-2023 |
| 3 | +# Make file to build Fractal Creator Program |
| 4 | +# URL:: https://github.com/gavinlyonsrepo/Fractal_creator |
| 5 | +# Run make help for options |
| 6 | +#============================== |
| 7 | + |
| 8 | +SRC=src/ |
2 | 9 | CC=g++
|
3 |
| -CFLAGS=-Wall -g -c |
4 |
| -LDFLAGS=-Wall -g -L /usr/lib/x86_64-linux-gnu |
5 |
| -SOURCES = $(wildcard ./src/*.cpp) |
6 |
| -OBJECTS = $(SOURCES:.cpp=.o) |
7 |
| -BIN=./bin |
8 |
| -INCLUDES=./include |
9 |
| -TARGET=$(BIN)/fcsim |
10 |
| - |
11 |
| - |
12 |
| -# --- Target of build process |
13 |
| -all: $(TARGET) clean |
14 |
| - |
15 |
| -$(TARGET): $(OBJECTS) |
16 |
| - $(CC) -o $(TARGET) $(OBJECTS) $(LDFLAGS) |
17 |
| - |
18 |
| -# Make an .o from a .cpp |
19 |
| -%.o: %.cpp |
20 |
| - $(CC) $(CFLAGS) -o $@ -c $< -iquote $(INCLUDES) |
21 |
| - |
22 |
| - |
23 |
| -# --- Cleanup |
24 |
| -#.PHONY: clean |
| 10 | +LDFLAGS= -L /usr/lib/x86_64-linux-gnu |
| 11 | +CFLAGS = -std=c++2a -Iinclude/ -c -Wall -Wextra |
| 12 | +MD=mkdir |
| 13 | +BUILD=Build |
| 14 | +SRCS = $(wildcard $(SRC)/*.cpp) |
| 15 | +OBJS = $(patsubst $(SRC)/%.cpp, $(BUILD)/%.o, $(SRCS)) |
| 16 | +BIN=./Bin |
| 17 | +EXENAME=fcsim |
| 18 | +TARGET=$(BIN)/$(EXENAME) |
| 19 | +PREFIX=/usr/local/bin |
| 20 | + |
| 21 | +# The --no-print-directory option of make tells make not to print the message about entering |
| 22 | +# and leaving the working directory. |
| 23 | +MAKEFLAGS += --no-print-directory |
| 24 | + |
| 25 | +# Main task, makes build directory, updates your objects, builds your executable |
| 26 | +.PHONY: all |
| 27 | +all: clean build |
| 28 | + |
| 29 | + |
| 30 | +# Task producing target from built files |
| 31 | +$(TARGET): $(OBJS) $(BUILD) |
| 32 | + @echo 'MAKE EXE FILE' |
| 33 | + $(CXX) $(OBJS) -o $@ $(LDFLAGS) |
| 34 | + @echo '[DONE!]' |
| 35 | + |
| 36 | +# Compile all cpp files |
| 37 | +$(BUILD)/%.o : $(SRC)/%.cpp $(BUILD) |
| 38 | + @echo 'MAKE OBJECT FILE' |
| 39 | + $(CXX) $(CFLAGS) $< -o $@ |
| 40 | + |
| 41 | + |
| 42 | +# Build task |
| 43 | +.PHONY: build |
| 44 | +build: |
| 45 | + @echo |
| 46 | + @echo '[BUILDING:!]' |
| 47 | + @echo $(SRC) |
| 48 | + $(MD) -vp $(BIN) |
| 49 | + $(MD) -vp $(BUILD) |
| 50 | + $(MAKE) $(TARGET) |
| 51 | + @echo '***************' |
| 52 | + |
| 53 | +# Run task |
| 54 | +.PHONY: run |
| 55 | +run: |
| 56 | + $(TARGET) |
| 57 | + |
| 58 | +# Clean task :: removes obj and executbale |
| 59 | +.PHONY: clean |
25 | 60 | clean:
|
26 |
| - rm -vf $(OBJECTS) |
| 61 | + @echo |
| 62 | + @echo '[CLEANUP!]' |
| 63 | + rm -rvf $(BUILD) $(BIN) |
| 64 | + @echo '[DONE!]' |
| 65 | + |
| 66 | + |
| 67 | +# Help task :: explains the options |
| 68 | +.PHONY: help |
| 69 | +help: |
| 70 | + @echo '[HELP!]' |
| 71 | + @echo "make - Cleans + builds project" |
| 72 | + @echo "make clean - Cleans : Removes object file folder and executable" |
| 73 | + @echo "make build - Complies and Builds project" |
| 74 | + @echo "make run - Runs exe" |
| 75 | + @echo "make install - Installs exe, may need sudo" |
| 76 | + @echo "make uninstall - Uninstalls exe, may need sudo" |
| 77 | + @echo "make help - Prints help message" |
| 78 | + @echo '***************' |
| 79 | + |
| 80 | +#install exe |
| 81 | +.PHONY: install |
| 82 | +install: |
| 83 | + @echo "[INSTALL EXE]" |
| 84 | + cp -v $(TARGET) $(PREFIX)/$(EXENAME) |
| 85 | + @echo "*****************" |
| 86 | + |
| 87 | +# Uninstall the exe |
| 88 | +.PHONY: uninstall |
| 89 | +uninstall: |
| 90 | + @echo "[UNINSTALL EXE]" |
| 91 | + @rm -vf $(PREFIX)/$(EXENAME) |
| 92 | + @echo "******************" |
0 commit comments