-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathMakefile
More file actions
37 lines (29 loc) · 984 Bytes
/
Makefile
File metadata and controls
37 lines (29 loc) · 984 Bytes
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
CC = gcc
CFLAGS = -Wall -Wextra -O2 -fPIC -Iinclude
LDFLAGS = -shared
EXAMPLE_LDFLAGS = -Wl,-rpath=$(BUILD_DIR) -L$(BUILD_DIR) -lplinux
BUILD_DIR = build
SRC_DIR = src
INCLUDE_DIR = include
EXAMPLE_DIR = example
LIB_NAME = libplinux.so
SRC_FILES = $(wildcard $(SRC_DIR)/*.c)
OBJ_FILES = $(patsubst $(SRC_DIR)/%.c,$(BUILD_DIR)/%.o,$(SRC_FILES))
EXAMPLE_SRC = $(wildcard $(EXAMPLE_DIR)/*.c)
EXAMPLE_BINS = $(patsubst $(EXAMPLE_DIR)/%.c,$(EXAMPLE_DIR)/%,$(EXAMPLE_SRC))
all: $(BUILD_DIR)/$(LIB_NAME) $(EXAMPLE_BINS)
# Compilar objetos
$(BUILD_DIR)/%.o: $(SRC_DIR)/%.c
@mkdir -p $(BUILD_DIR)
$(CC) $(CFLAGS) -c $< -o $@
# Criar a biblioteca compartilhada
$(BUILD_DIR)/$(LIB_NAME): $(OBJ_FILES)
$(CC) $(LDFLAGS) -o $@ $^
# Compilar os exemplos linkando com a lib
$(EXAMPLE_DIR)/%: $(EXAMPLE_DIR)/%.c $(BUILD_DIR)/$(LIB_NAME)
@mkdir -p $(EXAMPLE_DIR)
$(CC) $(CFLAGS) $< -o $@ $(EXAMPLE_LDFLAGS)
clean:
rm -rf $(BUILD_DIR)
rm example/example example/process
.PHONY: all clean