-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathMakefile
69 lines (59 loc) · 2.29 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
# source files from include/
c_include_source_files := $(shell find include/* -name "*.c")
c_include_header_files := $(shell find include/* -name "*.h")
# source files from src/
c_source_files := $(shell find src/* -name "*.c")
c_header_files := $(shell find src/* -name "*.h")
# shared so files
#shared_libs = $(shell find shared_lib/* -name "*.so")
# Compile flags
FLAGS= -std=c11 -ggdb -w -nostdlib
# input args to main ( set at runtime )
args=
# make all so files and build main binary with it
bootstrap_shared_lib:
@mkdir -p build shared_lib
@echo -e "[\e[42m Building so files... \e[0m]"
@$(foreach file ,$(c_include_source_files),gcc -shared $(file) -o $(patsubst include/src/%.c, shared_lib/%.so, $(file)) && ) true
@echo -e "\e[32m[+]\e[0m Done."
.PHONY: shared_lib
shared_lib: bootstrap_shared_lib $(c_include_source_files) $(c_source_files) $(c_header_files)
@echo -e "\e[32m[+]\e[0m Linking File..."
gcc ${FLAGS} $(shell find shared_lib/* -name "*.so") include/src/_lib.c ${c_source_files} -o build/main
@echo -e "\e[32m[+]\e[0m Done."
.PHONY: static_lib
static_lib: $(c_include_source_files) $(c_include_header_files) $(c_source_files) $(c_include_files)
@mkdir -p build/
@echo -e "[\e[42m Building Static lib... \e[0m]"
cd static_lib && make
@echo -e "\e[32m[+]\e[0m Linking File..."
gcc -nostdlib -L. ./src/main.c -l:./static_lib/no_libc.a -o build/main
@echo -e "\e[32m[+]\e[0m Done."
test:
@echo -e "\e[43m[ TESTING BUILDS \e[0m]"
@echo -e "\e[33m[#]\e[0m TESTING : LINKING C FILES"
make all
@echo -e "\e[33m[#]\e[0m TESTING : CREATING SO LIBS"
make shared_lib
@echo -e "\e[33m[#]\e[0m TESTING : CREATING STATIC LIBS"
make static_lib
@echo -e "\e[32m[+]\e[0m Done."
workflow-test:
@echo -e "\e[43m[ TESTING WORKFLOW BUILD \e[0m]"
@echo -e "\e[33m[#]\e[0m TESTING : LINKING C FILES"
make all
# uses .c files
.PHONY: all
all: $(c_include_source_files) $(c_include_header_files) $(c_source_files) $(c_include_files)
@echo -e "[\e[42m Building Binary file... \e[0m]"
@mkdir -p build/
gcc $(FLAGS) ${c_include_source_files} ${c_source_files} -o build/main
@echo -e "\e[32m[+]\e[0m Done."
.PHONY: run
run:
@echo "=============================================="
@./build/main $(args)
@echo "=============================================="
make clean
clean:
rm -rf build/* 2>/dev/null