Skip to content
Open
18 changes: 17 additions & 1 deletion examples/rules.mk
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,25 @@ else
include $(OPENCM3_DIR)/mk/genlink-rules.mk
endif

# Find libopencm3 library folder
# this tries to match LIBNAME to manufacturer or manufacturer/series folder in lib/
# eg. LIBNAME=lm3s LIBFOLDER=lib/lm3s or LIBNAME=stm32f7 LIBFOLDER=lib/stm32/f7
DIR=$(notdir $(subst /.,,$(wildcard $1/*/.)))
LIBFOLDER=lib/$(strip \
$(foreach M,$(filter-out usb ethernet dispatch,$(call DIR,$(OPENCM3_DIR)/lib)), \
$(if $(subst opencm3_$M,,$(LIBNAME)),\
$(foreach S,$(call DIR,$(OPENCM3_DIR)/lib/$(M)), \
$(if $(subst opencm3_$M$S,,$(LIBNAME)),,$M/$S)), \
$M)))
# exceptions
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

definitely not interested in this one. I've had enough rpoblems with people trying to pick and choose things, and reportings bugs when all they really needed to do was just run "make" once in the top and everythign would have been fine. This relies far too much on knowledge of the build system and file structure within the library, which should be treated as a simple .a dependency. It's a submodule for exactly that reason, just build it once, move on.

ifeq ($(LIBFOLDER),lib/lpc43xx)
LIBFOLDER=lib/lpc43xx/m4
endif

# Build libopencm3-lib if it does exists
$(OPENCM3_DIR)/lib/lib$(LIBNAME).a:
$(warning $(LIBNAME).a not found, attempting to rebuild in $(OPENCM3_DIR))
$(MAKE) -C $(OPENCM3_DIR)
$(MAKE) -C $(OPENCM3_DIR) $(LIBFOLDER)
$(OPENCM3_DIR)/include/%.h: $(OPENCM3_DIR)/lib/lib$(LIBNAME).a;

# Define a helper macro for debugging make errors online
Expand Down