Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added -h, -? CLI options for help & -v for redsocks-version.

  • Loading branch information...
commit 457c5eb79a35f301151808a1e46d94b465148dfc 1 parent 9fce864
@darkk authored
Showing with 33 additions and 4 deletions.
  1. +18 −1 Makefile
  2. +9 −3 main.c
  3. +6 −0 version.h
View
19 Makefile
@@ -1,4 +1,4 @@
-OBJS := parser.o main.o redsocks.o log.o http-connect.o socks4.o socks5.o http-relay.o base.o base64.o md5.o http-auth.o utils.o redudp.o dnstc.o
+OBJS := parser.o main.o redsocks.o log.o http-connect.o socks4.o socks5.o http-relay.o base.o base64.o md5.o http-auth.o utils.o redudp.o dnstc.o gen/version.o
SRCS := $(OBJS:.o=.c)
CONF := config.h
DEPS := .depend
@@ -29,6 +29,22 @@ $(CONF):
;; \
esac
+# Dependency on .git is useful to rebuild `version.c' after commit
+# FIXME: non-git builds should be supported.
+gen/version.c: *.c *.h gen/.build .git
+ rm -f $@.tmp
+ echo '/* this file is auto-generated during build */' > $@.tmp
+ echo '#include "../version.h"' > $@.tmp
+ echo 'const char* redsocks_version = "redsocks.git/"' >> $@.tmp
+ echo '"'`git describe --tags`'"' >> $@.tmp
+ [ `git status --porcelain | grep -v -c '^??'` != 0 ] && { echo '"-unclean"' >> $@.tmp; } || true
+ echo ';' >> $@.tmp
+ mv -f $@.tmp $@
+
+gen/.build:
+ mkdir -p gen
+ touch $@
+
base.c: $(CONF)
$(DEPS): $(SRCS)
@@ -64,3 +80,4 @@ clean:
distclean: clean
$(RM) tags $(DEPS)
+ $(RM) -r gen
View
12 main.c
@@ -25,6 +25,7 @@
#include "log.h"
#include "main.h"
#include "utils.h"
+#include "version.h"
extern app_subsys redsocks_subsys;
extern app_subsys base_subsys;
@@ -66,7 +67,7 @@ int main(int argc, char **argv)
int i;
red_srand();
- while ((opt = getopt(argc, argv, "tc:p:")) != -1) {
+ while ((opt = getopt(argc, argv, "h?vtc:p:")) != -1) {
switch (opt) {
case 't':
conftest = true;
@@ -77,13 +78,18 @@ int main(int argc, char **argv)
case 'p':
pidfile = optarg;
break;
+ case 'v':
+ puts(redsocks_version);
+ return EXIT_SUCCESS;
default:
printf(
- "Usage: %s [-t] [-c config] [-p pidfile]\n"
+ "Usage: %s [-?hvt] [-c config] [-p pidfile]\n"
+ " -h, -? this message\n"
+ " -v print version\n"
" -t test config syntax\n"
" -p write pid to pidfile\n",
argv[0]);
- return EXIT_FAILURE;
+ return (opt == '?' || opt == 'h') ? EXIT_SUCCESS : EXIT_FAILURE;
}
}
View
6 version.h
@@ -0,0 +1,6 @@
+#ifndef VERSION_H_SUN_NOV_27_03_22_30_2011
+#define VERSION_H_SUN_NOV_27_03_22_30_2011
+
+extern const char* redsocks_version;
+
+#endif // VERSION_H_SUN_NOV_27_03_22_30_2011
Please sign in to comment.
Something went wrong with that request. Please try again.