From 0160b515ff640ca90153f66c4fcdc8013f427d00 Mon Sep 17 00:00:00 2001 From: Jianjun Jiang <8192542@qq.com> Date: Sun, 5 Dec 2021 11:20:37 +0800 Subject: [PATCH] [libcg]modify some directory --- .gitignore | 3 -- Makefile | 77 ++++----------------------------------- README.md | 3 +- examples/.gitignore | 19 ++++++++++ examples/Makefile | 71 ++++++++++++++++++++++++++++++++++++ cat.h => examples/cat.h | 0 main.c => examples/main.c | 0 src/Makefile | 61 +++++++++++++++++++++++++++++++ cg.c => src/cg.c | 0 cg.h => src/cg.h | 0 swft.c => src/swft.c | 0 swft.h => src/swft.h | 0 12 files changed, 159 insertions(+), 75 deletions(-) create mode 100644 examples/.gitignore create mode 100644 examples/Makefile rename cat.h => examples/cat.h (100%) rename main.c => examples/main.c (100%) create mode 100644 src/Makefile rename cg.c => src/cg.c (100%) rename cg.h => src/cg.h (100%) rename swft.c => src/swft.c (100%) rename swft.h => src/swft.h (100%) diff --git a/.gitignore b/.gitignore index 13fff59..3129cbe 100644 --- a/.gitignore +++ b/.gitignore @@ -4,7 +4,6 @@ *.map *.elf *.bin -*.png *.rej *.orig *.d @@ -16,8 +15,6 @@ # # Generated files # -!/screenshots/*.png /.cproject /.project /.settings -/example diff --git a/Makefile b/Makefile index 335f18e..2c050a5 100644 --- a/Makefile +++ b/Makefile @@ -1,76 +1,13 @@ # -# Makefile for module. +# Top Makefile # -CROSS ?= +.PHONY: all clean - -AS := $(CROSS)gcc -x assembler-with-cpp -CC := $(CROSS)gcc -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 $@ +all: + @$(MAKE) -C src all + @$(MAKE) -C examples all clean: - @$(RM) $(DEPS) $(OBJS) $(NAME).map $(NAME) *.png *~ - @echo Clean complete. + @$(MAKE) -C src clean + @$(MAKE) -C examples clean diff --git a/README.md b/README.md index 929d2a6..d783417 100644 --- a/README.md +++ b/README.md @@ -5,8 +5,7 @@ The tiny `C` library of 2D computer graphics. ## Getting Started -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 example binary file. +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. ```shell cd libcg diff --git a/examples/.gitignore b/examples/.gitignore new file mode 100644 index 0000000..24fb7b2 --- /dev/null +++ b/examples/.gitignore @@ -0,0 +1,19 @@ +# +# Normal rules +# +*.map +*.elf +*.bin +*.png +*.rej +*.orig +*.d +*.o +*.a +*.so +*~ + +# +# Generated files +# +/examples diff --git a/examples/Makefile b/examples/Makefile new file mode 100644 index 0000000..5052610 --- /dev/null +++ b/examples/Makefile @@ -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) diff --git a/cat.h b/examples/cat.h similarity index 100% rename from cat.h rename to examples/cat.h diff --git a/main.c b/examples/main.c similarity index 100% rename from main.c rename to examples/main.c diff --git a/src/Makefile b/src/Makefile new file mode 100644 index 0000000..bc45223 --- /dev/null +++ b/src/Makefile @@ -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) diff --git a/cg.c b/src/cg.c similarity index 100% rename from cg.c rename to src/cg.c diff --git a/cg.h b/src/cg.h similarity index 100% rename from cg.h rename to src/cg.h diff --git a/swft.c b/src/swft.c similarity index 100% rename from swft.c rename to src/swft.c diff --git a/swft.h b/src/swft.h similarity index 100% rename from swft.h rename to src/swft.h