Skip to content

Commit

Permalink
Fixes to makefile and gdb script
Browse files Browse the repository at this point in the history
  • Loading branch information
HAKarlsson committed Oct 29, 2023
1 parent 067cfa8 commit 5ee49c2
Show file tree
Hide file tree
Showing 15 changed files with 190 additions and 191 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
export ROOT=${abspath .}


PROJECTS=projects/hello projects/trapped projects/ping-pong
PROJECTS:=projects/hello projects/trapped projects/ping-pong
PLATFORM?=qemu_virt

include tools.mk
Expand Down
33 changes: 18 additions & 15 deletions common/Makefile
Original file line number Diff line number Diff line change
@@ -1,29 +1,32 @@
.POSIX:

include plat/${PLATFORM}.mk
BUILD=build/${PLATFORM}

include ${ROOT}/tools.mk

CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL}
CFLAGS+=-DPLATFORM_${PLATFORM}
CFLAGS+=-Os
CFLAGS+=-flto -ffat-lto-objects
CFLAGS+=-nostdlib -Iinc
# CFLAGS
CFLAGS:=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} \
-DPLATFORM_${PLATFORM} \
-Os -flto -ffat-lto-objects \
-nostdlib -Iinc \

BUILD :=build/${PLATFORM}
SRCS2OBJS=${patsubst src/%.S, ${BUILD}/%.o, ${filter %.S, ${1}}} \
${patsubst src/%.c, ${BUILD}/%.o, ${filter %.c, ${1}}}
${patsubst src/%.c, ${BUILD}/%.o, ${filter %.c, ${1}}}

ALTC_SRCS=${wildcard src/altc/*.[cS]}
S3K_SRCS=${wildcard src/s3k/*.[cS]}
START_SRCS=${wildcard src/start/*.S}
ALTC_SRCS :=${wildcard src/altc/*.[cS]}
S3K_SRCS :=${wildcard src/s3k/*.[cS]}
START_SRCS:=${wildcard src/start/*.S}

PLAT_OBJS=${call SRCS2OBJS, ${PLAT_SRCS}}
ALTC_OBJS=${call SRCS2OBJS, ${ALTC_SRCS}}
S3K_OBJS=${call SRCS2OBJS, ${S3K_SRCS}}
START_OBJS=${call SRCS2OBJS, ${START_SRCS}}
PLAT_OBJS :=${call SRCS2OBJS, ${PLAT_SRCS}}
ALTC_OBJS :=${call SRCS2OBJS, ${ALTC_SRCS}}
S3K_OBJS :=${call SRCS2OBJS, ${S3K_SRCS}}
START_OBJS:=${call SRCS2OBJS, ${START_SRCS}}

TARGETS=${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}
Expand Down
6 changes: 3 additions & 3 deletions common/plat/qemu_virt.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export ABI=lp64
export CMODEL=medany
export QEMU_MACHINE=virt
export QEMU_SMP=4
export COMMON_INC=${ROOT}/common/inc
export COMMON_LIB=${ROOT}/common/build/${PLATFORM}
export STARTFILES=${ROOT}/common/build/${PLATFORM}/start
export COMMON_INC:=${ROOT}/common/inc
export COMMON_LIB:=${ROOT}/common/build/${PLATFORM}
export STARTFILES:=${ROOT}/common/build/${PLATFORM}/start
PLAT_SRCS=src/drivers/uart/ns16550a.c src/drivers/time.c
6 changes: 3 additions & 3 deletions common/plat/sifive_unleashed.mk
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ export ABI=lp64
export CMODEL=medany
export QEMU_MACHINE=sifive_u
export QEMU_SMP=5
export COMMON_INC=${ROOT}/common/inc
export COMMON_LIB=${BUILD}/common
export STARTFILES=${BUILD}/common/start
export COMMON_INC:=${ROOT}/common/inc
export COMMON_LIB:=${ROOT}/common/build/${PLATFORM}
export STARTFILES:=${ROOT}/common/build/${PLATFORM}/start
PLAT_SRCS=src/drivers/uart/sifive.c src/drivers/time.c
61 changes: 30 additions & 31 deletions kernel/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,53 +2,52 @@
.POSIX:

# Kernel basename
ROOT=..
PROGRAM?=kernel

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

# CC flags
CFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL}
CFLAGS+=-DPLATFORM_${PLATFORM}
CFLAGS+=-std=c11
CFLAGS+=-Os -g3
CFLAGS+=-Wall -Wextra -Werror
CFLAGS+=-Wno-unused-parameter
CFLAGS+=-Wshadow -fno-common
CFLAGS+=-Wno-builtin-declaration-mismatch
CFLAGS+=-fno-stack-protector
CFLAGS+=-flto

# Include files and directories
CFLAGS+=-include ${S3K_CONF_H}
CFLAGS+=-Iinc -I${COMMON_INC}
CFLAGS:=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} \
-DPLATFORM_${PLATFORM} \
-std=c11 \
-Os -g3 \
-Wall -Wextra -Werror \
-Wno-unused-parameter \
-Wshadow -fno-common \
-Wno-builtin-declaration-mismatch \
-fno-stack-protector \
-flto \
-include ${S3K_CONF_H} \
-Iinc -I${COMMON_INC}

# LD flags
LDFLAGS=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL}
LDFLAGS+=-Tlinker.ld
LDFLAGS+=-nostartfiles -ffreestanding
LDFLAGS+=-flto -fwhole-program
LDFLAGS+=-Wl,--no-warn-rwx-segment
LDFLAGS+=-Wl,--gc-sections
LDFLAGS+=--specs=nosys.specs
LDFLAGS+=-ffunction-sections -fdata-sections
LDFLAGS+=-L${COMMON_LIB}
LDFLAGS+=-laltc -lplat
LDFLAGS:=-march=${ARCH} -mabi=${ABI} -mcmodel=${CMODEL} \
-Tlinker.ld \
-nostartfiles -ffreestanding \
-flto -fwhole-program \
-Wl,--no-warn-rwx-segment \
-Wl,--gc-sections \
--specs=nosys.specs \
-ffunction-sections -fdata-sections \
-L${COMMON_LIB} \
-laltc -lplat

# Source files
S_SRCS=${wildcard src/*.S}
C_SRCS=${wildcard src/*.c}
S_SRCS:=${wildcard src/*.S}
C_SRCS:=${wildcard src/*.c}

# Object files
OBJS=${patsubst src/%.S, ${BUILD}/${PROGRAM}/%.o, ${S_SRCS}} \
${patsubst src/%.c, ${BUILD}/${PROGRAM}/%.o, ${C_SRCS}}
OBJS:=${patsubst src/%.S, ${BUILD}/${PROGRAM}/%.o, ${S_SRCS}} \
${patsubst src/%.c, ${BUILD}/${PROGRAM}/%.o, ${C_SRCS}}

# Dependency files
DEPS=${OBJS:.o=.d}
DEPS:=${OBJS:.o=.d}

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

all: ${ELF} ${BIN}
elf: ${ELF}
Expand Down
10 changes: 5 additions & 5 deletions projects/demonstrator/Makefile
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
.POSIX:

export PLATFORM?=qemu_virt
export ROOT=${abspath ../..}
export BUILD=${abspath build}
export S3K_CONF_H=${abspath s3k_conf.h}
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=boot app0 app1 monitor crypto uartppp

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

all: kernel ${APPS}

Expand Down
53 changes: 26 additions & 27 deletions projects/demonstrator/build.mk
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
.POSIX:

BUILD?=build
PROGRAM?=a
BUILD ?=build
PROGRAM ?=a

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

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}
CFLAGS+=-nostdlib
CFLAGS+=-DSTACK_SIZE=1024
CFLAGS+=-Os -g3 -flto
CFLAGS+=-I${COMMON_INC} -include ${S3K_CONF_H}

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

ELF=${BUILD}/${PROGRAM}.elf
BIN=${ELF:.elf=.bin}
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} \
-DPLATFORM_${PLATFORM} \
-nostdlib \
-DSTACK_SIZE=1024 \
-Os -g3 -flto \
-I${COMMON_INC} -include ${S3K_CONF_H}

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

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

all: ${ELF} ${BIN}

Expand All @@ -50,7 +50,6 @@ ${BUILD}/${PROGRAM}/%.o: ${PROGRAM}/%.c
%.bin: %.elf
${OBJCOPY} -O binary $< $@

.PHONY: all elf clean
.PHONY: all clean

-include ${DEPS}

10 changes: 5 additions & 5 deletions projects/hello/Makefile
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
export PLATFORM?=qemu_virt
export ROOT=${abspath ../..}
export BUILD=${abspath build}
export S3K_CONF_H=${abspath s3k_conf.h}
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

Expand All @@ -28,7 +28,7 @@ qemu: kernel ${APPS}
@ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh

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

gdb: kernel ${APPS}
@ELFS="${ELFS}" ${ROOT}/scripts/gdb.sh
Expand Down
53 changes: 26 additions & 27 deletions projects/hello/build.mk
Original file line number Diff line number Diff line change
@@ -1,34 +1,34 @@
.POSIX:

BUILD?=build
PROGRAM?=a
BUILD ?=build
PROGRAM ?=a

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

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}
CFLAGS+=-nostdlib
CFLAGS+=-DSTACK_SIZE=1024
CFLAGS+=-Os -g3 -flto
CFLAGS+=-I${COMMON_INC} -include ${S3K_CONF_H}

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

ELF=${BUILD}/${PROGRAM}.elf
BIN=${ELF:.elf=.bin}
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} \
-DPLATFORM_${PLATFORM} \
-nostdlib \
-DSTACK_SIZE=1024 \
-Os -g3 -flto \
-I${COMMON_INC} -include ${S3K_CONF_H}

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

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

all: ${ELF} ${BIN}

Expand All @@ -50,7 +50,6 @@ ${BUILD}/${PROGRAM}/%.o: ${PROGRAM}/%.c
%.bin: %.elf
${OBJCOPY} -O binary $< $@

.PHONY: all elf clean
.PHONY: all clean

-include ${DEPS}

12 changes: 6 additions & 6 deletions projects/ping-pong/Makefile
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
export PLATFORM?=qemu_virt
export ROOT=${abspath ../..}
export BUILD=${abspath build}
export S3K_CONF_H=${abspath s3k_conf.h}
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

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

all: kernel ${APPS}

Expand All @@ -28,7 +28,7 @@ qemu: kernel ${APPS}
@ELFS="${ELFS}" ${ROOT}/scripts/qemu.sh

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

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

0 comments on commit 5ee49c2

Please sign in to comment.