Skip to content
Snippets Groups Projects
Select Git revision
  • master default protected
  • unstable
  • processes_wip
  • clang
  • cmake
  • cmake-old
  • sd-fix
  • shield_stackX
  • compute-unit-v2
  • con-rig
  • testing_ram_cu_v2
  • parafoil-sensortile
  • angel-swi
  • ignition
  • miosix-2.22
  • alderaan-v1
16 results

Makefile

Blame
  • Makefile 3.08 KiB
    ##
    ## Makefile for Miosix embedded OS
    ##
    MAKEFILE_VERSION := 1.10
    ## Path to kernel directory (edited by init_project_out_of_git_repo.pl)
    KPATH := miosix
    ## Path to config directory (edited by init_project_out_of_git_repo.pl)
    CONFPATH := $(KPATH)
    include $(CONFPATH)/config/Makefile.inc
    
    ##
    ## List here subdirectories which contains makefiles
    ##
    SUBDIRS := $(KPATH)
    
    ##
    ## List here your source files (both .s, .c and .cpp)
    ##
    SRC :=                                  \
    main.cpp
    
    ##
    ## List here additional static libraries with relative path
    ##
    LIBS :=
    
    ##
    ## List here additional include directories (in the form -Iinclude_dir)
    ##
    INCLUDE_DIRS :=
    
    ##############################################################################
    ## You should not need to modify anything below                             ##
    ##############################################################################
    
    ifeq ("$(VERBOSE)","1")
    Q := 
    ECHO := @true
    else
    Q := @
    ECHO := @echo
    endif
    
    ## Replaces both "foo.cpp"-->"foo.o" and "foo.c"-->"foo.o"
    OBJ := $(addsuffix .o, $(basename $(SRC)))
    
    ## Includes the miosix base directory for C/C++
    ## Always include CONFPATH first, as it overrides the config file location
    CXXFLAGS := $(CXXFLAGS_BASE) -I$(CONFPATH) -I$(CONFPATH)/config/$(BOARD_INC)  \
                -I. -I$(KPATH) -I$(KPATH)/arch/common -I$(KPATH)/$(ARCH_INC)      \
                -I$(KPATH)/$(BOARD_INC) $(INCLUDE_DIRS)
    CFLAGS   := $(CFLAGS_BASE)   -I$(CONFPATH) -I$(CONFPATH)/config/$(BOARD_INC)  \
                -I. -I$(KPATH) -I$(KPATH)/arch/common -I$(KPATH)/$(ARCH_INC)      \
                -I$(KPATH)/$(BOARD_INC) $(INCLUDE_DIRS)
    AFLAGS   := $(AFLAGS_BASE)
    LFLAGS   := $(LFLAGS_BASE)
    DFLAGS   := -MMD -MP
    
    ## libmiosix.a is among stdlibs because needs to be within start/end group
    STDLIBS  := -lmiosix -lstdc++ -lc -lm -lgcc -latomic
    LINK_LIBS := $(LIBS) -L$(KPATH) -Wl,--start-group $(STDLIBS) -Wl,--end-group
    
    all: all-recursive main
    
    clean: clean-recursive clean-topdir
    
    program:
    	$(PROGRAM_CMDLINE)
    
    all-recursive:
    	$(foreach i,$(SUBDIRS),$(MAKE) -C $(i)                               \
    	  KPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(KPATH))       \
    	  CONFPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(CONFPATH)) \
    	  || exit 1;)
    
    clean-recursive:
    	$(foreach i,$(SUBDIRS),$(MAKE) -C $(i)                               \
    	  KPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(KPATH))       \
    	  CONFPATH=$(shell perl $(KPATH)/_tools/relpath.pl $(i) $(CONFPATH)) \
    	  clean || exit 1;)
    
    clean-topdir:
    	-rm -f $(OBJ) main.elf main.hex main.bin main.map $(OBJ:.o=.d)
    
    main: main.elf
    	$(ECHO) "[CP  ] main.hex"
    	$(Q)$(CP) -O ihex   main.elf main.hex
    	$(ECHO) "[CP  ] main.bin"
    	$(Q)$(CP) -O binary main.elf main.bin
    	$(Q)$(SZ) main.elf
    
    main.elf: $(OBJ) all-recursive
    	$(ECHO) "[LD  ] main.elf"
    	$(Q)$(CXX) $(LFLAGS) -o main.elf $(OBJ) $(KPATH)/$(BOOT_FILE) $(LINK_LIBS)
    
    %.o: %.s
    	$(ECHO) "[AS  ] $<"
    	$(Q)$(AS)  $(AFLAGS) $< -o $@
    
    %.o : %.c
    	$(ECHO) "[CC  ] $<"
    	$(Q)$(CC)  $(DFLAGS) $(CFLAGS) $< -o $@
    
    %.o : %.cpp
    	$(ECHO) "[CXX ] $<"
    	$(Q)$(CXX) $(DFLAGS) $(CXXFLAGS) $< -o $@
    
    #pull in dependecy info for existing .o files
    -include $(OBJ:.o=.d)