-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfigure
executable file
·66 lines (52 loc) · 1.33 KB
/
configure
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
#!/bin/bash
# Variables
CC=gcc
CFLAGS="-Wall -Wextra -pedantic -std=c99"
LDFLAGS="-lcurl"
TARGET="bin/csvToJSON"
SRC="src/csvToJSON.c src/csvToJSON_lib.c"
TEST_TARGET="bin/test_csvToJSON"
TEST_SRC="src/test_csvToJSON.c src/csvToJSON_lib.c"
# Function to check for the existence of a program
check_program() {
command -v $1 >/dev/null 2>&1 || {
echo >&2 "$1 is required but it's not installed. Aborting."
exit 1
}
}
# Check for gcc
check_program gcc
# Check for curl development libraries
check_program curl-config
# Get curl compiler and linker flags
CURL_CFLAGS=$(curl-config --cflags)
CURL_LDFLAGS="" #$(curl-config --libs)
# Create Makefile
cat <<EOL >Makefile
# Makefile generated by configure script
# Variables
CC = $CC
CFLAGS = $CFLAGS $CURL_CFLAGS
LDFLAGS = $LDFLAGS $CURL_LDFLAGS
TARGET = $TARGET
SRC = $SRC
TEST_TARGET = $TEST_TARGET
TEST_SRC = $TEST_SRC
# Default target
all: \$(TARGET) \$(TEST_TARGET)
# Build target
\$(TARGET): \$(SRC)
\$(CC) \$(CFLAGS) -o \$(TARGET) \$(SRC) \$(LDFLAGS)
# Build test target
\$(TEST_TARGET): \$(TEST_SRC)
\$(CC) \$(CFLAGS) -o \$(TEST_TARGET) \$(TEST_SRC) \$(LDFLAGS)
# Run tests
test: \$(TEST_TARGET)
./\$(TEST_TARGET)
# Clean target
clean:
rm -f \$(TARGET) \$(TEST_TARGET)
# Phony targets
.PHONY: all clean test
EOL
echo "Configuration complete. You can now run 'make' to build the program."