Skip to content

Commit

Permalink
Improved version handling, added package target.
Browse files Browse the repository at this point in the history
Version number has been moved to a separate file.
Makefile has been updated to generate C header file
from that version. Added making package, for both
windows and unix-like OS.
  • Loading branch information
mefistotelis committed Sep 24, 2015
1 parent 8663ed8 commit b8a5306
Show file tree
Hide file tree
Showing 5 changed files with 106 additions and 32 deletions.
10 changes: 8 additions & 2 deletions .cproject
Original file line number Diff line number Diff line change
Expand Up @@ -67,20 +67,26 @@
<buildTargets>
<target name="clean" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>clean</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="all" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>all</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
<target name="package" path="" targetID="org.eclipse.cdt.build.MakeTargetBuilder">
<buildCommand>make</buildCommand>
<buildArguments/>
<buildTarget>package</buildTarget>
<stopOnError>true</stopOnError>
<useDefaultCommand>true</useDefaultCommand>
<runAllBuilders>true</runAllBuilders>
</target>
</buildTargets>
</storageModule>
</cproject>
100 changes: 75 additions & 25 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,27 +17,37 @@
# (at your option) any later version.
#
#******************************************************************************
OS = $(shell uname -s)
ifneq (,$(findstring MINGW,$(OS)))
RES = obj/png2bestpal_stdres.res
EXEEXT = .exe
ifneq (,$(findstring Windows,$(OS)))
RES = obj/png2bestpal_stdres.res
EXEEXT = .exe
PKGFMT = zip
PKGOS = win
else
RES =
EXEEXT =
RES =
EXEEXT =
PKGFMT = tar.gz
PKGOS = lin
endif

CPP = g++
CC = gcc
WINDRES = windres
DLLTOOL = dlltool
RM = rm -f
MV = mv -f
CP = cp -f
MKDIR = mkdir -p
ECHO = @echo
TAR = tar
ZIP = zip

BIN = bin/png2bestpal$(EXEEXT)
LIBS =
OBJS = \
obj/png2bestpal.o \
$(RES)

GENSRC = obj/ver_defs.h
LINKOBJ = $(OBJS)
LINKLIB = -static -lpng -lz -lm
INCS =
Expand All @@ -55,40 +65,80 @@ WARNFLAGS = -Wall -Wno-sign-compare -Wno-unused-parameter
CXXFLAGS = $(CXXINCS) -std=c++11 -c -fmessage-length=0 $(WARNFLAGS) $(DEPFLAGS) $(OPTFLAGS)
CFLAGS = $(INCS) -c -fmessage-length=0 $(WARNFLAGS) $(DEPFLAGS) $(OPTFLAGS)
LDFLAGS = $(LINKLIB) $(OPTFLAGS) $(DBGFLAGS) $(LINKFLAGS)
RM = rm -f

.PHONY: all all-before all-after clean clean-custom
# load program version
include version.mk
VER_STRING = $(VER_MAJOR).$(VER_MINOR).$(VER_RELEASE).$(VER_BUILD)

.PHONY: all all-before all-after clean clean-custom package pkg-before zip tar.gz

all: all-before $(BIN) all-after

all-before:
$(MKDIR) obj bin

clean: clean-custom
-${RM} $(OBJS) $(BIN) $(LIBS)
-@echo ' '
-${RM} $(OBJS) $(GENSRC) $(BIN) $(LIBS)
-${RM} pkg/*
-$(ECHO) ' '

$(BIN): $(OBJS) $(LIBS)
@echo 'Building target: $@'
-$(ECHO) 'Building target: $@'
$(CPP) $(LINKOBJ) -o "$@" $(LDFLAGS)
@echo 'Finished building target: $@'
@echo ' '
-$(ECHO) 'Finished building target: $@'
-$(ECHO) ' '

obj/%.o: src/%.cpp
@echo 'Building file: $<'
obj/%.o: src/%.cpp $(GENSRC)
-$(ECHO) 'Building file: $<'
$(CPP) $(CXXFLAGS) -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
-$(ECHO) 'Finished building: $<'
-$(ECHO) ' '

obj/%.o: src/%.c
@echo 'Building file: $<'
obj/%.o: src/%.c $(GENSRC)
-$(ECHO) 'Building file: $<'
$(CC) $(CFLAGS) -o"$@" "$<"
@echo 'Finished building: $<'
@echo ' '
-$(ECHO) 'Finished building: $<'
-$(ECHO) ' '

obj/%.res: res/%.rc
@echo 'Building resource: $<'
obj/%.res: res/%.rc $(GENSRC)
-$(ECHO) 'Building resource: $<'
$(WINDRES) -i "$<" --input-format=rc -o "$@" -O coff
@echo 'Finished building: $<'
@echo ' '
-$(ECHO) 'Finished building: $<'
-$(ECHO) ' '

obj/ver_defs.h: version.mk Makefile
$(ECHO) \#define VER_MAJOR $(VER_MAJOR) > "$(@D)/tmp"
$(ECHO) \#define VER_MINOR $(VER_MINOR) >> "$(@D)/tmp"
$(ECHO) \#define VER_RELEASE $(VER_RELEASE) >> "$(@D)/tmp"
$(ECHO) \#define VER_BUILD $(VER_BUILD) >> "$(@D)/tmp"
$(ECHO) \#define VER_STRING \"$(VER_STRING)\" >> "$(@D)/tmp"
$(ECHO) \#define PACKAGE_SUFFIX \"$(PACKAGE_SUFFIX)\" >> "$(@D)/tmp"
$(MV) "$(@D)/tmp" "$@"

package: pkg-before $(PKGFMT)

pkg-before:
-${RM} pkg/*
$(MKDIR) pkg
$(CP) bin/* pkg/
$(CP) docs/*_readme.txt pkg/

pkg/%.tar.gz: pkg-before
-$(ECHO) 'Creating package: $<'
cd $(@D); \
$(TAR) --owner=0 --group=0 --exclude=*.tar.gz --exclude=*.zip -zcf "$(@F)" .
-$(ECHO) 'Finished creating: $<'
-$(ECHO) ' '

tar.gz: pkg/png2bestpal-$(subst .,_,$(VER_STRING))-$(PACKAGE_SUFFIX)-$(PKGOS).tar.gz

pkg/%.zip: pkg-before
-$(ECHO) 'Creating package: $<'
cd $(@D); \
$(ZIP) -x*.tar.gz -x*.zip -9 -r "$(@F)" .
-$(ECHO) 'Finished creating: $<'
-$(ECHO) ' '

zip: pkg/png2bestpal-$(subst .,_,$(VER_STRING))-$(PACKAGE_SUFFIX)-$(PKGOS).zip

#******************************************************************************
11 changes: 11 additions & 0 deletions docs/png2bestpal_readme.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@

Best 8bpp palette selector for a series of PNG files (Png2bestPal)
Created by Tomasz Lis; GNU General Public License
----------------------------------------
usage:

png2bestpal.exe [options] <filename>
where <filename> should be the input BMP file, and [options] are:
-v,--verbose Verbose console output mode
-m<file>,--palmap<file> Static palette entries mapping file name
-o<file>,--output<file> Output PAL file name
12 changes: 7 additions & 5 deletions src/png2bestpal_version.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,13 @@
#define PNG2BESTPAL_VERSION_H

/* Version definitions */
#define VER_MAJOR 1
#define VER_MINOR 0
#define VER_RELEASE 0
#define VER_BUILD 1
#define VER_STRING "1.0.0.1"
#include "../obj/ver_defs.h"
//#define VER_MAJOR 1
//#define VER_MINOR 2
//#define VER_RELEASE 3
//#define VER_BUILD 4
//#define VER_STRING "1.2.3.4"

/* Program name, copyrights and file names */
#define PROGRAM_NAME "Png2bestPal"
#define PROGRAM_FULL_NAME "Best 8bpp palette selector for a series of PNG files"
Expand Down
5 changes: 5 additions & 0 deletions version.mk
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
VER_MAJOR=1
VER_MINOR=0
VER_RELEASE=1
VER_BUILD=19
PACKAGE_SUFFIX=devel

0 comments on commit b8a5306

Please sign in to comment.