-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
167 lines (119 loc) · 4.09 KB
/
Copy pathMakefile
File metadata and controls
167 lines (119 loc) · 4.09 KB
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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
# This Makefile was generated by scaffold
# https://codeberg.org/xtrm/scaffold
NAME = woody_woodpacker
VERSION = 0.9.3
MAKE = make --no-print-directory
CC = clang
CFLAGS = -Wall -Wextra -std=c23
LDFLAGS =
NASM = nasm
NASMFLAGS = -f elf64
PEDANTIC ?= 1
ifeq ($(PEDANTIC), 1)
CFLAGS += -Wpedantic
endif
CFLAGS += -DWW_PROJECT_NAME=\"$(NAME)\"
CFLAGS += -DWW_PROJECT_VERSION=\"$(VERSION)\"
SRC_DIR = src/main
SHSRC_DIR = src/shellcode
INC_DIR = include
CFLAGS += -I$(INC_DIR)
BUILD_DIR = build
OBJ_DIR = $(BUILD_DIR)/obj
-include development.mk
ifeq ($(DEVELOPMENT),1)
CFLAGS += -g3 -gdwarf-3 -ggdb -DWW_DEBUG=1
USE_WARNINGS := 1
_ := $(shell bash gensources.sh $(SRC_DIR) $(SHSRC_DIR))
endif
include sources.mk
ifneq ($(USE_WARNINGS), 1)
CFLAGS += -Werror
endif
OBJS := $(addprefix $(OBJ_DIR)/,$(patsubst %.c,%.o,$(patsubst %.s,%.o,$(SRCS))))
SRCS := $(addprefix $(SRC_DIR)/,$(SRCS))
SHSRCS := $(addprefix $(SHSRC_DIR)/,$(SHSRCS))
SHBINS := $(patsubst %.s,%.bin,$(SHSRCS))
LIB_DIR = third-party
LIBFT_DIR = $(LIB_DIR)/libft
LIBFT = $(LIBFT_DIR)/build/output/libft.a
LIBELFSTREAM_DIR = $(LIB_DIR)/libelfstream
LIBELFSTREAM = $(LIBELFSTREAM_DIR)/libelfstream.a
CLEAN_DEPS += clean_libft clean_libelfstream
FCLEAN_DEPS += fclean_libft fclean_libelfstream
CFLAGS += -I$(LIBFT_DIR)/include
CFLAGS += -I$(LIBELFSTREAM_DIR)/include
LDFLAGS += $(LIBFT)
LDFLAGS += $(LIBELFSTREAM)
CFLAGS += $(EXTRA_CFLAGS)
LDFLAGS += $(EXTRA_LDFLAGS)
all: $(NAME)
$(LIBFT):
$(MAKE) -C $(LIBFT_DIR) -j$(shell nproc)
$(LIBELFSTREAM):
$(MAKE) -C $(LIBELFSTREAM_DIR) LIBFT_DIR=../libft -j$(shell nproc) DEVELOPMENT=$(DEVELOPMENT)
$(NAME): $(OBJS) $(LIBFT) $(LIBELFSTREAM)
$(CC) $(LDFLAGS) -o $@ $^
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.c $(SHBINS)
@mkdir -p $(dir $@)
$(CC) $(CFLAGS) -c -o $@ $<
$(OBJ_DIR)/%.o: $(SRC_DIR)/%.s $(SHBINS)
@mkdir -p $(dir $@)
cd src/main; $(NASM) $(NASMFLAGS) -o ../../$@ ../../$<
$(SHSRC_DIR)/%.bin: $(SHSRC_DIR)/%.s
ifeq ($(DEVELOPMENT),1)
cd $(SHSRC_DIR); $(NASM) -f elf64 -o ../../$@.elf ../../$<
endif
cd $(SHSRC_DIR); $(NASM) -f bin -o ../../$@ ../../$<
clean-tests:
rm -rf test-dyna test-static test-dyna-32 test-static-32
test: clean-tests test-dyna test-static test-dyna-32 test-static-32
test-dyna:
clang -g3 -o test-dyna testing/test.c
test-static:
nix-shell -p pkgs.glibc.static --command "clang -static -g3 -o test-static testing/test.c"
test-dyna-32:
nix-shell -p pkgs.pkgsi686Linux.clang --command "clang -g3 -o test-dyna-32 testing/test.c"
test-static-32:
nix-shell -p pkgs.pkgsi686Linux.clang pkgs.pkgsi686Linux.glibc.static --command "clang -m32 -g3 -static -o test-static-32 testing/test.c"
test-run-dyna: test-dyna $(NAME)
rm -rf woody
./$(NAME) -vv test-dyna
test-diff-dyna: test-run-dyna
nix-shell -p busybox --command 'xxd test-dyna > dyna.hex && xxd woody > woody.hex' && nvim -d dyna.hex woody.hex
test-run-static: test-static $(NAME)
rm -rf woody
./$(NAME) -vv test-static
test-diff-static: # test-run-static
nix-shell -p busybox --command 'xxd test-static > static.hex && xxd woody > woody.hex' && nvim -d static.hex woody.hex
test-run-dyna-32: test-dyna-32 $(NAME)
rm -rf woody
./$(NAME) -vv test-dyna-32
test-diff-dyna-32: test-run-dyna-32
nix-shell -p busybox --command 'xxd test-dyna-32 > dyna-32.hex && xxd woody > woody.hex' && nvim -d dyna-32.hex woody.hex
test-run-static-32: test-static-32 $(NAME)
rm -rf woody
./$(NAME) -vv test-static-32
test-diff-static-32: test-run-static-32
nix-shell -p busybox --command 'xxd test-static-32 > static-32.hex && xxd woody > woody.hex' && nvim -d static-32.hex woody.hex
oclean:
rm -rf $(BUILD_DIR) $(SHBINS)
clean: $(CLEAN_DEPS) oclean
fclean: $(eval NOCLEAN := 1)
fclean: $(FCLEAN_DEPS) oclean
rm -f $(NAME)
clean_libft:
$(MAKE) -C $(LIBFT_DIR) clean
clean_libelfstream:
$(MAKE) -C $(LIBELFSTREAM_DIR) clean
fclean_libft:
$(MAKE) -C $(LIBFT_DIR) fclean
fclean_libelfstream:
$(MAKE) -C $(LIBELFSTREAM_DIR) fclean
re: fclean
$(MAKE) -j$(shell nproc)
remake: oclean
$(MAKE) -j$(shell nproc)
compile_commands.json: oclean
bear -- $(MAKE) USE_WARNINGS=1 $(OBJS)
.PHONY: all oclean clean fclean re remake $(CLEAN_DEPS) $(FCLEAN_DEPS) test