[libcg]modify some directory

This commit is contained in:
Jianjun Jiang 2021-12-05 11:20:37 +08:00
parent 7d8a09c837
commit 0160b515ff
12 changed files with 159 additions and 75 deletions

3
.gitignore vendored
View File

@ -4,7 +4,6 @@
*.map *.map
*.elf *.elf
*.bin *.bin
*.png
*.rej *.rej
*.orig *.orig
*.d *.d
@ -16,8 +15,6 @@
# #
# Generated files # Generated files
# #
!/screenshots/*.png
/.cproject /.cproject
/.project /.project
/.settings /.settings
/example

View File

@ -1,76 +1,13 @@
# #
# Makefile for module. # Top Makefile
# #
CROSS ?= .PHONY: all clean
all:
AS := $(CROSS)gcc -x assembler-with-cpp @$(MAKE) -C src all
CC := $(CROSS)gcc @$(MAKE) -C examples all
CXX := $(CROSS)g++
LD := $(CROSS)ld
AR := $(CROSS)ar
OC := $(CROSS)objcopy
OD := $(CROSS)objdump
RM := rm -fr
ASFLAGS := -g -ggdb -Wall -O3 -ffunction-sections -fdata-sections -ffreestanding -std=gnu99
CFLAGS := -g -ggdb -Wall -O3 -ffunction-sections -fdata-sections -ffreestanding -std=gnu99
CXXFLAGS := -g -ggdb -Wall -O3 -ffunction-sections -fdata-sections -ffreestanding -std=gnu99
LDFLAGS := -Wl,-gc-sections
ARFLAGS := -rcs
OCFLAGS := -v -O binary
ODFLAGS :=
MCFLAGS :=
LIBDIRS :=
LIBS := -lm
INCDIRS := -I .
SRCDIRS := .
SFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.S))
CFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.cpp))
SDEPS := $(patsubst %, %, $(SFILES:.S=.o.d))
CDEPS := $(patsubst %, %, $(CFILES:.c=.o.d))
CPPDEPS := $(patsubst %, %, $(CPPFILES:.cpp=.o.d))
DEPS := $(SDEPS) $(CDEPS) $(CPPDEPS)
SOBJS := $(patsubst %, %, $(SFILES:.S=.o))
COBJS := $(patsubst %, %, $(CFILES:.c=.o))
CPPOBJS := $(patsubst %, %, $(CPPFILES:.cpp=.o))
OBJS := $(SOBJS) $(COBJS) $(CPPOBJS)
OBJDIRS := $(patsubst %, %, $(SRCDIRS))
NAME := example
VPATH := $(OBJDIRS)
.PHONY: all clean
all : $(NAME)
$(NAME) : $(OBJS)
@echo [LD] Linking $@
@$(CC) $(LDFLAGS) $(LIBDIRS) $^ -o $@ $(LIBS)
$(SOBJS) : %.o : %.S
@echo [AS] $<
@$(AS) $(ASFLAGS) $(INCDIRS) -c $< -o $@
@$(AS) $(ASFLAGS) -MD -MP -MF $@.d $(INCDIRS) -c $< -o $@
$(COBJS) : %.o : %.c
@echo [CC] $<
@$(CC) $(CFLAGS) $(INCDIRS) -c $< -o $@
@$(CC) $(CFLAGS) -MD -MP -MF $@.d $(INCDIRS) -c $< -o $@
$(CPPOBJS) : %.o : %.cpp
@echo [CXX] $<
@$(CXX) $(CXXFLAGS) $(INCDIRS) -c $< -o $@
@$(CXX) $(CXXFLAGS) -MD -MP -MF $@.d $(INCDIRS) -c $< -o $@
clean: clean:
@$(RM) $(DEPS) $(OBJS) $(NAME).map $(NAME) *.png *~ @$(MAKE) -C src clean
@echo Clean complete. @$(MAKE) -C examples clean

View File

@ -5,8 +5,7 @@ The tiny `C` library of 2D computer graphics.
## Getting Started ## Getting Started
The library's .c and .h files can be dropped into a project and compiled along with it. The library's .c and .h files can be dropped into a project and compiled along with it. Just type `make` at the root directory, you will see a static library and some binary of [examples](examples) for usage.
Just type `make` at the root directory, you will see a example binary file.
```shell ```shell
cd libcg cd libcg

19
examples/.gitignore vendored Normal file
View File

@ -0,0 +1,19 @@
#
# Normal rules
#
*.map
*.elf
*.bin
*.png
*.rej
*.orig
*.d
*.o
*.a
*.so
*~
#
# Generated files
#
/examples

71
examples/Makefile Normal file
View File

@ -0,0 +1,71 @@
#
# Makefile for application
#
CROSS_COMPILE ?=
AS := $(CROSS_COMPILE)gcc -x assembler-with-cpp
CC := $(CROSS_COMPILE)gcc
CXX := $(CROSS_COMPILE)g++
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
OC := $(CROSS_COMPILE)objcopy
OD := $(CROSS_COMPILE)objdump
RM := rm -fr
ASFLAGS := -g -ggdb -Wall -O3
CFLAGS := -g -ggdb -Wall -O3
CXXFLAGS := -g -ggdb -Wall -O3
LDFLAGS :=
OCFLAGS := -v -O binary
ODFLAGS :=
MCFLAGS :=
LIBDIRS := -L ../src
LIBS := -lcg -lm
INCDIRS := -I . -I ../src
SRCDIRS := .
SFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.S))
CFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.cpp))
SDEPS := $(patsubst %, %, $(SFILES:.S=.o.d))
CDEPS := $(patsubst %, %, $(CFILES:.c=.o.d))
CPPDEPS := $(patsubst %, %, $(CPPFILES:.cpp=.o.d))
DEPS := $(SDEPS) $(CDEPS) $(CPPDEPS)
SOBJS := $(patsubst %, %, $(SFILES:.S=.o))
COBJS := $(patsubst %, %, $(CFILES:.c=.o))
CPPOBJS := $(patsubst %, %, $(CPPFILES:.cpp=.o))
OBJS := $(SOBJS) $(COBJS) $(CPPOBJS)
OBJDIRS := $(patsubst %, %, $(SRCDIRS))
NAME := examples
VPATH := $(OBJDIRS)
.PHONY: all clean
all : $(NAME)
$(NAME) : $(OBJS)
@echo [LD] Linking $@
@$(CC) $(LDFLAGS) $(LIBDIRS) $^ -o $@ $(LIBS) -static
$(SOBJS) : %.o : %.S
@echo [AS] $<
@$(AS) $(ASFLAGS) -MD -MP -MF $@.d $(INCDIRS) -c $< -o $@
$(COBJS) : %.o : %.c
@echo [CC] $<
@$(CC) $(CFLAGS) -MD -MP -MF $@.d $(INCDIRS) -c $< -o $@
$(CPPOBJS) : %.o : %.cpp
@echo [CXX] $<
@$(CXX) $(CXXFLAGS) -MD -MP -MF $@.d $(INCDIRS) -c $< -o $@
clean:
@$(RM) $(DEPS) $(OBJS) $(NAME) *.png
sinclude $(DEPS)

61
src/Makefile Normal file
View File

@ -0,0 +1,61 @@
#
# Makefile for library
#
CROSS_COMPILE ?=
AS := $(CROSS_COMPILE)gcc -x assembler-with-cpp
CC := $(CROSS_COMPILE)gcc
CXX := $(CROSS_COMPILE)g++
LD := $(CROSS_COMPILE)ld
AR := $(CROSS_COMPILE)ar
OC := $(CROSS_COMPILE)objcopy
OD := $(CROSS_COMPILE)objdump
RM := rm -fr
ASFLAGS := -g -ggdb -Wall -O3 -ffunction-sections -fdata-sections -ffreestanding -std=gnu99
CFLAGS := -g -ggdb -Wall -O3 -ffunction-sections -fdata-sections -ffreestanding -std=gnu99
CXXFLAGS := -g -ggdb -Wall -O3 -ffunction-sections -fdata-sections -ffreestanding -std=gnu99
INCDIRS := -I .
SRCDIRS := .
SFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.S))
CFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.c))
CPPFILES := $(foreach dir, $(SRCDIRS), $(wildcard $(dir)/*.cpp))
SDEPS := $(patsubst %, %, $(SFILES:.S=.o.d))
CDEPS := $(patsubst %, %, $(CFILES:.c=.o.d))
CPPDEPS := $(patsubst %, %, $(CPPFILES:.cpp=.o.d))
DEPS := $(SDEPS) $(CDEPS) $(CPPDEPS)
SOBJS := $(patsubst %, %, $(SFILES:.S=.o))
COBJS := $(patsubst %, %, $(CFILES:.c=.o))
CPPOBJS := $(patsubst %, %, $(CPPFILES:.cpp=.o))
OBJS := $(SOBJS) $(COBJS) $(CPPOBJS)
NAME := libcg.a
.PHONY: all clean
all : $(NAME)
$(NAME) : $(OBJS)
@echo [AR] Archiving $@
@$(AR) -rcs $@ $(OBJS)
$(SOBJS) : %.o : %.S
@echo [AS] $<
@$(AS) $(ASFLAGS) -MD -MP -MF $@.d $(INCDIRS) -c $< -o $@
$(COBJS) : %.o : %.c
@echo [CC] $<
@$(CC) $(CFLAGS) -MD -MP -MF $@.d $(INCDIRS) -c $< -o $@
$(CPPOBJS) : %.o : %.cpp
@echo [CXX] $<
@$(CXX) $(CXXFLAGS) -MD -MP -MF $@.d $(INCDIRS) -c $< -o $@
clean:
@$(RM) $(DEPS) $(OBJS) $(NAME)
sinclude $(DEPS)

View File

View File

View File

View File