apps: Add support for C++ apps alongside C ones

This commit is contained in:
apio 2022-11-09 12:01:48 +01:00
parent b6f2b41f1f
commit d1dea3f1d6
2 changed files with 20 additions and 6 deletions

View File

@ -1,24 +1,32 @@
APPS := init sh uname uptime hello ps ls args cat stat su session date mkdir screen
C_APPS := init sh uname uptime hello ps ls args cat stat su session date mkdir screen
CXX_APPS := hello-cpp
APPS_DIR := $(LUNA_ROOT)/apps
APPS_SRC := $(APPS_DIR)/src
APPS_BIN := $(APPS_DIR)/bin
REAL_APPS := $(patsubst %, $(APPS_BIN)/%, $(APPS))
C_APPS_PATH := $(patsubst %, $(APPS_BIN)/%, $(C_APPS))
CXX_APPS_PATH := $(patsubst %, $(APPS_BIN)/%, $(CXX_APPS))
CFLAGS := -Wall -Wextra -Werror -Os -fno-asynchronous-unwind-tables -ffunction-sections -fdata-sections -Wl,--gc-sections
CXXFLAGS := -fno-exceptions
$(APPS_BIN)/%: $(APPS_SRC)/%.c
@mkdir -p $(@D)
@$(CC) $(CFLAGS) -o $@ $^
@echo " CC $^"
build: $(REAL_APPS)
$(APPS_BIN)/%: $(APPS_SRC)/%.cpp
@mkdir -p $(@D)
@$(CXX) $(CFLAGS) $(CXXFLAGS) -o $@ $^
@echo " CXX $^"
install: $(REAL_APPS)
build: $(C_APPS_PATH) $(CXX_APPS_PATH)
install: $(C_APPS_PATH) $(CXX_APPS_PATH)
@mkdir -p $(LUNA_ROOT)/initrd/bin
@cp $(REAL_APPS) $(LUNA_ROOT)/initrd/bin
@echo " INSTALL $(REAL_APPS)"
@cp $(C_APPS_PATH) $(CXX_APPS_PATH) $(LUNA_ROOT)/initrd/bin
@echo " INSTALL $(C_APPS_PATH) $(CXX_APPS_PATH)"
@chmod a+s $(LUNA_ROOT)/initrd/bin/su
clean:

6
apps/src/hello-cpp.cpp Normal file
View File

@ -0,0 +1,6 @@
#include <cstdio>
int main()
{
printf("Well hello world!\n");
}