APPS := init sh uname uptime hello ps ls args cat stat su session date mkdir screen

APPS_DIR := $(LUNA_ROOT)/apps
APPS_SRC := $(APPS_DIR)/src
APPS_BIN := $(APPS_DIR)/bin

REAL_APPS := $(patsubst %, $(APPS_BIN)/%, $(APPS))

CFLAGS := -Wall -Wextra -Werror -Os -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -Wl,--gc-sections

$(APPS_BIN)/%: $(APPS_SRC)/%.c
	@mkdir -p $(@D)
	@$(CC) $(CFLAGS) -o $@ $^
	@echo "  CC $^"

build: $(REAL_APPS)

install: $(REAL_APPS)
	@mkdir -p $(LUNA_ROOT)/initrd/bin
	@cp $(REAL_APPS) $(LUNA_ROOT)/initrd/bin
	@echo "  INSTALL $(REAL_APPS)"
	@chmod a+s $(LUNA_ROOT)/initrd/bin/su

clean:
	rm -f $(APPS_BIN)/*