os-workshop

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

commit 3f12e2c54bdd2710e6d1c3553e6338ff51d1b538
parent fd021b20b3b0d43830ca8e501f400f30b53f7814
Author: Brian Swetland <swetland@frotz.net>
Date:   Wed, 11 May 2022 18:27:35 -0700

build: small improvements and some documentation

- modules now include libNAME/inc for libraries they depend on
- libraries now automatically include their own libNAME/inc
- add some documentation for the build system

Diffstat:
Adocs/build-system.md | 49+++++++++++++++++++++++++++++++++++++++++++++++++
Mmake/lib.mk | 11++++++-----
Mmake/rules.mk | 3++-
Mreadme.md | 2++
4 files changed, 59 insertions(+), 6 deletions(-)

diff --git a/docs/build-system.md b/docs/build-system.md @@ -0,0 +1,49 @@ + +# Build System Notes + +Define projects in `project/NAME.lib.mk` (for libraries) or `project/NAME.app.mk` (for executables) + +## Common Module Parameters + +`MOD_NAME`: Name of the project. Must be unique. +Libraries must be named such that `libNAME/inc` is their include directory and their generated library will be `out/libNAME.a` + +`MOD_SRC`: List of source files (`.c` or `.S`). Paths must be relative to the top of the project. + +`MOD_LIB`: List of libraries the module depends on. Bare library name, for example `c` for `libc`, etc. + +## Application Parameters + +`MOD_LDSCRIPT`: alternate linker script + +`MOD_QEMU_FB`: If defined, this when `make run.NAME` is invoked to run this module under Qemu, the framebuffer will be enabled. + +## Application Build Outputs + +`out/NAME/...`: Intermediate files (`.o`, `.d`, etc) + +`out/NAME.elf`: ELF binary with full symbols, debug info, etc + +`out/NAME.bin`: Raw binary file for loading directly into memory + +`out/NAME.lst`: Disassembly listing (handy for debugging) + +## Library Build Outputs + +`out/libNAME/...`: Intermediate files + +`out/libNAME.a`: Static library + +## Sample Project + +```make +# project/mandelbrot-fb.app.mk + +MOD_NAME := mandelbrot-fb +MOD_SRC := hw/src/start.S misc/mandelbrot-fb.c +MOD_SRC += hw/src/debug-printf.c hw/src/debug-io.c +MOD_LIB := c +MOD_QEMU_FB := yes + +include make/app.mk +``` diff --git a/make/lib.mk b/make/lib.mk @@ -2,16 +2,17 @@ ## Licensed under the Apache License, Version 2.0 MOD_DIR := $(BUILD)/lib$(MOD_NAME) -MOD_LIB := $(BUILD)/lib$(MOD_NAME).a +MOD_LIB += $(MOD_NAME) +MOD_ALIB := $(BUILD)/lib$(MOD_NAME).a -ALL += $(MOD_LIB) +ALL += $(MOD_ALIB) include make/rules.mk -$(MOD_LIB): $(MOD_DIR)/build.opts +$(MOD_ALIB): $(MOD_DIR)/build.opts -$(MOD_LIB): _OBJ := $(MOD_OBJ) -$(MOD_LIB): $(MOD_OBJ) $(MOD_DIR)/build.opts +$(MOD_ALIB): _OBJ := $(MOD_OBJ) +$(MOD_ALIB): $(MOD_OBJ) $(MOD_DIR)/build.opts @$(info linking $@) @rm -f $@ $(V)$(XAR) -crs $@ -o $@ $(_OBJ) diff --git a/make/rules.mk b/make/rules.mk @@ -4,7 +4,8 @@ # Todo: check for missing inputs, duplicate module names, etc # Assemble compile and link flags. -MOD_CFLAGS := $(ARCHFLAGS) $(CFLAGS) $(patsubst %,-I%,$(MOD_INC)) +MOD_CFLAGS := $(ARCHFLAGS) $(CFLAGS) +MOD_CFLAGS += $(patsubst %,-I%,$(MOD_INC)) $(patsubst %,-Ilib%/inc,$(MOD_LIB)) MOD_LDFLAGS := $(ARCHFLAGS) -Wl,--gc-sections # Generate objects from sources. diff --git a/readme.md b/readme.md @@ -5,4 +5,6 @@ ### [Hardware Setup Instructions](docs/hardware-setup.md) +### [Build System Documentation](docs/build-system.md) +