This repository has been archived by the owner on May 2, 2023. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMakefile
executable file
·79 lines (64 loc) · 1.53 KB
/
Makefile
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
# Compiler settings
CC = gcc
CFLAGS = -O3
ifeq (debug, $(filter debug, $(MAKECMDGOALS)))
CFLAGS += -Wall -DDEBUG
endif
# Folders
SRC = src
BIN = bin
BUILD = build
LIB = lib
TEST = test
CFL := $(BIN) $(BUILD) $(LIB) # Create Folders List
# Files
LIBA = libbntl.a
INCLIB = bntl
TESTFILE = $(filter-out debug, $(MAKECMDGOALS))
SRCS := $(wildcard $(SRC)/*.c)
OBJS := $(addprefix $(BUILD)/, $(notdir $(SRCS:.c=.o)))
# Executables
EXE = $(basename $(TESTFILE))
# Architecture
ARCH = $(shell uname -m)
# Aesthetics
GREEN = \033[0;32m
RESET = \033[0m
all: archinfo $(CFL) $(LIBA)
# Build c files into object files
$(BUILD)/%.o: $(SRC)/%.c
@echo -n 'Building object $^: '
@ $(CC) -c $(CFLAGS) $^
@ mv *.o $(BUILD)
@echo -e ' $(GREEN)Done$(RESET)'
# Create static library archive
$(LIBA): $(OBJS)
@echo -n 'Creating static library archive: '
@ ar -rcs $@ $(BUILD)/*
@ cp -p *.a $(LIB)/
@ rm *.a
@echo -e ' $(GREEN)Done$(RESET)'
# Compile the test file
$(TESTFILE): all
@ $(CC) $(CFLAGS) -o $(BIN)/$(EXE) $(TEST)/$(TESTFILE) -l$(INCLIB) -I$(SRC)/ -L$(LIB)/
./$(BIN)/$(EXE)
# Check if all needed directory exists, if not, creates it
$(CFL):
ifeq ("$(wildcard $@)", "")
@echo -n 'Creating $@ folder: '
@ mkdir $@
@echo -e ' $(GREEN)Done$(RESET)'
endif
# Ignore debug target
debug:
echo -n
# Print architecture info
archinfo:
@echo 'Test file: $(TESTFILE))'
@echo 'Building on $(ARCH) architecture'
# Clear folders
clean:
rm $(BIN)/* $(BUILD)/* $(LIB)/*
# Clear folders and delete the directories
cleanall:
rm -r $(BIN)/ $(BUILD)/ $(LIB)/