Skip to content

Commit

Permalink
Track Makefile in examples
Browse files Browse the repository at this point in the history
  • Loading branch information
mickjc750 committed Aug 22, 2024
1 parent ea2f938 commit aab5067
Show file tree
Hide file tree
Showing 5 changed files with 613 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -19,3 +19,6 @@
*.out
*.hex
*.eep

# Unignore Makefile
!Makefile
151 changes: 151 additions & 0 deletions examples/custom_allocator/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#----------------------------------------------------------------------------
# BEWARE: Messed up by makefile NOOB Michael Clift for Command line applications
#

# Target file name (without extension).
TARGET = heap-buf

# List C source files here. (C dependencies are automatically generated.)
# To exclude certain files in a folder remove the $(wildcard) and
# list them seperated by spaces, ie src/main.c src/util.c
SRC = heap-buf.c ../../strbuf.c ../../strview.c

# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = . ../..

# Object and list files directory
# To put .o and .lst files alongside .c files use a dot (.), do NOT make
# this an empty or blank macro!
# If source files are in sub directories, matching subdirectories must exist under this folder for the .o files
# This is a pain, if you can fix this, please do and share.
OBJLSTDIR = .

# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99

# Place -D or -U options here for C sources
CDEFS = -DPLATFORM_PC

#---------------- Compiler Options C ----------------
# -g debug information
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
CFLAGS += $(CDEFS)
CFLAGS += -Wall
CFLAGS += -Wno-unused-function
CFLAGS += -Wno-unused-but-set-variable
CFLAGS += $(CSTANDARD)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))

# List any extra directories to look for libraries here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRALIBDIRS = .
EXTRALIBS = -lm

#---------------- Linker Options ----------------

LDFLAGS = $(patsubst %,-L%,$(EXTRALIBDIRS))
LDFLAGS += $(EXTRALIBS)

#============================================================================

# Define programs and commands.
SHELL = sh
CC = gcc
REMOVE = rm -f
REMOVEDIR = rm -rf
COPY = cp

# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_CLEANING = Cleaning project:

# Define all object files.
OBJ = $(SRC:%.c=$(OBJLSTDIR)/%.o)

# Compiler flags to generate dependency files.
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d

# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -I. $(CFLAGS) $(GENDEPFLAGS)

# Default target.
all: begin gccversion buildinfo build end


build: tgt

tgt: $(TARGET)

# Eye candy.
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)

end:
@cat build_date.inc
@echo $(MSG_END)
@echo

# Gather information about build
buildinfo:
@$(CC) --version | grep gcc | awk '{print "\x22" $$0 "\x22"}' > gcc_version.inc
@date --iso-8601=seconds -u | awk '{print "\x22" $$0 "\x22"}' > build_date.inc
@read LASTNUM < build_number.inc; \
NEWNUM=$$(($$LASTNUM + 1)); \
echo "$$NEWNUM" > build_number.inc
@touch version.c

# Display compiler version information.
gccversion :
@$(CC) --version


# Link: create output file from object files.
.SECONDARY : $(TARGET)
.PRECIOUS : $(OBJ)
$(TARGET): $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)

# Compile: create object files from C source files.
$(OBJLSTDIR)/%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@

# Target: clean project.
clean: begin clean_list end

clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(SRC:%.c=$(OBJLSTDIR)/%.o)
$(REMOVE) $(SRC:%.c=$(OBJLSTDIR)/%.lst)
$(REMOVEDIR) .dep

# Create object files directory
$(shell mkdir $(OBJLSTDIR) 2>/dev/null)

# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)

# Listing of phony targets.
.PHONY : all begin end buildinfo gccversion build tgt clean clean_list
151 changes: 151 additions & 0 deletions examples/stack_buffer/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#----------------------------------------------------------------------------
# BEWARE: Messed up by makefile NOOB Michael Clift for Command line applications
#

# Target file name (without extension).
TARGET = stack-buf

# List C source files here. (C dependencies are automatically generated.)
# To exclude certain files in a folder remove the $(wildcard) and
# list them seperated by spaces, ie src/main.c src/util.c
SRC = stack-buf.c ../../strbuf.c ../../strview.c

# List any extra directories to look for include files here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRAINCDIRS = . ../..

# Object and list files directory
# To put .o and .lst files alongside .c files use a dot (.), do NOT make
# this an empty or blank macro!
# If source files are in sub directories, matching subdirectories must exist under this folder for the .o files
# This is a pain, if you can fix this, please do and share.
OBJLSTDIR = .

# Compiler flag to set the C Standard level.
# c89 = "ANSI" C
# gnu89 = c89 plus GCC extensions
# c99 = ISO C99 standard (not yet fully implemented)
# gnu99 = c99 plus GCC extensions
CSTANDARD = -std=gnu99

# Place -D or -U options here for C sources
CDEFS = -DPLATFORM_PC

#---------------- Compiler Options C ----------------
# -g debug information
# -f...: tuning, see GCC manual and avr-libc documentation
# -Wall...: warning level
CFLAGS += $(CDEFS)
CFLAGS += -Wall
CFLAGS += -Wno-unused-function
CFLAGS += -Wno-unused-but-set-variable
CFLAGS += $(CSTANDARD)
CFLAGS += $(patsubst %,-I%,$(EXTRAINCDIRS))

# List any extra directories to look for libraries here.
# Each directory must be seperated by a space.
# Use forward slashes for directory separators.
# For a directory that has spaces, enclose it in quotes.
EXTRALIBDIRS = .
EXTRALIBS = -lm

#---------------- Linker Options ----------------

LDFLAGS = $(patsubst %,-L%,$(EXTRALIBDIRS))
LDFLAGS += $(EXTRALIBS)

#============================================================================

# Define programs and commands.
SHELL = sh
CC = gcc
REMOVE = rm -f
REMOVEDIR = rm -rf
COPY = cp

# Define Messages
# English
MSG_ERRORS_NONE = Errors: none
MSG_BEGIN = -------- begin --------
MSG_END = -------- end --------
MSG_LINKING = Linking:
MSG_COMPILING = Compiling C:
MSG_CLEANING = Cleaning project:

# Define all object files.
OBJ = $(SRC:%.c=$(OBJLSTDIR)/%.o)

# Compiler flags to generate dependency files.
GENDEPFLAGS = -MMD -MP -MF .dep/$(@F).d

# Combine all necessary flags and optional flags.
# Add target processor to flags.
ALL_CFLAGS = -I. $(CFLAGS) $(GENDEPFLAGS)

# Default target.
all: begin gccversion buildinfo build end


build: tgt

tgt: $(TARGET)

# Eye candy.
# the following magic strings to be generated by the compile job.
begin:
@echo
@echo $(MSG_BEGIN)

end:
@cat build_date.inc
@echo $(MSG_END)
@echo

# Gather information about build
buildinfo:
@$(CC) --version | grep gcc | awk '{print "\x22" $$0 "\x22"}' > gcc_version.inc
@date --iso-8601=seconds -u | awk '{print "\x22" $$0 "\x22"}' > build_date.inc
@read LASTNUM < build_number.inc; \
NEWNUM=$$(($$LASTNUM + 1)); \
echo "$$NEWNUM" > build_number.inc
@touch version.c

# Display compiler version information.
gccversion :
@$(CC) --version


# Link: create output file from object files.
.SECONDARY : $(TARGET)
.PRECIOUS : $(OBJ)
$(TARGET): $(OBJ)
@echo
@echo $(MSG_LINKING) $@
$(CC) $(ALL_CFLAGS) $^ --output $@ $(LDFLAGS)

# Compile: create object files from C source files.
$(OBJLSTDIR)/%.o : %.c
@echo
@echo $(MSG_COMPILING) $<
$(CC) -c $(ALL_CFLAGS) $< -o $@

# Target: clean project.
clean: begin clean_list end

clean_list :
@echo
@echo $(MSG_CLEANING)
$(REMOVE) $(SRC:%.c=$(OBJLSTDIR)/%.o)
$(REMOVE) $(SRC:%.c=$(OBJLSTDIR)/%.lst)
$(REMOVEDIR) .dep

# Create object files directory
$(shell mkdir $(OBJLSTDIR) 2>/dev/null)

# Include the dependency files.
-include $(shell mkdir .dep 2>/dev/null) $(wildcard .dep/*)

# Listing of phony targets.
.PHONY : all begin end buildinfo gccversion build tgt clean clean_list
Loading

0 comments on commit aab5067

Please sign in to comment.