Skip to content

Commit a17d989

Browse files
committed
Improve build tracking for C source changes
- Add @external_resource declarations for all C files so mix compile detects changes without needing 'mix clean' first - Add -MMD -MP flags to Makefile for automatic header dependency tracking - Clean .d files in 'make clean' target
1 parent 21f5bf8 commit a17d989

2 files changed

Lines changed: 11 additions & 2 deletions

File tree

Makefile

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,10 @@ endif
138138

139139
$(BUILD)/%.o: c_src/%.c
140140
@echo " CC $(notdir $@)"
141-
$(CC) -c $(ERL_CFLAGS) $(CFLAGS) -o $@ $<
141+
$(CC) -c $(ERL_CFLAGS) $(CFLAGS) -MMD -MP -o $@ $<
142+
143+
# Include dependency files for automatic header tracking
144+
-include $(OBJ:.o=.d)
142145

143146
$(LIB_NAME): $(OBJ)
144147
@echo " LD $(notdir $@)"
@@ -152,7 +155,7 @@ $(PREFIX) $(BUILD):
152155
mkdir -p $@
153156

154157
clean:
155-
$(RM) $(LIB_NAME) $(ARCHIVE_NAME) $(OBJ)
158+
$(RM) $(LIB_NAME) $(ARCHIVE_NAME) $(OBJ) $(OBJ:.o=.d)
156159

157160
.PHONY: all clean
158161

lib/exqlite/sqlite3_nif.ex

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ defmodule Exqlite.Sqlite3NIF do
44
should be avoided unless you are aware of what you are doing.
55
"""
66

7+
# Track C source files so Mix recompiles when they change
8+
@external_resource "c_src/sqlite3_nif.c"
9+
@external_resource "c_src/sqlite3.c"
10+
@external_resource "c_src/sqlite3.h"
11+
@external_resource "c_src/sqlite3ext.h"
12+
713
@compile {:autoload, false}
814
@on_load {:load_nif, 0}
915

0 commit comments

Comments
 (0)