[PATCH] Makefile: move libraries to end of command; rename filename having a colon

From: Greg Reagle <greg.reagle_AT_umbc.edu>
Date: Thu, 19 Nov 2015 13:56:03 -0500

I need to have libraries at the end of the command line, after the object files, in order not to get undefined references. Also, the colon in the filename xmpp:time confuses my make severely, even when I try to escape it with a backslash.
---
 Makefile    |  22 ++++++-------
 xmpp:time.c | 106 ------------------------------------------------------------
 xmpp_time.c | 106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 117 insertions(+), 117 deletions(-)
 delete mode 100644 xmpp:time.c
 create mode 100644 xmpp_time.c
diff --git a/Makefile b/Makefile
index ac3a838..9907ad9 100644
--- a/Makefile
+++ b/Makefile
_AT_@ -12,45 +12,45 @@ LIBS_MXML := `pkg-config --libs mxml`
 .PHONY: all tests clean debug update install
 .SUFFIXES: .o .c
 
-BINS=sj messaged presenced iqd roster presence xmpp:time
+BINS=sj messaged presenced iqd roster presence xmpp_time
 
 all: $(BINS)
 
 # core deamon
 sj: sj.o sasl/sasl.o sasl/base64.o bxml/bxml.o
 	_AT_echo "Build: $@"
-	_AT_$(CC) -o $@ $(LDFLAGS) $(LIBS_MXML) $(LIBS_BSD) -lm \
-	    sj.o sasl/sasl.o sasl/base64.o bxml/bxml.o
+	_AT_$(CC) -o $@ $(LDFLAGS) sj.o sasl/sasl.o sasl/base64.o bxml/bxml.o\
+	     $(LIBS_MXML) $(LIBS_BSD) -lm
 
 messaged: messaged.o bxml/bxml.o
 	_AT_echo "Build: $@"
-	_AT_$(CC) -o $@ $(LDFLAGS) $(LIBS_MXML) $(LIBS_BSD) messaged.o bxml/bxml.o
+	_AT_$(CC) -o $@ $(LDFLAGS) messaged.o bxml/bxml.o $(LIBS_MXML) $(LIBS_BSD)
 
 presenced: presenced.o bxml/bxml.o
 	_AT_echo "Build: $@"
-	_AT_$(CC) -o $@ $(LDFLAGS) $(LIBS_MXML) $(LIBS_BSD) presenced.o bxml/bxml.o
+	_AT_$(CC) -o $@ $(LDFLAGS) presenced.o bxml/bxml.o $(LIBS_MXML) $(LIBS_BSD)
 
 iqd: iqd.o bxml/bxml.o
 	_AT_echo "Build: $@"
-	_AT_$(CC) -o $@ $(LDFLAGS) $(LIBS_MXML) iqd.o bxml/bxml.o
+	_AT_$(CC) -o $@ $(LDFLAGS) iqd.o bxml/bxml.o $(LIBS_MXML)
 
 # commandline tools
 roster: roster.o
 	_AT_echo "Build: $@"
-	_AT_$(CC) -o $@ $(LDFLAGS) $(LIBS_MXML) roster.o
+	_AT_$(CC) -o $@ $(LDFLAGS) roster.o $(LIBS_MXML)
 
 presence: presence.o
 	_AT_echo "Build: $@"
 	_AT_$(CC) -o $@ $(LDFLAGS) presence.o
 
 # extensions
-xmpp:time: xmpp:time.o
+xmpp_time: xmpp_time.o
 	_AT_echo "Build: $@"
-	_AT_$(CC) -o $@ $(LDFLAGS) $(LIBS_MXML) xmpp:time.o
+	_AT_$(CC) -o $@ $(LDFLAGS) xmpp_time.o $(LIBS_MXML)
 
-xmpp:time.o: xmpp:time.c
+xmpp_time.o: xmpp_time.c
 	_AT_echo "Build: $@"
-	_AT_$(CC) $(CFLAGS) $(CFLAGS_MXML) -c -o $@ xmpp:time.c
+	_AT_$(CC) $(CFLAGS) $(CFLAGS_MXML) -c -o $@ xmpp_time.c
 
 sj.o: sj.c bxml/bxml.h sasl/sasl.h
 	_AT_echo "Build: $@"
diff --git a/xmpp:time.c b/xmpp:time.c
deleted file mode 100644
index 2e41bdc..0000000
--- a/xmpp:time.c
+++ /dev/null
_AT_@ -1,106 +0,0 @@
-#include <err.h>
-#include <limits.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <time.h>
-#include <unistd.h>
-
-#include <mxml.h>
-
-static void
-send_time(FILE *fh, const char *to, const char *id)
-{
-	char tzo[BUFSIZ];
-	char utc[BUFSIZ];
-	time_t t = time(NULL);
-
-	/* +HHMM  */
-	strftime(tzo, sizeof tzo, "%z", localtime(&t));
-
-	/* convert "+HHMM" to "+HH:MM" */
-	tzo[6] = tzo[5];
-	tzo[5] = tzo[4];
-	tzo[4] = tzo[3];
-	tzo[3] = ':';
-
-	/* 2006-12-19T17:58:35Z */
-	strftime(utc, sizeof utc, "%FT%TZ", gmtime(&t));
-
-	fprintf(fh,
-	"<iq type='result' to='%s' id='%s'>"
-	  "<time xmlns='urn:xmpp:time'>"
-	    "<tzo>%s</tzo>"
-	    "<utc>%s</utc>"
-	  "</time>"
-	"</iq>", to, id, tzo, utc);
-}
-
-static void
-usage(void)
-{
-	fprintf(stderr, "xmpp:time [-d dir]\n");
-	exit(EXIT_FAILURE);
-}
-
-int
-main(int argc, char *argv[])
-{
-	/* HACK: we need this, cause mxml can't parse pure tags */
-	mxml_node_t *tree = NULL;
-	mxml_node_t *node = NULL;
-	const char *base = "<?xml ?>";
-	const char *id = NULL;
-	const char *from = NULL;
-	const char *type = NULL;
-	char *dir = ".";
-	char out_file[PATH_MAX];
-	FILE *fh;
-	int ch;
-
-	while ((ch = getopt(argc, argv, "d:h")) != -1) {
-		switch (ch) {
-		case 'd':
-			if ((dir = strdup(optarg)) == NULL)
-				err(EXIT_FAILURE, "strdup");
-			break;
-		case 'h':
-		default:
-			usage();
-			/* NOTREACHED */
-		}
-	}
-	argc -= optind;
-	argv += optind;
-
-	if ((tree = mxmlLoadString(NULL, base, MXML_NO_CALLBACK)) == NULL)
-		err(EXIT_FAILURE, "unable to read xml tree");
-	mxmlLoadFile(tree, stdin, MXML_NO_CALLBACK); 
-
-	/* check iq tag */
-	if ((node = tree->child) == NULL)
-		errx(EXIT_FAILURE, "unable to parse xml data");
-
-	if ((id = mxmlElementGetAttr(node, "id")) == NULL)
-		errx(EXIT_FAILURE, "iq stanze has no \"id\" attribute");
-
-	if ((from = mxmlElementGetAttr(node, "from")) == NULL)
-		errx(EXIT_FAILURE, "iq stanze has no \"from\" attribute");
-
-	if ((type = mxmlElementGetAttr(node, "type")) == NULL)
-		errx(EXIT_FAILURE, "iq stanze has no \"type\" attribute");
-
-	if (strcmp(type, "get") != 0)
-		errx(EXIT_FAILURE, "unable to handle iq type: %s", type);
-
-	/* open file for output */
-	snprintf(out_file, sizeof out_file, "%s/in", dir);
-	if ((fh = fopen(out_file, "w")) == NULL)
-		err(EXIT_FAILURE, "fopen");
-
-	send_time(fh, from, id);
-
-	if (fclose(fh) == EOF)
-		err(EXIT_FAILURE, "fclose");
-
-	return EXIT_SUCCESS;
-}
diff --git a/xmpp_time.c b/xmpp_time.c
new file mode 100644
index 0000000..2e41bdc
--- /dev/null
+++ b/xmpp_time.c
_AT_@ -0,0 +1,106 @@
+#include <err.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <time.h>
+#include <unistd.h>
+
+#include <mxml.h>
+
+static void
+send_time(FILE *fh, const char *to, const char *id)
+{
+	char tzo[BUFSIZ];
+	char utc[BUFSIZ];
+	time_t t = time(NULL);
+
+	/* +HHMM  */
+	strftime(tzo, sizeof tzo, "%z", localtime(&t));
+
+	/* convert "+HHMM" to "+HH:MM" */
+	tzo[6] = tzo[5];
+	tzo[5] = tzo[4];
+	tzo[4] = tzo[3];
+	tzo[3] = ':';
+
+	/* 2006-12-19T17:58:35Z */
+	strftime(utc, sizeof utc, "%FT%TZ", gmtime(&t));
+
+	fprintf(fh,
+	"<iq type='result' to='%s' id='%s'>"
+	  "<time xmlns='urn:xmpp:time'>"
+	    "<tzo>%s</tzo>"
+	    "<utc>%s</utc>"
+	  "</time>"
+	"</iq>", to, id, tzo, utc);
+}
+
+static void
+usage(void)
+{
+	fprintf(stderr, "xmpp:time [-d dir]\n");
+	exit(EXIT_FAILURE);
+}
+
+int
+main(int argc, char *argv[])
+{
+	/* HACK: we need this, cause mxml can't parse pure tags */
+	mxml_node_t *tree = NULL;
+	mxml_node_t *node = NULL;
+	const char *base = "<?xml ?>";
+	const char *id = NULL;
+	const char *from = NULL;
+	const char *type = NULL;
+	char *dir = ".";
+	char out_file[PATH_MAX];
+	FILE *fh;
+	int ch;
+
+	while ((ch = getopt(argc, argv, "d:h")) != -1) {
+		switch (ch) {
+		case 'd':
+			if ((dir = strdup(optarg)) == NULL)
+				err(EXIT_FAILURE, "strdup");
+			break;
+		case 'h':
+		default:
+			usage();
+			/* NOTREACHED */
+		}
+	}
+	argc -= optind;
+	argv += optind;
+
+	if ((tree = mxmlLoadString(NULL, base, MXML_NO_CALLBACK)) == NULL)
+		err(EXIT_FAILURE, "unable to read xml tree");
+	mxmlLoadFile(tree, stdin, MXML_NO_CALLBACK); 
+
+	/* check iq tag */
+	if ((node = tree->child) == NULL)
+		errx(EXIT_FAILURE, "unable to parse xml data");
+
+	if ((id = mxmlElementGetAttr(node, "id")) == NULL)
+		errx(EXIT_FAILURE, "iq stanze has no \"id\" attribute");
+
+	if ((from = mxmlElementGetAttr(node, "from")) == NULL)
+		errx(EXIT_FAILURE, "iq stanze has no \"from\" attribute");
+
+	if ((type = mxmlElementGetAttr(node, "type")) == NULL)
+		errx(EXIT_FAILURE, "iq stanze has no \"type\" attribute");
+
+	if (strcmp(type, "get") != 0)
+		errx(EXIT_FAILURE, "unable to handle iq type: %s", type);
+
+	/* open file for output */
+	snprintf(out_file, sizeof out_file, "%s/in", dir);
+	if ((fh = fopen(out_file, "w")) == NULL)
+		err(EXIT_FAILURE, "fopen");
+
+	send_time(fh, from, id);
+
+	if (fclose(fh) == EOF)
+		err(EXIT_FAILURE, "fclose");
+
+	return EXIT_SUCCESS;
+}
-- 
1.9.1
--------------010002000401070506020708--
Received on Mon Sep 17 2001 - 00:00:00 CEST

This archive was generated by hypermail 2.3.0 : Fri Nov 20 2015 - 07:12:10 CET