aboutsummaryrefslogtreecommitdiff
path: root/configure
blob: e8cdbae547da01408165e83bbe6b9f3fd7842530 (plain)
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
#!/bin/bash

# These are the project-specific variables

EXECUTABLE="dmtool"

# e.g., foo.so
LIBRARY=

# List of libs as given to pkg-config
LIBS=

CFLAGS="-c -Wall -fPIC -std=c++20"

LDFLAGS=

SOURCE_DIR="src"

EXTRAS="
parsed: parser/scrapeToJson.py parser/utils.py
	python parser/scrapeToJson.py
	touch parsed/
"

INSTALL="
install: \$(EXECUTABLE) parsed
	install -d \$(DESTDIR)\$(PREFIX)/share/dmtool/
	cp -r parsed/* \$(DESTDIR)\$(PREFIX)/share/dmtool/
	install -d \$(DESTDIR)\$(PREFIX)/bin/
	install -m 755 \$(EXECUTABLE) \$(DESTDIR)\$(PREFIX)/bin/
	install -m 644 src/dmtool.bash \$(pkg-config --variable=completionsdir bash-completion)/dmtool
"

# Below here shouldn't need editing

SOURCES=`ls $SOURCE_DIR/*.cc | tr '\n' ' '`

PKG_CONFIG_CFLAGS=
PKG_CONFIG_LIBS=
if [ -n "$LIBS" ]; then
    PKG_CONFIG_CFLAGS='`pkg-config $(LIBS) --cflags`'
    PKG_CONFIG_LIBS='`pkg-config $(LIBS) --libs`'
fi

ALL="all: \$(SOURCES)"

LIBRULE=
if [ -n "$LIBRARY" ]; then
    LIBRULE="
\$(LIBRARY): \$(OBJECTS)
	\$(CC) \$(OBJECTS) -shared -o \$@ \$(LDFLAGS) $PKG_CONFIG_LIBS
"
    ALL="$ALL \$(LIBRARY)"
fi

EXERULE=
if [ -n "$EXECUTABLE" ]; then
    EXERULE="
\$(EXECUTABLE): \$(OBJECTS)
	\$(CC) \$(OBJECTS) -o \$@ \$(LDFLAGS) $PKG_CONFIG_LIBS
"
    ALL="$ALL \$(EXECUTABLE)"
fi

ORULES=$(for cc in `ls $SOURCE_DIR/*.cc`; do g++ -MM -MT `cut -d'.' -f-1 <<< $cc`.o $cc; echo -e "\t"'$(CC) $(CFLAGS) $< -o $@ '"$PKG_CONFIG_CFLAGS\n"; done)

cat << EOF > Makefile
CC=g++
LIBS=$LIBS
CFLAGS=$CFLAGS
LDFLAGS=$LDFLAGS
SOURCES=$SOURCES
OBJECTS=\$(SOURCES:.cc=.o)
LIBRARY=$LIBRARY
EXECUTABLE=$EXECUTABLE
ifeq (\$(PREFIX),)
    PREFIX := /usr
endif

$ALL
$EXTRAS$INSTALL$LIBRULE$EXERULE

$ORULES

clean:
	rm -f $SOURCE_DIR/*.o \$(LIBRARY) \$(EXECUTABLE)
EOF