|
| 1 | +# Makefile for building components of the IVC (Inter-VM Communication) library: kernel driver, user |
| 2 | +# library, python bindings, and demo applications. |
| 3 | + |
| 4 | +# Basic information |
| 5 | +LIB_NAME := ivc |
| 6 | + |
| 7 | +# Architecture and cross-compilation settings |
| 8 | +ARCH ?= arm64 |
| 9 | +CROSS ?= aarch64-linux-musl- |
| 10 | +CCOMP ?= $(CROSS)gcc |
| 11 | +CAR ?= $(CROSS)ar |
| 12 | + |
| 13 | +# Input, output, and kernel dependency directories |
| 14 | +MAKEFILE_DIR := $(dir $(abspath $(lastword $(MAKEFILE_LIST)))) |
| 15 | + |
| 16 | +BUILD_DIR ?= $(MAKEFILE_DIR)build |
| 17 | +INCLUDE_DIR := $(MAKEFILE_DIR)include |
| 18 | + |
| 19 | +ULIB_SRC_DIR := $(MAKEFILE_DIR)ulib |
| 20 | +DEMO_SRC_DIR := $(MAKEFILE_DIR)demo |
| 21 | + |
| 22 | +# Source files and outputs |
| 23 | +ULIB_SRC := $(wildcard $(ULIB_SRC_DIR)/*.c) |
| 24 | +ULIB_OBJ := $(patsubst $(ULIB_SRC_DIR)/%.c,$(BUILD_DIR)/ulib/%.o,$(ULIB_SRC)) |
| 25 | +ULIB_STATIC := $(BUILD_DIR)/lib$(LIB_NAME).a |
| 26 | +ULIB_SHARED := $(BUILD_DIR)/lib$(LIB_NAME).so |
| 27 | + |
| 28 | +DEMO_SRC := $(wildcard $(DEMO_SRC_DIR)/*.c) |
| 29 | +DEMO_BIN := $(patsubst $(DEMO_SRC_DIR)/%.c,$(BUILD_DIR)/demo/%, $(DEMO_SRC)) |
| 30 | + |
| 31 | + |
| 32 | +# Compiler flags |
| 33 | +CFLAGS ?= -I$(INCLUDE_DIR) |
| 34 | +ULIB_CFLAGS ?= $(CFLAGS) -Wall -Wextra -Os -s -Wl,--gc-sections -fPIC |
| 35 | +DEMO_CFLAGS ?= $(CFLAGS) -Wall -Wextra -Os -s -Wl,--gc-sections -static |
| 36 | + |
| 37 | +.PHONY: all ulib demo output_dir clean rebuild |
| 38 | +all: ulib demo |
| 39 | + |
| 40 | +ulib: output_dir $(ULIB_STATIC) $(ULIB_SHARED) |
| 41 | +demo: output_dir $(DEMO_BIN) |
| 42 | + |
| 43 | +$(ULIB_STATIC): $(ULIB_OBJ) |
| 44 | + $(CAR) rcs $@ $^ |
| 45 | + |
| 46 | +$(ULIB_SHARED): $(ULIB_OBJ) |
| 47 | + $(CCOMP) -shared -o $@ $^ |
| 48 | + |
| 49 | +$(BUILD_DIR)/ulib/%.o: $(ULIB_SRC_DIR)/%.c |
| 50 | + $(CCOMP) $(ULIB_CFLAGS) -c $< -o $@ |
| 51 | + |
| 52 | +$(BUILD_DIR)/demo/%: $(DEMO_SRC_DIR)/%.c $(ULIB_STATIC) |
| 53 | + $(CCOMP) $(DEMO_CFLAGS) -o $@ $< -L$(BUILD_DIR) -l$(LIB_NAME) |
| 54 | + |
| 55 | +output_dir: |
| 56 | + @mkdir -p $(BUILD_DIR)/ulib |
| 57 | + @mkdir -p $(BUILD_DIR)/demo |
| 58 | + |
| 59 | +clean: |
| 60 | + rm -rf $(BUILD_DIR) |
| 61 | + |
| 62 | +rebuild: clean all |
0 commit comments