Add version option
This commit is contained in:
parent
fced49c98e
commit
144ff45830
4 changed files with 50 additions and 7 deletions
16
Makefile
16
Makefile
|
|
@ -23,6 +23,11 @@ else
|
||||||
# release flags
|
# release flags
|
||||||
CXXFLAGS += -Ofast
|
CXXFLAGS += -Ofast
|
||||||
endif
|
endif
|
||||||
|
|
||||||
|
ifneq ($(RELEASE), true)
|
||||||
|
VSUFFIX=-dev-$(SHA_SHORT)
|
||||||
|
endif
|
||||||
|
|
||||||
ifeq ($(STATIC),true)
|
ifeq ($(STATIC),true)
|
||||||
# static links
|
# static links
|
||||||
LDFLAGS += -l:libztd.a
|
LDFLAGS += -l:libztd.a
|
||||||
|
|
@ -33,22 +38,27 @@ endif
|
||||||
|
|
||||||
## END CONFIG ##
|
## END CONFIG ##
|
||||||
|
|
||||||
|
$(shell ./generate_version.sh)
|
||||||
$(shell mkdir -p $(ODIR))
|
$(shell mkdir -p $(ODIR))
|
||||||
$(shell mkdir -p $(BINDIR))
|
$(shell mkdir -p $(BINDIR))
|
||||||
|
|
||||||
# automatically find .h and .hpp
|
# automatically find .h and .hpp
|
||||||
DEPS = $(shell find $(IDIR) -type f -regex '.*\.hp?p?')
|
DEPS = $(shell find $(IDIR) -type f -regex '.*\.hp?p?' ! -name 'g_version.h')
|
||||||
# automatically find .c and .cpp and make the corresponding .o rule
|
# automatically find .c and .cpp and make the corresponding .o rule
|
||||||
OBJ = $(shell find $(SRCDIR) -type f -regex '.*\.cp?p?' | sed 's|\.cpp|.o|g;s|\.c|.o|g;s|^$(SRCDIR)/|$(ODIR)/|g')
|
OBJ = $(shell find $(SRCDIR) -type f -regex '.*\.cp?p?' | sed 's|\.cpp|.o|g;s|\.c|.o|g;s|^$(SRCDIR)/|$(ODIR)/|g')
|
||||||
|
|
||||||
|
build: lxsh $(OBJ) $(DEPS)
|
||||||
|
|
||||||
$(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS)
|
$(ODIR)/%.o: $(SRCDIR)/%.c $(DEPS)
|
||||||
$(CC) $(CXXFLAGS) -c -o $@ $<
|
$(CC) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(ODIR)/%.o: $(SRCDIR)/%.cpp $(DEPS)
|
$(ODIR)/%.o: $(SRCDIR)/%.cpp $(DEPS)
|
||||||
$(CC) $(CXXFLAGS) -c -o $@ $<
|
$(CC) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
$(BINDIR)/$(NAME): $(OBJ)
|
$(ODIR)/main.o: $(SRCDIR)/main.cpp $(DEPS) $(IDIR)/g_version.h
|
||||||
|
$(CC) $(CXXFLAGS) -c -o $@ $<
|
||||||
|
|
||||||
|
lxsh: $(OBJ)
|
||||||
$(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
|
$(CC) $(CXXFLAGS) -o $@ $^ $(LDFLAGS)
|
||||||
|
|
||||||
test: $(BINDIR)/$(NAME)
|
test: $(BINDIR)/$(NAME)
|
||||||
|
|
|
||||||
23
generate_version.sh
Executable file
23
generate_version.sh
Executable file
|
|
@ -0,0 +1,23 @@
|
||||||
|
#!/bin/sh
|
||||||
|
|
||||||
|
SHA_FULL=$(git rev-parse HEAD)
|
||||||
|
IDIR=$(grep '^IDIR=' Makefile | cut -d '=' -f2-)
|
||||||
|
file="$IDIR/g_version.h"
|
||||||
|
|
||||||
|
OLD_SHA=$(grep 'VERSION_SHA' "$file" | cut -d '"' -f2)
|
||||||
|
OLD_SUFFIX=$(grep 'VERSION_SUFFIX' "$file" | cut -d '"' -f2)
|
||||||
|
|
||||||
|
[ "$RELEASE" != "true" ] && SUFFIX="-dev-$(echo "$SHA_FULL" | cut -c1-10)"
|
||||||
|
|
||||||
|
|
||||||
|
if [ "$OLD_SHA" != "$SHA_FULL" ] || [ "$OLD_SUFFIX" != "$SUFFIX" ] ; then
|
||||||
|
cat > "$file" << EOF
|
||||||
|
#ifndef G_VERSION_H
|
||||||
|
#define G_VERSION_H
|
||||||
|
#define VERSION_SUFFIX "$SUFFIX"
|
||||||
|
#define VERSION_SHA "$SHA_FULL"
|
||||||
|
#endif
|
||||||
|
EOF
|
||||||
|
fi
|
||||||
|
|
||||||
|
exit 0
|
||||||
15
src/main.cpp
15
src/main.cpp
|
|
@ -15,20 +15,27 @@
|
||||||
#include "minimize.hpp"
|
#include "minimize.hpp"
|
||||||
#include "resolve.hpp"
|
#include "resolve.hpp"
|
||||||
|
|
||||||
|
#include "version.h"
|
||||||
|
#include "g_version.h"
|
||||||
|
|
||||||
void oneshot_opt_process(const char* arg0)
|
void oneshot_opt_process(const char* arg0)
|
||||||
{
|
{
|
||||||
if(options['h'])
|
if(options['h'])
|
||||||
{
|
{
|
||||||
print_help(arg0);
|
print_help(arg0);
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
if(options["help-commands"])
|
else if(options["version"])
|
||||||
|
{
|
||||||
|
printf("%s %s%s\n", arg0, VERSION_STRING, VERSION_SUFFIX);
|
||||||
|
printf("%s\n", VERSION_SHA);
|
||||||
|
}
|
||||||
|
else if(options["help-commands"])
|
||||||
{
|
{
|
||||||
print_include_help();
|
print_include_help();
|
||||||
printf("\n\n");
|
printf("\n\n");
|
||||||
print_resolve_help();
|
print_resolve_help();
|
||||||
exit(1);
|
|
||||||
}
|
}
|
||||||
|
exit(0);
|
||||||
}
|
}
|
||||||
|
|
||||||
int main(int argc, char* argv[])
|
int main(int argc, char* argv[])
|
||||||
|
|
@ -47,6 +54,8 @@ int main(int argc, char* argv[])
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
oneshot_opt_process(argv[0]);
|
||||||
|
|
||||||
// resolve input
|
// resolve input
|
||||||
std::string file;
|
std::string file;
|
||||||
if(args.size() > 0) // argument provided
|
if(args.size() > 0) // argument provided
|
||||||
|
|
|
||||||
|
|
@ -15,6 +15,7 @@ ztd::option_set gen_options()
|
||||||
ret.add(
|
ret.add(
|
||||||
ztd::option("\r [Help]"),
|
ztd::option("\r [Help]"),
|
||||||
ztd::option('h', "help", false, "Display this help message"),
|
ztd::option('h', "help", false, "Display this help message"),
|
||||||
|
ztd::option("version", false, "Display version"),
|
||||||
ztd::option("help-commands", false, "Print help for linker commands"),
|
ztd::option("help-commands", false, "Print help for linker commands"),
|
||||||
ztd::option("\r [Output]"),
|
ztd::option("\r [Output]"),
|
||||||
ztd::option('o', "output", true , "Output result script to file", "file"),
|
ztd::option('o', "output", true , "Output result script to file", "file"),
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue