diff options
-rw-r--r-- | .gitignore | 2 | ||||
-rw-r--r-- | Makefile | 59 | ||||
-rw-r--r-- | decodepng.c | 35 | ||||
-rw-r--r-- | decodepng.cpp | 23 | ||||
-rw-r--r-- | lodepng.c | 2 |
5 files changed, 90 insertions, 31 deletions
@@ -1 +1,3 @@ bin/ +*.d +*.o @@ -1,12 +1,55 @@ -BUILD_FLAGS := -DBUILD_COMMIT="\"`git rev-parse --short HEAD``git diff --shortstat --quiet || echo ' (dirty)'`\"" -DBUILD_DATE="\"`date -u +'%Y-%m-%d %H:%M:%S %Z'`\"" +TARGET := $(shell basename "$(shell pwd)") -all: - mkdir -p bin - g++ -o bin/decodepng decodepng.cpp lodepng/lodepng.cpp $(BUILD_FLAGS) +SOURCES := . +INCLUDES := $(SOURCES) -armhf: - mkdir -p bin - arm-linux-gnueabihf-g++ -o bin/decodepng-armhf decodepng.cpp lodepng/lodepng.cpp $(BUILD_FLAGS) +CFLAGS := +CFLAGS := $(CFLAGS) -Wall -Wextra -Os -std=gnu99 +#CFLAGS := $(CFLAGS) -flto=3 -fwhole-program -fuse-linker-plugin +CFLAGS := $(CFLAGS) -flto=4 -fuse-linker-plugin +CFLAGS := $(CFLAGS) -fno-stack-protector -fno-ident -fomit-frame-pointer -falign-functions=1 -falign-jumps=1 -falign-loops=1 -fno-unwind-tables -fno-asynchronous-unwind-tables -fno-unroll-loops -fmerge-all-constants -fno-math-errno +CFLAGS := $(CFLAGS) -Wl,--as-needed +CFLAGS := $(CFLAGS) -DBUILD_COMMIT="\"`git rev-parse --short HEAD``git diff --shortstat --quiet || echo ' (dirty)'`\"" -DBUILD_DATE="\"`date -u +'%Y-%m-%d %H:%M:%S %Z'`\"" + +LIBDIR := +LDFLAGS := -lm -lc + +INCLUDE += $(foreach dir,$(INCLUDES),-I$(CURDIR)/$(dir)) +CFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.c))) +CPPFILES += $(foreach dir,$(SOURCES),$(notdir $(wildcard $(dir)/*.cpp))) + +OBJS := $(CFILES:.c=.o) $(CPPFILES:.cpp=.o) +DEPENDS := $(OBJS:.o=.d) + +OUTPUT := $(CURDIR)/bin +ELF := $(OUTPUT)/$(TARGET) + +export VPATH := $(foreach dir,$(SOURCES),$(CURDIR)/$(dir)) + +GCC ?= $(CROSS_COMPILE)gcc +STRIP ?= $(CROSS_COMPILE)strip + +.PHONY: all elf dir +all: elf +elf: $(ELF) + +%.o:%.c Makefile + @$(GCC) -MMD $(CFLAGS) $(INCLUDE) -c $< -o $@ + +%.o:%.cpp Makefile + @$(GCC) -MMD $(CFLAGS) $(INCLUDE) -c $< -o $@ + +-include $(DEPENDS) + +dir: + @mkdir -p "$(OUTPUT)" + +$(ELF).elf: $(OBJS) dir + @$(GCC) $(CFLAGS) $(OBJS) $(LDFLAGS) $(LDLIBS) -o $@ && $(STRIP) --strip-all $@ + +$(ELF): $(ELF).elf + @upx -qq --ultra-brute $^ -o $@ -f clean: - rm -r bin
\ No newline at end of file + @rm -f *.o *.d + @rm -f lodepng/*.o lodepng/*.d diff --git a/decodepng.c b/decodepng.c new file mode 100644 index 0000000..907be9a --- /dev/null +++ b/decodepng.c @@ -0,0 +1,35 @@ +#include <stdio.h> +#include <stdint.h> +#include "lodepng/lodepng.h" + +int main(int argc, char *argv[]) +{ + if(argc < 2) + { + fprintf(stderr, "decodepng by DanTheMan827 and madmonkey1907\n\n"); + fprintf(stderr, "Build Date: %s \n", BUILD_DATE); + fprintf(stderr, " Commit: %s \n", BUILD_COMMIT); + return 1; + } + + unsigned char*image=0; //the raw pixels + unsigned width=0,height=0; + + //decode + unsigned error = lodepng_decode32_file(&image, &width, &height, argv[1]); + + if(error) + return error; + + unsigned imageLength = width * height * 4; + if((image==0)||(imageLength==0)) + { + fprintf(stderr, "SOMEBODY SET UP US THE BOMB\n"); + return 1; + } + + fwrite(image, 1, imageLength, stdout); + fflush(stdout); + + return 0; +}
\ No newline at end of file diff --git a/decodepng.cpp b/decodepng.cpp deleted file mode 100644 index 9a30a25..0000000 --- a/decodepng.cpp +++ /dev/null @@ -1,23 +0,0 @@ -#include <stdio.h> -#include <iostream> -#include <iterator> -#include "lodepng/lodepng.h" - -int main(int argc, char *argv[]) -{ - fprintf(stderr, "decodepng by DanTheMan827\n\n"); - fprintf(stderr, "Build Date: %s \n", BUILD_DATE); - fprintf(stderr, " Commit: %s \n", BUILD_COMMIT); - - if(argc == 1){ - return 1; - } - - std::vector<unsigned char> image; //the raw pixels - unsigned width, height; - - //decode - unsigned error = lodepng::decode(image, width, height, argv[1]); - - std::copy(image.begin(), image.end(), std::ostream_iterator<char>(std::cout)); -} diff --git a/lodepng.c b/lodepng.c new file mode 100644 index 0000000..3f52d9c --- /dev/null +++ b/lodepng.c @@ -0,0 +1,2 @@ +#define LODEPNG_NO_COMPILE_ENCODER +#include "lodepng/lodepng.cpp" |