Skip to content

Commit

Permalink
Further refininf build process
Browse files Browse the repository at this point in the history
  • Loading branch information
Henrik Karlsson committed Oct 27, 2023
1 parent 86d9229 commit 05717a4
Show file tree
Hide file tree
Showing 22 changed files with 176 additions and 170 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,11 @@ Build and Run
For building and running the `hello` project
```bash
# Build common libraries kernel and hello project
make PROJECT=hello
cd projects/hello
# Build the project
make
# Run the program using QEMU
make qemu PROJECT=hello
make qemu
```

Requirements
Expand Down
25 changes: 16 additions & 9 deletions common/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -21,29 +21,36 @@ ALTC_OBJS=${call SRCS2OBJS, ${ALTC_SRCS}}
S3K_OBJS=${call SRCS2OBJS, ${S3K_SRCS}}
START_OBJS=${call SRCS2OBJS, ${START_SRCS}}

all: ${BUILD}/libplat.a ${BUILD}/libaltc.a ${BUILD}/libs3k.a ${START_OBJS}
TARGETS=${BUILD}/libplat.a ${BUILD}/libaltc.a ${BUILD}/libs3k.a ${START_OBJS}


all: ${TARGETS}
clean:
rm -rf ${TARGETS}

${BUILD}/libplat.a: ${PLAT_OBJS}
echo ${PLAT_OBJS}
@mkdir -p ${@D}
${AR} cr $@ $^
@echo -e "AR\t${@F}"
@${AR} cr $@ $^

${BUILD}/libaltc.a: ${ALTC_OBJS}
@mkdir -p ${@D}
${AR} cr $@ $^
@echo -e "AR\t${@F}"
@${AR} cr $@ $^

${BUILD}/libs3k.a: ${S3K_OBJS}
@mkdir -p ${@D}
${AR} cr $@ $^
@echo -e "AR\t${@F}"
@${AR} cr $@ $^

${BUILD}/%.o: src/%.c
@mkdir -p ${@D}
${CC} -o $@ $< -c ${CFLAGS}
@echo -e "CC\t${@F}"
@${CC} -o $@ $< -c ${CFLAGS}

${BUILD}/%.o: src/%.S
@mkdir -p ${@D}
${CC} -o $@ $< -c ${CFLAGS}
clean:
rm -rf ${BUILD}
@echo -e "CC\t${@F}"
@${CC} -o $@ $< -c ${CFLAGS}

.PHONY: all clean
24 changes: 16 additions & 8 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -44,30 +44,38 @@ OBJS=${patsubst src/%.S, ${BUILD}/${PROGRAM}/%.o, ${S_SRCS}} \
${patsubst src/%.c, ${BUILD}/${PROGRAM}/%.o, ${C_SRCS}}

# Dependency files
DEPS=${patsubst %.o, ${BUILD}/obj/%.d, ${OBJS}}
DEPS=${OBJS:.o=.d}

# Targets
ELF=${BUILD}/${PROGRAM}.elf
BIN=${ELF:.elf=.bin}

all: ${ELF}

all: ${ELF} ${BIN}
elf: ${ELF}
bin: ${BIN}

clean:
rm -f ${ELF} ${OBJS} ${DEPS}

${BUILD}/${PROGRAM}/%.o: src/%.S
@mkdir -p ${@D}
${CC} -o $@ $< -c -MMD ${CFLAGS}
@echo -e "CC\t${@F}"
@${CC} -o $@ $< -c -MMD ${CFLAGS}

${BUILD}/${PROGRAM}/%.o: src/%.c
@mkdir -p ${@D}
${CC} -o $@ $< -c -MMD ${CFLAGS}
@echo -e "CC\t${@F}"
@${CC} -o $@ $< -c -MMD ${CFLAGS}

${ELF}: ${OBJS}
%.elf: ${OBJS}
@mkdir -p ${@D}
${CC} -o $@ ${OBJS} ${LDFLAGS}
@echo -e "CC\t${@F}"
@${CC} -o $@ ${OBJS} ${LDFLAGS}

%.bin: %.elf
@echo -e "OBJCOPY\t${@F}"
@${OBJCOPY} -O binary $< $@

.PHONY: all elf bin da format clean
.PHONY: all common elf bin da format clean

-include ${DEPS}
29 changes: 16 additions & 13 deletions projects/demonstrator/Makefile
Original file line number Diff line number Diff line change
@@ -1,39 +1,42 @@
.POSIX:
export PLATFORM?=qemu_virt
export ROOT=${abspath ../..}
export BUILD=${abspath build}
export S3K_CONF_H=${abspath s3k_conf.h}

include ${ROOT}/common/plat/${PLATFORM}.mk

APPS=app0 app1
APPS=boot app0 app1 monitor crypto uartppp

ELFS=${patsubst %, ${BUILD}/%.elf, kernel ${APPS}}
ELFS=${patsubst %,${BUILD}/%.elf,kernel boot}

all: kernel ${APPS}

clean:
${MAKE} -C ${ROOT}/common clean
${MAKE} -C ${ROOT}/kernel clean
for prog in ${APPS}; do \
@${MAKE} -C ${ROOT}/common clean
@${MAKE} -C ${ROOT}/kernel clean
@for prog in ${APPS}; do \
${MAKE} -f build.mk PROGRAM=$$prog clean; \
done

common:
${MAKE} -C ${ROOT}/common
@${MAKE} -C ${ROOT}/common

kernel: common
${MAKE} -C ${ROOT}/kernel
@${MAKE} -C ${ROOT}/kernel

boot: monitor crypto uartppp
${APPS}:
@${MAKE} -f build.mk PROGRAM=$@

qemu: kernel ${APPS}
ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh
@ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh -serial tcp:localhost:8888,server,nowait

qemu-gdb: kernel ${APPS}
ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh -s -S
@ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh -serial tcp:localhost:8888,server,nowait -gdb tcp::3333 -S

gdb: kernel ${APPS}
ELFS="${ELFS}" ${ROOT}/scripts/gdb.sh
@ELFS="${ELFS}" ${ROOT}/scripts/gdb.sh

${APPS}: common
${MAKE} -f build.mk PROGRAM=$@

.PHONY: all clean qemu kernel common ${APPS}
.PHONY: all clean qemu qemu-gdb gdb kernel common ${APPS}
File renamed without changes.
File renamed without changes.
File renamed without changes.
6 changes: 3 additions & 3 deletions projects/demonstrator/boot/payload.S
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
.section .data

monitor_bin:
.incbin "../build/monitor.bin"
.incbin "build/monitor.bin"
crypto_bin:
.incbin "../build/crypto.bin"
.incbin "build/crypto.bin"
uart_bin:
.incbin "../build/uart.bin"
.incbin "build/uartppp.bin"
end_bin:

monitor_bin_len:
Expand Down
37 changes: 23 additions & 14 deletions projects/demonstrator/build.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,12 @@ PROGRAM?=a
include ${ROOT}/tools.mk
include ${ROOT}/common/plat/${PLATFORM}.mk

SRCS=${wildcard ${PROGRAM}/*.[cS]}
OBJS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.o, ${SRCS}} ${STARTFILES}/start.o
DEPS=${patsubst ${PROGRAM}/%, ${BUILD}/${PROGRAM}/%.d, ${SRCS}}
C_SRCS=${wildcard ${PROGRAM}/*.c}
S_SRCS=${wildcard ${PROGRAM}/*.S}
OBJS=${patsubst %.c, ${BUILD}/%.o, ${C_SRCS}} \
${patsubst %.S, ${BUILD}/%.o, ${S_SRCS}} \
${STARTFILES}/start.o
DEPS=${OBJS:.o=.d}

CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL}
CFLAGS+=-DPLATFORM_${PLATFORM}
Expand All @@ -15,31 +18,37 @@ CFLAGS+=-DSTACK_SIZE=1024
CFLAGS+=-Os -g3
CFLAGS+=-I${COMMON_INC} -include ${S3K_CONF_H}

LDFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL}
LDFLAGS+=-g3
LDFLAGS+=-nostartfiles -nostdlib
LDFLAGS=--nostdlib
LDFLAGS+=-T${PROGRAM}.ld -Tdefault.ld
LDFLAGS+=-Wl,--no-warn-rwx-segments
LDFLAGS+=--no-warn-rwx-segments
LDFLAGS+=-L${COMMON_LIB} -ls3k -laltc -lplat

ELF=${BUILD}/${PROGRAM}.elf
BIN=${ELF:.elf=.bin}

all: ${ELF}
all: ${ELF} ${BIN}

clean:
rm -f ${ELF} ${OBJS} ${DEPS}

${BUILD}/${PROGRAM}/%.S.o: ${PROGRAM}/%.S
${BUILD}/${PROGRAM}/%.o: ${PROGRAM}/%.S
@mkdir -p ${@D}
${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c
@echo -e "CC\t${@F}"
@${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c

${BUILD}/${PROGRAM}/%.c.o: ${PROGRAM}/%.c
${BUILD}/${PROGRAM}/%.o: ${PROGRAM}/%.c
@mkdir -p ${@D}
${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c
@echo -e "CC\t${@F}"
@${CC} -o $@ $< ${CFLAGS} ${INC} -MMD -c

${ELF}: ${OBJS}
%.elf: ${OBJS}
@mkdir -p ${@D}
${CC} -o $@ ${OBJS} ${LDFLAGS} -MMD ${INC}
@echo -e "LD\t${@F}"
@${LD} -o $@ ${OBJS} ${LDFLAGS} ${INC}

%.bin: %.elf
@echo -e "OBJCOPY\t${@F}"
@${OBJCOPY} -O binary $< $@

.PHONY: all elf clean

Expand Down
File renamed without changes.
File renamed without changes.
37 changes: 0 additions & 37 deletions projects/demonstrator/scripts/gdb.sh

This file was deleted.

11 changes: 0 additions & 11 deletions projects/demonstrator/scripts/qemu.sh

This file was deleted.

File renamed without changes.
5 changes: 0 additions & 5 deletions projects/demonstrator/uartppp/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,6 @@ void main(void)
s3k_msg_t msg;
s3k_reply_t reply;

while (1) {
char c = alt_getchar();
alt_putchar(c);
}

char *buf = SHARED0_MEM;

while (1) {
Expand Down
20 changes: 10 additions & 10 deletions projects/hello/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -12,28 +12,28 @@ ELFS=${patsubst %, ${BUILD}/%.elf, kernel ${APPS}}
all: kernel ${APPS}

clean:
${MAKE} -C ${ROOT}/common clean
${MAKE} -C ${ROOT}/kernel clean
for prog in ${APPS}; do \
@${MAKE} -C ${ROOT}/common clean
@${MAKE} -C ${ROOT}/kernel clean
@for prog in ${APPS}; do \
${MAKE} -f build.mk PROGRAM=$$prog clean; \
done

common:
${MAKE} -C ${ROOT}/common
@${MAKE} -C ${ROOT}/common

kernel: common
${MAKE} -C ${ROOT}/kernel
@${MAKE} -C ${ROOT}/kernel

qemu: kernel ${APPS}
ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh
@ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh

qemu-gdb: kernel ${APPS}
ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh -s -S
@ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh -s -S

gdb: kernel ${APPS}
ELFS="${ELFS}" ${ROOT}/scripts/gdb.sh
@ELFS="${ELFS}" ${ROOT}/scripts/gdb.sh

${APPS}: common
${MAKE} -f build.mk PROGRAM=$@
@${MAKE} -f build.mk PROGRAM=$@

.PHONY: all clean qemu kernel common ${APPS}
.PHONY: all clean qemu qemu-gdb gdb kernel common ${APPS}
Loading

0 comments on commit 05717a4

Please sign in to comment.