-
Notifications
You must be signed in to change notification settings - Fork 0
kurt/helios/unified-make-file #127
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: master
Are you sure you want to change the base?
Changes from all commits
c2d7510
a787638
4261e61
89ab663
3d94d28
111c780
6fafb1f
288d21c
563ebb4
daf3ecc
e2e039c
1cb8597
12d9d4d
c8a54e1
9514e56
941aa15
d6852db
0706dc9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -34,6 +34,14 @@ ifneq ($(INCLUDES),) | |
CFLAGS+=$(INCLUDES) | ||
endif | ||
|
||
# Architecture passed from parent Makefile (default to x64 if run standalone) | ||
ARCH ?= x64 | ||
|
||
# Build and Output directories relative to this Makefile | ||
BUILD_DIR = $(ARCH) | ||
OUTPUT_DIR = output | ||
FINAL_TARGET = $(OUTPUT_DIR)/helios_cli | ||
|
||
# local NONSTANDARD libraries to link with | ||
# these MUST be exact filenames, cannot be -l syntax | ||
# for example: | ||
|
@@ -59,13 +67,19 @@ else | |
$(shell find . -type f -name '*.cpp') | ||
endif | ||
|
||
# object files are source files with .c replaced with .o | ||
OBJS=\ | ||
$(SRC:.cpp=.o) \ | ||
# Separate source files by directory | ||
HELIOS_SRC = $(shell find ../Helios -type f -name '*.cpp') | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I admit I've let you flail around a bit with this because I've been too busy to give you proper direction. You've done an amazing job so far with my half-assed comments, I commend you. So what would normally happen in this case is you wouldn't build the helios src files with this makefile, like I said this is the spaghetti you don't really want. This makefile only really needs to track it's own sources and object files, then in order to get HeliosLib into HeliosCli you need to turn HeliosLib into a true lib and link the library in this makefile The Makefile in HeliosLib/ needs to be able to produce a static library out of the code there, on linux this looks like HeliosLib.a or something like that. The reason that I never really bothered with this part is because it doesn't exactly matter but now that you're fixing these makefiles we might as well solve the problem. Here is an example makefile that produces a static lib by using 'ar' to combine all the .obj files together and produce the .a:
I just grabbed this from gpt the part you would be adapting would be the That would be like: LIB = HeliosLib.a And this would also be able to build for x86 or x64.... But here's where things get a little funky... The Embedded Build Yeah, so, HeliosEmbedded also does this same thing of building the src files from the other folder... but that's because I don't know if using ar to make an archive/static lib out of helios then linking that into the HeliosEmbedded entrypoint would cause different results in optimizations for size. Like, if you build a static library the ar tool doesn't discriminate which functions/things to keep. There's no optimization in terms of trimming away useless functions when making a static lib. I don't know if the optimizer would work the same for the avr build if we simply linked HeliosLib.a (in avr arch) with the main.o for the embedded entrypoint. In theory, it should work the same... but I didn't feel like testing it in case it ended up being a waste of time. Anyway sorry if this is a bit of a rant my brain is cooked today but I wanted to try and help you out. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. to be a bit more clear, it absolutely should work fine to build the static lib with avr arch and just link it with the heliosembedded main.o -- I was probably more lazy than worried it wouldn't work the ar tool is just archiving, ie putting all the obj files together into a single archive file. Linking a .a I believe follows the same procedure as .o files. Here I got some more gpt crap:
So the lib/Makefile is like HeliosLib like the one in the above example I gave. Then the app that pulls on the lib is like HeliosCli or HeliosEmbedded:
This above example is slightly tailored, it uses some of the tricks I've shown like the DFILES and it also uses a trick to build the static lib:
This target catches all libs and runs make in the directory of $@ (so the libs folder) on the lib name. So in Helios for example it would run:
Then ../HeliosLib/HeliosLib.a can simply be put at the end of the compiler command like
which would be:
you can interchange LD with g++ in the above example btw. g++ understands if it receives obj files it will just passthrough to LD. |
||
LOCAL_SRC = $(shell find . -type f -name '*.cpp') | ||
|
||
# dependency files are source files with .c replaced with .d | ||
DFILES=\ | ||
$(SRC:.cpp=.d) \ | ||
# Generate object file paths using BUILD_DIR | ||
HELIOS_OBJS = $(patsubst ../Helios/%.cpp,$(BUILD_DIR)/Helios/%.o,$(HELIOS_SRC)) | ||
LOCAL_OBJS = $(patsubst ./%.cpp,$(BUILD_DIR)/%.o,$(LOCAL_SRC)) | ||
OBJS = $(HELIOS_OBJS) $(LOCAL_OBJS) | ||
|
||
# dependency files | ||
HELIOS_DFILES = $(patsubst ../Helios/%.cpp,$(BUILD_DIR)/Helios/%.d,$(HELIOS_SRC)) | ||
LOCAL_DFILES = $(patsubst ./%.cpp,$(BUILD_DIR)/%.d,$(LOCAL_SRC)) | ||
DFILES = $(HELIOS_DFILES) $(LOCAL_DFILES) | ||
|
||
# target dependencies | ||
# this includes any script generated c/h files, | ||
|
@@ -87,12 +101,18 @@ all: $(TARGETS) | |
# unit test target | ||
tests: $(TESTS) | ||
|
||
# target for vortex lib | ||
# target for helios cli | ||
helios: compute_version $(DEPS) | ||
$(CC) $(CFLAGS) $(DEPS) -o $@ $(LLIBS) | ||
@mkdir -p $(OUTPUT_DIR) | ||
$(CC) $(CFLAGS) $(OBJS) -o $(FINAL_TARGET) $(LLIBS) | ||
|
||
# catch-all make target to generate .o and .d files | ||
%.o: %.cpp | ||
# Rules for building object files | ||
$(BUILD_DIR)/Helios/%.o: ../Helios/%.cpp | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. so in theory this shouldn't exist, all building of HeliosLib stuff should be in the makefile that is in that folder |
||
@mkdir -p $(dir $@) | ||
$(CC) $(CFLAGS) -MMD -c $< -o $@ | ||
|
||
$(BUILD_DIR)/%.o: ./%.cpp | ||
@mkdir -p $(dir $@) | ||
$(CC) $(CFLAGS) -MMD -c $< -o $@ | ||
|
||
# catch-all for static libraries in the form of: | ||
|
@@ -107,7 +127,8 @@ FORCE: | |
|
||
# generic clean target | ||
clean: | ||
@$(RM) $(DFILES) $(OBJS) $(TARGETS) $(TESTS) | ||
@$(RM) -rf $(BUILD_DIR) $(OUTPUT_DIR) | ||
@$(RM) -f $(DFILES) $(OBJS) $(TESTS) | ||
|
||
compute_version: | ||
$(eval LATEST_TAG ?= $(shell git fetch --depth=1 origin +refs/tags/*:refs/tags/* &> /dev/null && git tag --list | sort -V | tail -n1)) | ||
|
@@ -121,18 +142,43 @@ compute_version: | |
$(eval HELIOS_BUILD_NUMBER := $(if $(HELIOS_BUILD_NUMBER),$(HELIOS_BUILD_NUMBER),0)) | ||
$(eval HELIOS_VERSION_NUMBER := $(HELIOS_VERSION_MAJOR).$(HELIOS_VERSION_MINOR).$(HELIOS_BUILD_NUMBER)) | ||
|
||
# generate bmps | ||
bmps: | ||
./PatternGenerator/generate_bmps.sh -c | ||
|
||
# generate svg | ||
svgs: bmps | ||
./generate_svgs.sh | ||
./PatternGenerator/generate_svgs.sh | ||
|
||
# generate pngs | ||
pngs: bmps | ||
./generate_pngs.sh | ||
./PatternGenerator/generate_pngs.sh | ||
|
||
# generate pngs | ||
bmps: | ||
./generate_bmps.sh -c | ||
# record tests | ||
record_tests: all | ||
../tests/record_tests.sh | ||
|
||
# record test | ||
record_test: all | ||
../tests/record_test.sh | ||
|
||
# run tests | ||
run_tests: all | ||
../tests/run_tests.sh | ||
|
||
# create_tests | ||
create_tests: all | ||
../tests/create_test.sh | ||
|
||
# export tests | ||
export_tests: all | ||
../tests/export_tests.sh | ||
|
||
# import tests | ||
import_tests: all | ||
../tests/import_tests.sh | ||
|
||
# clean storage | ||
clean_storage: | ||
@echo "Cleaning Helios storage file..." | ||
@$(RM) Helios.storage | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -66,25 +66,36 @@ LLIBS=\ | |
LIBS=\ | ||
$(LLIBS) \ | ||
|
||
# Architecture passed from parent Makefile (default to x64 if run standalone) | ||
ARCH ?= x64 | ||
|
||
# Build and Output directories relative to this Makefile | ||
BUILD_DIR = $(ARCH) | ||
OUTPUT_DIR = output | ||
FINAL_LIB_TARGET = $(OUTPUT_DIR)/helios_lib.a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. oh neat, a static lib, LOL |
||
FINAL_WASM_TARGET = $(OUTPUT_DIR)/helios_wasm.js | ||
FINAL_WASM_BIN_TARGET = $(OUTPUT_DIR)/helios_wasm.wasm | ||
|
||
# source files | ||
# local source files first, other sources after | ||
ifeq ($(OS),Windows_NT) | ||
SRC = $(shell find ../Helios/ -type f -name \\*.cpp) HeliosLib.cpp | ||
HELIOS_SRC = $(shell find ../Helios/ -type f -name \\*.cpp) | ||
LOCAL_SRC = HeliosLib.cpp | ||
else | ||
SRC = $(shell find ../Helios/ -type f -name '*.cpp') HeliosLib.cpp | ||
HELIOS_SRC = $(shell find ../Helios/ -type f -name '*.cpp') | ||
LOCAL_SRC = HeliosLib.cpp | ||
endif | ||
|
||
# object files are source files with .c replaced with .o | ||
OBJS=\ | ||
$(SRC:.cpp=.o) \ | ||
# Generate object file paths using BUILD_DIR | ||
HELIOS_OBJS = $(patsubst ../Helios/%.cpp,$(BUILD_DIR)/Helios/%.o,$(HELIOS_SRC)) | ||
LOCAL_OBJS = $(patsubst %.cpp,$(BUILD_DIR)/%.o,$(LOCAL_SRC)) | ||
OBJS = $(HELIOS_OBJS) $(LOCAL_OBJS) | ||
|
||
# dependency files are source files with .c replaced with .d | ||
DFILES=\ | ||
$(SRC:.cpp=.d) \ | ||
# Generate dependency file paths | ||
HELIOS_DFILES = $(patsubst ../Helios/%.cpp,$(BUILD_DIR)/Helios/%.d,$(HELIOS_SRC)) | ||
LOCAL_DFILES = $(patsubst %.cpp,$(BUILD_DIR)/%.d,$(LOCAL_SRC)) | ||
DFILES = $(HELIOS_DFILES) $(LOCAL_DFILES) | ||
|
||
# target dependencies | ||
# this includes any script generated c/h files, | ||
# the $(LLIBS) list, and the $(OBJS) list | ||
DEPS=\ | ||
$(LLIBS) \ | ||
$(OBJS) \ | ||
|
@@ -94,10 +105,9 @@ TESTS=\ | |
|
||
# target files | ||
ifdef WASM | ||
TARGETS=HeliosLib.js \ | ||
helios.a | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ohhhhhhh I already had a helios.a being generated, well I'm ahead of myself then |
||
TARGETS=$(FINAL_WASM_TARGET) $(FINAL_LIB_TARGET) | ||
else | ||
TARGETS=helios.a | ||
TARGETS=$(FINAL_LIB_TARGET) | ||
endif | ||
|
||
# Default target for 'make' command | ||
|
@@ -108,25 +118,45 @@ tests: $(TESTS) | |
|
||
# force sub-build of wasm | ||
wasm: FORCE | ||
env WASM=1 $(MAKE) | ||
@if command -v em++; then \ | ||
echo "WebAssembly compiler found, building WASM..."; \ | ||
env ARCH=wasm WASM=1 $(MAKE) $(FINAL_WASM_TARGET) $(FINAL_LIB_TARGET); \ | ||
else \ | ||
echo "WebAssembly compiler (em++) not found, skipping WASM build."; \ | ||
mkdir -p $(OUTPUT_DIR); \ | ||
touch $(FINAL_WASM_TARGET); \ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why are these here? If it's skipping the wasm build in this section why mkdir and touch files? |
||
touch $(FINAL_WASM_BIN_TARGET); \ | ||
fi | ||
|
||
# target for helios lib | ||
helios.a: compute_version $(DEPS) | ||
$(FINAL_LIB_TARGET): compute_version $(DEPS) | ||
@mkdir -p $(dir $@) | ||
$(AR) $@ $(DEPS) | ||
@echo "Created $@" | ||
|
||
HeliosLib.js: compute_version $(DEPS) | ||
# target for HeliosLib.js | ||
$(FINAL_WASM_TARGET): compute_version $(DEPS) | ||
@mkdir -p $(dir $@) | ||
$(CC) $(LDFLAGS) $(DEPS) -o $@ $(LLIBS) | ||
|
||
# catch-all make target to generate .o and .d files | ||
%.o: %.cpp | ||
# Rules for building object files | ||
$(BUILD_DIR)/Helios/%.o: ../Helios/%.cpp | ||
@mkdir -p $(dir $@) | ||
$(CC) $(CFLAGS) -MMD -c $< -o $@ | ||
|
||
$(BUILD_DIR)/%.o: %.cpp | ||
@mkdir -p $(dir $@) | ||
$(CC) $(CFLAGS) -MMD -c $< -o $@ | ||
|
||
# Empty rule that forces %.a to run all the time | ||
# Empty rule that forces .a to run all the time | ||
FORCE: | ||
|
||
# generic clean target | ||
clean: | ||
@$(RM) $(DFILES) $(OBJS) $(TARGETS) $(TESTS) HeliosLib.js HeliosLib.wasm | ||
@echo "Cleaning up HeliosLib..." | ||
@$(RM) -rf $(BUILD_DIR) $(OUTPUT_DIR) | ||
@$(RM) -f $(DFILES) $(OBJS) $(TESTS) HeliosLib.js HeliosLib.wasm # Remove old possible output names | ||
@echo "Cleaned HeliosLib!" | ||
|
||
compute_version: | ||
$(eval LATEST_TAG ?= $(shell git fetch --depth=1 origin +refs/tags/*:refs/tags/* &> /dev/null && git tag --list | sort -V | tail -n1)) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
output must also be arch-specific, otherwise say you have x86/x64 you can't build them side by side.
Either the binary name or the output folder needs to reflect the arch.
You could do away with output/ entirely and just dump the binary in the arch directory with the object files, that's kinda fine too.