Skip to content
This repository was archived by the owner on Jan 14, 2026. It is now read-only.

Commit 31ef27d

Browse files
committed
fix Makefile's user elf
1 parent 204c9fd commit 31ef27d

1 file changed

Lines changed: 27 additions & 3 deletions

File tree

Makefile

Lines changed: 27 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,18 @@ SOURCES = $(shell find $(SRC_KERNEL) -name "*.c")
3737
ASM_SOURCES = $(shell find $(SRC_KERNEL) -name "*.asm")
3838
OBJECTS = $(shell printf "%s\n" $(patsubst $(SRC_KERNEL)/%.c, $(K_OUT_DIR)/%.o, $(SOURCES)) $(patsubst $(SRC_KERNEL)/%.asm, $(K_OUT_DIR)/%.o, $(ASM_SOURCES)) | sort -u)
3939

40-
USER_SOURCES = $(shell find $(SRC_USER) -name "*.c")
40+
USER_SOURCES = $(shell find $(SRC_USER) -name "*.c" \! -name "syscall.c")
4141
USER_OBJECTS = $(shell printf "%s\n" $(patsubst $(SRC_USER)/%.c, $(OUT_DIR)/usr/%.o, $(USER_SOURCES)) | sort -u)
4242
USER_ELFS = $(shell printf "%s\n" $(patsubst $(SRC_USER)/%.c, $(OUT_DIR)/usr/%.elf, $(USER_SOURCES)) | sort -u)
4343

44+
SRC_APPS = apps
45+
APP_OUT_DIR = $(OUT_DIR)/apps
46+
APP_SOURCES = $(shell if [ -d "$(SRC_APPS)" ]; then find $(SRC_APPS) -name "*.c"; fi)
47+
APP_OBJECTS = $(shell printf "%s\n" $(patsubst $(SRC_APPS)/%.c, $(APP_OUT_DIR)/%.o, $(APP_SOURCES)) | sort -u)
48+
APP_ELFS = $(shell printf "%s\n" $(patsubst $(SRC_APPS)/%.c, $(APP_OUT_DIR)/%.elf, $(APP_SOURCES)) | sort -u)
49+
50+
ALL_USER_ELFS = $(USER_ELFS) $(APP_ELFS)
51+
4452
BIN_LIB_DIR = $(OUT_DIR)/lib
4553
USER_LDFLAGS ?= -L$(BIN_LIB_DIR) -lc
4654

@@ -108,10 +116,24 @@ $(OUT_DIR)/usr/%.o: $(SRC_USER)/%.c
108116
@mkdir -p $(dir $@)
109117
@$(CC) $(CFLAGS) -D_FORTIFY_SOURCE=0 -fno-builtin -I$(BIN_LIB_DIR)/targ-include -c $< -o $@
110118

119+
$(APP_OUT_DIR)/%.o: $(SRC_APPS)/%.c
120+
@mkdir -p $(dir $@)
121+
@$(CC) $(CFLAGS) -D_FORTIFY_SOURCE=0 -fno-builtin -I$(BIN_LIB_DIR)/targ-include -c $< -o $@
122+
123+
124+
user: lib $(ALL_USER_ELFS) $(APP_ELFS)
125+
@echo "Built user ELFs: $(ALL_USER_ELFS)"
126+
111127

112-
user: lib $(USER_ELFS)
113-
@echo "Built user ELFs: $(USER_ELFS)"
114128

129+
$(APP_OUT_DIR)/%.elf: $(APP_OUT_DIR)/%.o
130+
@mkdir -p $(dir $@)
131+
@echo "Linking app ELF: $@"
132+
@if [ -f "$(BIN_LIB_DIR)/libc.a" ]; then \
133+
$(CC) -nostdlib -static $< $(USER_LDFLAGS) -o $@; \
134+
else \
135+
$(CC) -nostdlib -static $< -o $@; \
136+
fi
115137

116138
$(OUT_DIR)/user/%.elf: $(OUT_DIR)/user/%.o
117139
@mkdir -p $(dir $@)
@@ -176,9 +198,11 @@ $(EXT2_IMG): $(KERNEL)
176198
@echo "Creating FAT16 filesystem image..."
177199
@mkdir -p bin/fs_tmp/kernel/fonts
178200
@mkdir -p bin/fs_tmp/usr
201+
@mkdir -p bin/fs_tmp/apps
179202
@mkdir -p bin/fs_tmp/lib
180203
@cp -f $(FONTS) bin/fs_tmp/kernel/fonts/ 2>/dev/null || true
181204
@cp -f bin/usr/*.elf bin/fs_tmp/usr/ 2>/dev/null || true
205+
@cp -f bin/apps/*.elf bin/fs_tmp/apps/ 2>/dev/null || true
182206
@cp -f bin/lib/* bin/fs_tmp/lib/ 2>/dev/null || true
183207
@find bin -type f \
184208
-not -name "*.o" \

0 commit comments

Comments
 (0)