os-workshop

same materials and sample source for RV32 OS projects
git clone http://frotz.net/git/os-workshop.git
Log | Files | Refs

rules.mk (1331B)


      1 ## Copyright 2022, Brian Swetland <swetland@frotz.net>
      2 ## Licensed under the Apache License, Version 2.0
      3 
      4 # Todo: check for missing inputs, duplicate module names, etc
      5 
      6 # Assemble compile and link flags.
      7 MOD_CFLAGS := $(ARCHFLAGS) $(CFLAGS) 
      8 MOD_CFLAGS += $(patsubst %,-I%,$(MOD_INC)) $(patsubst %,-Ilib%/inc,$(MOD_LIB))
      9 MOD_LDFLAGS := $(ARCHFLAGS) -Wl,--gc-sections
     10 
     11 # Generate objects from sources.
     12 MOD_OBJ := $(patsubst %.c,$(MOD_DIR)/%.o,$(MOD_SRC))
     13 MOD_OBJ := $(patsubst %.S,$(MOD_DIR)/%.o,$(MOD_OBJ))
     14 
     15 # Track flags in a build.opts file so we can depend on it.
     16 # Write the file only if it does not already contain the
     17 # same options as currently defined.
     18 $(shell mkdir -p $(MOD_DIR))
     19 
     20 OPTS.A := $(strip $(MOD_CFLAGS) $(MOD_LDFLAGS))
     21 OPTS.B := $(strip $(file <$(MOD_DIR)/build.opts))
     22 
     23 ifneq ($(OPTS.A),$(OPTS.B))
     24 $(info generating $(MOD_DIR)/build.opts)
     25 $(file >$(MOD_DIR)/build.opts,$(OPTS.A))
     26 endif
     27 
     28 $(MOD_DIR)/%.o: _CFLAGS := $(MOD_CFLAGS)
     29 
     30 $(MOD_DIR)/%.o: %.c
     31 	@mkdir -p $(dir $@)
     32 	@$(info compiling $<)
     33 	$(V)$(XGCC) -c -o $@ $< $(_CFLAGS) -MD -MP -MT $@ -MF $(@:%o=%d)
     34 
     35 $(MOD_DIR)/%.o: %.S
     36 	@mkdir -p $(dir $@)
     37 	@$(info compiling $<)
     38 	$(V)$(XGCC) -c -o $@ $< $(_CFLAGS) -D__ASSEMBLY__ -MD -MP -MT $@ -MF $(@:%o=%d)
     39 
     40 # include compiler auto-deps
     41 -include $(patsubst %.o,%.d,$(MOD_OBJ))
     42 
     43 $(MOD_OBJ): $(MOD_DIR)/build.opts
     44