blob: c675d1bcf994e037d13ff82b0409582c2a5d72a8 (
plain) (
blame)
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
|
#
# Copyright (C) 2022 Ferass EL HAFIDI
# Copyright (C) 2022 Leah Rowe
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 3 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.
#
include ./config.mk
# Commands
# ========
all: clean box
genbox:
echo "#ifndef VERSION_H" > version.h
echo "#define VERSION_H" >> version.h
echo "#define COMPILETIME \"$$(git show --no-patch --pretty=format:%H)\"" >> version.h
echo >> version.h
echo "#endif" >> version.h
cat "box-templates/box_1-23.c" > box.c
for u in ${CORE}; do echo "int $${u%.c}_main(int, char**);" | sed "s/\[_/test_/g"; done>> box.c
test ${INCLUDE_EXTRA} == n || for u in ${EXTRA}; do echo "int $${u%.c}_main(int, char**);"; done>> box.c
cat "box-templates/box_45-49.c" >> box.c
for u in ${CORE}; do echo " else if(!strcmp(basename(argv[0]), \"$${u%.c}\")) return $${u%.c}_main(argc, argv);" | sed "s/\[_/test_/g"; done >> box.c
test ${INCLUDE_EXTRA} == n || for u in ${EXTRA}; do echo " else if(!strcmp(argv[0], \"$${u%.c}\")) return $${u%.c}_main(argc, argv);"; done >> box.c
cat "box-templates/box_70-73.c" >> box.c
for u in ${CORE}; do echo " printf(\"$${u%.c} \");"; done >> box.c
test ${INCLUDE_EXTRA} == n || for u in ${EXTRA}; do echo " printf(\"$${u%.c} \");"; done >> box.c
cat "box-templates/box_94-96.c" >> box.c
echo "/* Generated on $$(date) */" >> box.c
prepbox:
mkdir -p box_tmp
for f in ${CORE}; do sed "s/^int main(/int $$(echo "$$f")_main(/" < "core/"$$f".c" | sed "s/printUsage()/$$(echo "$$f")_printUsage()/g" | sed "s/\[_/test_/g" > "box_tmp/"$$f"_box.c"; done
rm -f "box_tmp/[_box.c"
test ${INCLUDE_EXTRA} == n || for f in ${EXTRA}; do sed "s/^int main(/int $$(echo "$$f")_main(/" < "extras/"$$f".c" | sed "s/printUsage()/$$(echo "$$f")_printUsage()/g" > "box_tmp/"$$f"_box.c"; done
box: box.o
$(CC) $(CFLAGS) box_tmp/*.c box.o -o box
rm -f version.h
clean:
rm -f box *.o extras-bin core-bin
rm -Rf box_tmp */bin/*
install:
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -r core/bin/* $(DESTDIR)$(PREFIX)/bin
install-box:
mkdir -p $(DESTDIR)$(PREFIX)/bin
cp -r box $(DESTDIR)$(PREFIX)/bin
links:
for u in ${CORE}; do ln -s "$(DESTDIR)$(PREFIX)/bin/box" "$(DESTDIR)$(PREFIX)/bin/$$u"; done
remove:
rm -f $(DESTDIR)$(PREFIX)/bin/box
for u in ${CORE}; do rm -f "$(DESTDIR)$(PREFIX)/bin/$$u"; done
# Utilities
# =========
box.o: prepbox
$(CC) $(CFLAGS) $(NOLINKER) box.c -o box.o
|