Skip to content

Instantly share code, notes, and snippets.

@caffeineshock
Created May 24, 2012 12:53
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save caffeineshock/2781392 to your computer and use it in GitHub Desktop.
Save caffeineshock/2781392 to your computer and use it in GitHub Desktop.
App to download an html document and the contained objects like a browser
This program is designed to download an HTML document, parse it and then download linked CSS, JS and favicon files.
It currently uses libcurl for HTTP requests, libxml2 to parse the HTML and glib for complex datastructures.
compile with 'make' and run with './fetcher http://www.example.org/'
#include "fetcher.h"
/* Maximum connections to open per distinct host */
#define MAX_CONNS_PER_HOST 6
GSList* objs;
GHashTable* parser_table;
GHashTable* download_tasks;
gchar* base_url;
CURLSH* share;
FILE* first_doc_fp;
static gboolean verbose = FALSE;
static gboolean save = FALSE;
static GOptionEntry entries[] = {
{ "verbose", 'v', 0, G_OPTION_ARG_NONE, &verbose, "Be verbose", NULL },
{ "save", 's', 0, G_OPTION_ARG_NONE, &save, "Save downloaded files", NULL },
{ NULL }
};
gint main(gint argc, gchar** argv) {
gchar* doc_content;
GError* error = NULL;
GOptionContext* context = g_option_context_new("URL");
g_option_context_add_main_entries(context, entries, NULL);
if (!g_option_context_parse(context, &argc, &argv, &error)) {
g_fprintf(stderr, "option parsing failed: %s\n", error->message);
exit(EXIT_FAILURE);
}
if (argc != 2) {
g_fprintf(stderr, "%s", g_option_context_get_help(context, TRUE, NULL));
exit(EXIT_FAILURE);
}
/* Write argv[1] to global string for later use in find_objects */
base_url = get_url_base(argv[1]);
/* Download the requested document */
doc_content = get_document_content(argv[1]);
/* Initialize object list for external objects */
objs = NULL;
/* Initialize a hashtable containing a parser function associated with a tag name */
parser_table_init();
/* Parse the received HTML */
parse_html((xmlChar*) doc_content);
/* Group objects by hostname and put them in queues */
download_tasks = g_hash_table_new(g_str_hash, g_str_equal);
g_slist_foreach(objs, queue_downloads, download_tasks);
/* Download all objects */
download_objects();
/* Clean up */
g_slist_free(objs);
g_hash_table_destroy(parser_table);
g_hash_table_destroy(download_tasks);
curl_global_cleanup();
return 0;
}
void ignore_xml_errors(void* ctx, const char* msg, ...) {
return;
}
gchar* get_document_content(gchar* url) {
CURL* handle = curl_easy_init();
GString* directory, * filename;
/* Initialize a handle through which DNS/SSL information is shared */
share = curl_share_init();
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_DNS);
curl_share_setopt(share, CURLSHOPT_SHARE, CURL_LOCK_DATA_SSL_SESSION);
/* String for the data of the first page */
GString *first_document = g_string_new("");
/* Open file handle if all is to be saved */
if (save) {
directory = g_string_new("");
filename = g_string_new("");
/* If URL contains no filename ... */
if (url_to_local_path(url, directory, filename) < 0) {
if (!g_str_has_suffix(url, "/")) {
directory = g_string_append(directory, "/");
}
/* ... append index.htm */
directory = g_string_append(directory, "index.htm");
} else {
/* ... else just append it */
directory = g_string_append(directory, filename->str);
}
if (g_str_has_prefix(url, "https")) {
directory = g_string_prepend(directory, "https://");
} else {
directory = g_string_prepend(directory, "http://");
}
first_doc_fp = mirror_path(directory->str);
g_string_free(filename, TRUE);
g_string_free(directory, TRUE);
}
/* Set options */
curl_easy_setopt(handle, CURLOPT_URL, url);
curl_easy_setopt(handle, CURLOPT_SHARE, share); /* Set the DNS/SSL share handle */
curl_easy_setopt(handle, CURLOPT_FOLLOWLOCATION, 1L); /* Follow redirects */
curl_easy_setopt(handle, CURLOPT_USERAGENT, "Mozilla/5.0"); /* Fake useragent header */
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, save_to_gstring);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, first_document);
/* Download of the first page */
curl_easy_perform(handle);
if (save) {
fclose(first_doc_fp);
}
return g_string_free(first_document, FALSE);
}
gchar* get_url_base(gchar* url) {
gint match_count;
GString* base = g_string_new("");
gchar** parts = crack_url(url, &match_count);
if (match_count < 3) {
g_fprintf(stderr, "Malformed url: %s\n", url);
exit(EXIT_FAILURE);
}
g_string_append(base, parts[1]);
g_string_append(base, parts[2]);
g_strfreev(parts);
return g_string_free(base, FALSE);
}
gchar** crack_url(gchar* url, gint* match_count) {
gchar *url_pattern;
gchar** parts;
GRegex *regex;
GMatchInfo *match_info;
if (!url_is_absolute(url)) {
g_fprintf(stderr, "URL is not absolute: <%s>\n", url);
exit(EXIT_FAILURE);
}
url_pattern = "^(http[s]?:\\/\\/)([^\\/]+)(.*?)([^\\/]*)$";
regex = g_regex_new(url_pattern, G_REGEX_CASELESS, 0, NULL);
g_regex_match(regex, url, 0, &match_info);
parts = g_match_info_fetch_all(match_info);
*match_count = g_match_info_get_match_count(match_info);
g_match_info_free(match_info);
g_regex_unref(regex);
return parts;
}
size_t save_to_gstring(char *ptr, size_t size, size_t nmemb, void *s) {
g_string_append(s, ptr);
if (save) {
fwrite(ptr, size, nmemb, first_doc_fp);
}
return size * nmemb;
}
size_t ignore(char *ptr, size_t size, size_t nmemb, void *s) {
return size * nmemb;
}
void parser_table_init() {
parser_table = g_hash_table_new(g_str_hash, g_str_equal);
g_hash_table_insert(parser_table, "img", parse_img);
g_hash_table_insert(parser_table, "link", parse_link);
g_hash_table_insert(parser_table, "script", parse_script);
}
void find_objects(htmlNodePtr element) {
htmlNodePtr node = element;
gchar* (*parser)(GHashTable*);
gchar* canonical_name;
gchar* url;
GString* absolute_url;
GHashTable* attrs;
for(; node != NULL; node = node->next) {
if(node->type == XML_ELEMENT_NODE) {
canonical_name = g_utf8_strdown((const gchar*) node->name, -1);
parser = g_hash_table_lookup(parser_table, canonical_name);
if (parser != NULL) {
attrs = get_attributes(node);
url = g_strdup((*parser)(attrs));
g_hash_table_destroy(attrs);
if (url != NULL) {
if (!url_is_absolute(url)) {
absolute_url = g_string_new(url);
g_string_prepend(absolute_url, base_url);
url = g_string_free(absolute_url, FALSE);
}
objs = g_slist_append(objs, url);
}
}
if(node->children != NULL) {
find_objects(node->children);
}
}
}
}
void parse_html(xmlChar* html) {
xmlSetGenericErrorFunc(NULL, ignore_xml_errors);
htmlDocPtr doc = htmlParseDoc(html, "UTF-8");
if(doc != NULL) {
htmlNodePtr root = xmlDocGetRootElement(doc);
if(root != NULL) {
find_objects(root);
}
xmlFreeDoc(doc);
doc = NULL;
}
}
gchar* parse_img(GHashTable* attrs) {
gchar* source = g_hash_table_lookup(attrs, "src");
if (source != NULL && verbose) {
g_printf("Found an image \t\t <%s>\n", source);
}
return source;
}
gchar* parse_link(GHashTable* attrs) {
gchar* rel = g_hash_table_lookup(attrs, "rel");
gchar* source = g_hash_table_lookup(attrs, "href");
if (g_strcmp0(rel, "stylesheet") == 0) {
if (verbose) {
g_printf("Found a stylesheet \t <%s>\n", source);
}
return source;
}
if (g_strcmp0(rel, "shortcut icon") == 0) {
if (verbose) {
g_printf("Found a shortcut icon \t <%s>\n", source);
}
return source;
}
return NULL;
}
gchar* parse_script(GHashTable* attrs) {
gchar* rel = g_hash_table_lookup(attrs, "type");
gchar* source = g_hash_table_lookup(attrs, "src");
if (g_strcmp0(rel, "text/javascript") == 0 && source != NULL) {
if (verbose) {
g_printf("Found a JS file \t <%s>\n", source);
}
return source;
}
return NULL;
}
GHashTable* get_attributes(htmlNodePtr node) {
xmlAttrPtr curr_attr;
gchar* canonical_name;
GHashTable* attrs = g_hash_table_new(g_str_hash, g_str_equal);
for(curr_attr = node->properties; curr_attr != NULL; curr_attr = curr_attr->next) {
canonical_name = g_utf8_strdown((const gchar*) curr_attr->name, -1);
g_hash_table_insert(attrs, canonical_name, curr_attr->children->content);
}
return attrs;
}
gboolean url_is_absolute(const gchar* url) {
if (url) {
const gchar* ptr = url;
while (*ptr) {
if (*ptr == ':') return TRUE;
if (*ptr == '/' || *ptr == '?' || *ptr == '#') break;
ptr++;
}
}
return FALSE;
}
gchar* get_hostname_from_url(gchar* url) {
gint match_count;
gchar* hostname;
gchar** parts = crack_url(url, &match_count);
if (match_count < 3) {
g_fprintf(stderr, "Malformed url: %s\n", url);
exit(EXIT_FAILURE);
}
hostname = g_strdup(parts[2]);
g_strfreev(parts);
return hostname;
}
void queue_downloads(gpointer data, gpointer download_tasks) {
gchar* url = data;
gchar* hostname = get_hostname_from_url(url);
DownloadTasks* tasks = g_hash_table_lookup(download_tasks, hostname);
/* If for the first time a hostname is used initialize a new queue */
if (tasks == NULL) {
tasks = g_malloc(sizeof(DownloadTasks));
tasks->unfinished = g_queue_new();
tasks->running = NULL;
g_hash_table_insert(download_tasks, hostname, tasks);
}
if (verbose) {
g_printf("download_tasks: %s -> %s\n", hostname, url);
}
/* Add the actual URL to the end of the queue */
g_queue_push_tail(tasks->unfinished, url);
}
void download_objects() {
CURLM* multi_handle;
int still_running;
/* init a multi stack */
multi_handle = curl_multi_init();
/* Add downloads/handles to the multihandle */
g_hash_table_foreach(download_tasks, add_tasks, multi_handle);
/* we start some action by calling perform right away */
curl_multi_perform(multi_handle, &still_running);
while (still_running) {
check_messages(multi_handle);
curl_multi_perform(multi_handle, &still_running);
}
check_messages(multi_handle);
}
void add_tasks(gpointer key, gpointer value, gpointer multi_handle) {
CURL* handle;
gchar* url;
FILE* fp;
gint i = 0;
DownloadTasks* tasks = value;
for (i = 0; i < MAX_CONNS_PER_HOST && !g_queue_is_empty(tasks->unfinished); i++) {
/* Get new task from the queue */
url = g_queue_pop_head(tasks->unfinished);
if (verbose) {
g_printf("Adding URL <%s>\n", url);
}
/* Initialize a new curl handle */
handle = curl_easy_init();
/* Set options */
curl_easy_setopt(handle, CURLOPT_URL, url);
curl_easy_setopt(handle, CURLOPT_SHARE, share); /* Set the DNS/SSL share handle */
/* Generate Filepointer and copy object to that if we want to mirror the site */
if (save) {
fp = mirror_path(url);
curl_easy_setopt(handle, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(handle, CURLOPT_PRIVATE, fp);
} else {
curl_easy_setopt(handle, CURLOPT_WRITEFUNCTION, ignore);
}
/* Add newly created handle to the multi handle */
curl_multi_add_handle(multi_handle, handle);
/* Save the handle associated with hostname and url */
tasks->running = g_slist_prepend(tasks->running, handle);
}
}
gint url_to_local_path(gchar* url, GString* directory, GString* filename) {
gint match_count, code = 0;
gchar** parts = crack_url(url, &match_count);
g_string_append(directory, parts[2]);
g_string_append(directory, parts[3]);
if (*parts[4] == '\0') {
code = -1;
} else {
g_string_append(filename, parts[4]);
}
g_strfreev(parts);
return code;
}
FILE* mirror_path(gchar* url) {
GString* directory = g_string_new("");
GString* filename = g_string_new("");
GString* path = g_string_new("/");
FILE* new_fp;
if (url_to_local_path(url, directory, filename) < 0) {
g_fprintf(stderr, "No filename in URL %s\n", url);
exit(EXIT_FAILURE);
}
if (verbose) {
g_printf("lets make sure that %s exists\n", directory->str);
}
g_mkdir_with_parents(directory->str, 0700);
g_string_prepend(path, g_string_free(directory, FALSE));
g_string_append(path, g_string_free(filename, FALSE));
if (verbose) {
g_printf("Open %s for some saving action\n", path->str);
}
new_fp = fopen(path->str, "w");
g_string_free(path, TRUE);
return new_fp;
}
void notify_task_completed(gpointer key, gpointer value, gpointer handle) {
DownloadTasks* tasks = value;
gchar* effective_url;
gchar* new_url;
HandleInfo* info = handle;
FILE* fp = NULL;
if (g_slist_find(tasks->running, info->handle) != NULL) {
curl_easy_getinfo(info->handle, CURLINFO_EFFECTIVE_URL, &effective_url);
if (verbose) {
g_printf("Download completed: %s\n", effective_url);
}
/* Remove easy handle from multi handle for now */
curl_multi_remove_handle(info->multi_handle, info->handle);
/* Reuse the handle for another download from the queue */
if (!g_queue_is_empty(tasks->unfinished)) {
/* Get new URL from the queue */
new_url = g_queue_pop_head(tasks->unfinished);
if (verbose) {
g_printf("Adding URL <%s> (Reuse of handle)\n", new_url);
}
/* Change URL */
curl_easy_setopt(info->handle, CURLOPT_URL, new_url);
/* Get new filepointer */
if (save) {
fp = mirror_path(new_url);
curl_easy_setopt(info->handle, CURLOPT_WRITEDATA, fp);
curl_easy_setopt(info->handle, CURLOPT_PRIVATE, fp);
}
/* Add handle to the multi handle again */
curl_multi_add_handle(info->multi_handle, info->handle);
} else {
curl_easy_getinfo(info->handle, CURLINFO_PRIVATE, (char**) &fp);
curl_easy_cleanup(info->handle);
fclose(fp);
}
}
}
void check_messages(CURLM* multi_handle) {
CURLMsg *msg;
int msgs_left;
HandleInfo info;
info.multi_handle = multi_handle;
/* See how the transfers are doing */
while ((msg = curl_multi_info_read(multi_handle, &msgs_left))) {
if (msg->msg == CURLMSG_DONE) {
info.handle = msg->easy_handle;
/* Notfiy the DownloadTasks that a transfer is complete */
g_hash_table_foreach(download_tasks, notify_task_completed, &info);
}
}
}
#ifndef FETCHER_H_
#define FETCHER_H_
#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>
#include <glib.h>
#include <glib/gprintf.h>
#include <libxml/HTMLparser.h>
typedef struct _DownloadTasks DownloadTasks;
struct _DownloadTasks {
GQueue* unfinished;
GSList* running;
};
typedef struct _HandleInfo HandleInfo;
struct _HandleInfo {
CURLM* multi_handle;
CURL* handle;
};
void ignore_xml_errors(void* ctx, const char* msg, ...);
gchar* get_document_content(gchar* url);
gchar* get_url_base(gchar*);
gchar** crack_url(gchar*, gint*);
size_t save_to_gstring(char*, size_t, size_t, void*);
size_t ignore(char*, size_t, size_t, void*);
void parser_table_init(void);
void find_links(htmlNodePtr);
void parse_html(xmlChar*);
gchar* parse_img(GHashTable*);
gchar* parse_link(GHashTable*);
gchar* parse_script(GHashTable*);
GHashTable* get_attributes(htmlNodePtr);
gboolean url_is_absolute(const gchar*);
gchar* get_hostname_from_url(gchar*);
void queue_downloads(gpointer, gpointer);
void download_objects();
void add_tasks(gpointer, gpointer, gpointer);
gint url_to_local_path(gchar*, GString*, GString*);
FILE* mirror_path(gchar*);
void notify_task_completed(gpointer, gpointer, gpointer);
void check_messages(CURLM*);
#endif /* FETCHER_H_ */
#############################################################################
#
# Generic Makefile for C/C++ Program
#
# License: GPL (General Public License)
# Author: whyglinux <whyglinux AT gmail DOT com>
# Date: 2006/03/04 (version 0.1)
# 2007/03/24 (version 0.2)
# 2007/04/09 (version 0.3)
# 2007/06/26 (version 0.4)
# 2008/04/05 (version 0.5)
#
# Description:
# ------------
# This is an easily customizable makefile template. The purpose is to
# provide an instant building environment for C/C++ programs.
#
# It searches all the C/C++ source files in the specified directories,
# makes dependencies, compiles and links to form an executable.
#
# Besides its default ability to build C/C++ programs which use only
# standard C/C++ libraries, you can customize the Makefile to build
# those using other libraries. Once done, without any changes you can
# then build programs using the same or less libraries, even if source
# files are renamed, added or removed. Therefore, it is particularly
# convenient to use it to build codes for experimental or study use.
#
# GNU make is expected to use the Makefile. Other versions of makes
# may or may not work.
#
# Usage:
# ------
# 1. Copy the Makefile to your program directory.
# 2. Customize in the "Customizable Section" only if necessary:
# * to use non-standard C/C++ libraries, set pre-processor or compiler
# options to <MY_CFLAGS> and linker ones to <MY_LIBS>
# (See Makefile.gtk+-2.0 for an example)
# * to search sources in more directories, set to <SRCDIRS>
# * to specify your favorite program name, set to <PROGRAM>
# 3. Type make to start building your program.
#
# Make Target:
# ------------
# The Makefile provides the following targets to make:
# $ make compile and link
# $ make NODEP=yes compile and link without generating dependencies
# $ make objs compile only (no linking)
# $ make tags create tags for Emacs editor
# $ make ctags create ctags for VI editor
# $ make clean clean objects and the executable file
# $ make distclean clean objects, the executable and dependencies
# $ make help get the usage of the makefile
#
#===========================================================================
## Customizable Section: adapt those variables to suit your program.
##==========================================================================
# The pre-processor and compiler options.
MY_CFLAGS = -I/usr/include/glib-2.0 -I/usr/lib/x86_64-linux-gnu/glib-2.0/include -I/usr/include/libxml2
# The linker options.
MY_LIBS = -lcurl -lxml2 -lglib-2.0
# The pre-processor options used by the cpp (man cpp for more).
CPPFLAGS = -Wall -ansi
# The options used in linking as well as in any direct use of ld.
LDFLAGS =
# The directories in which source files reside.
# If not specified, only the current directory will be serached.
SRCDIRS =
# The executable file name.
# If not specified, current directory name or `a.out' will be used.
PROGRAM =
## Implicit Section: change the following only when necessary.
##==========================================================================
# The source file types (headers excluded).
# .c indicates C source files, and others C++ ones.
SRCEXTS = .c .C .cc .cpp .CPP .c++ .cxx .cp
# The header file types.
HDREXTS = .h .H .hh .hpp .HPP .h++ .hxx .hp
# The pre-processor and compiler options.
# Users can override those variables from the command line.
CFLAGS = -g -O2
CXXFLAGS= -g -O2
# The C program compiler.
#CC = gcc
# The C++ program compiler.
#CXX = g++
# Un-comment the following line to compile C programs as C++ ones.
#CC = $(CXX)
# The command used to delete file.
#RM = rm -f
ETAGS = etags
ETAGSFLAGS =
CTAGS = ctags
CTAGSFLAGS =
## Stable Section: usually no need to be changed. But you can add more.
##==========================================================================
SHELL = /bin/sh
EMPTY =
SPACE = $(EMPTY) $(EMPTY)
ifeq ($(PROGRAM),)
CUR_PATH_NAMES = $(subst /,$(SPACE),$(subst $(SPACE),_,$(CURDIR)))
PROGRAM = $(word $(words $(CUR_PATH_NAMES)),$(CUR_PATH_NAMES))
ifeq ($(PROGRAM),)
PROGRAM = a.out
endif
endif
ifeq ($(SRCDIRS),)
SRCDIRS = .
endif
SOURCES = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(SRCEXTS))))
HEADERS = $(foreach d,$(SRCDIRS),$(wildcard $(addprefix $(d)/*,$(HDREXTS))))
SRC_CXX = $(filter-out %.c,$(SOURCES))
OBJS = $(addsuffix .o, $(basename $(SOURCES)))
DEPS = $(OBJS:.o=.d)
## Define some useful variables.
DEP_OPT = $(shell if `$(CC) --version | grep "GCC" >/dev/null`; then \
echo "-MM -MP"; else echo "-M"; fi )
DEPEND = $(CC) $(DEP_OPT) $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS)
DEPEND.d = $(subst -g ,,$(DEPEND))
COMPILE.c = $(CC) $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS) -c
COMPILE.cxx = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) -c
LINK.c = $(CC) $(MY_CFLAGS) $(CFLAGS) $(CPPFLAGS) $(LDFLAGS)
LINK.cxx = $(CXX) $(MY_CFLAGS) $(CXXFLAGS) $(CPPFLAGS) $(LDFLAGS)
.PHONY: all objs tags ctags clean distclean help show
# Delete the default suffixes
.SUFFIXES:
all: $(PROGRAM)
# Rules for creating dependency files (.d).
#------------------------------------------
%.d:%.c
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
%.d:%.C
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
%.d:%.cc
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
%.d:%.cpp
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
%.d:%.CPP
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
%.d:%.c++
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
%.d:%.cp
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
%.d:%.cxx
@echo -n $(dir $<) > $@
@$(DEPEND.d) $< >> $@
# Rules for generating object files (.o).
#----------------------------------------
objs:$(OBJS)
%.o:%.c
$(COMPILE.c) $< -o $@
%.o:%.C
$(COMPILE.cxx) $< -o $@
%.o:%.cc
$(COMPILE.cxx) $< -o $@
%.o:%.cpp
$(COMPILE.cxx) $< -o $@
%.o:%.CPP
$(COMPILE.cxx) $< -o $@
%.o:%.c++
$(COMPILE.cxx) $< -o $@
%.o:%.cp
$(COMPILE.cxx) $< -o $@
%.o:%.cxx
$(COMPILE.cxx) $< -o $@
# Rules for generating the tags.
#-------------------------------------
tags: $(HEADERS) $(SOURCES)
$(ETAGS) $(ETAGSFLAGS) $(HEADERS) $(SOURCES)
ctags: $(HEADERS) $(SOURCES)
$(CTAGS) $(CTAGSFLAGS) $(HEADERS) $(SOURCES)
# Rules for generating the executable.
#-------------------------------------
$(PROGRAM):$(OBJS)
ifeq ($(SRC_CXX),) # C program
$(LINK.c) $(OBJS) $(MY_LIBS) -o $@
@echo Type ./$@ to execute the program.
else # C++ program
$(LINK.cxx) $(OBJS) $(MY_LIBS) -o $@
@echo Type ./$@ to execute the program.
endif
ifndef NODEP
ifneq ($(DEPS),)
sinclude $(DEPS)
endif
endif
clean:
$(RM) $(OBJS) $(PROGRAM) $(PROGRAM).exe
distclean: clean
$(RM) $(DEPS) TAGS
# Show help.
help:
@echo 'Generic Makefile for C/C++ Programs (gcmakefile) version 0.5'
@echo 'Copyright (C) 2007, 2008 whyglinux <whyglinux@hotmail.com>'
@echo
@echo 'Usage: make [TARGET]'
@echo 'TARGETS:'
@echo ' all (=make) compile and link.'
@echo ' NODEP=yes make without generating dependencies.'
@echo ' objs compile only (no linking).'
@echo ' tags create tags for Emacs editor.'
@echo ' ctags create ctags for VI editor.'
@echo ' clean clean objects and the executable file.'
@echo ' distclean clean objects, the executable and dependencies.'
@echo ' show show variables (for debug use only).'
@echo ' help print this message.'
@echo
@echo 'Report bugs to <whyglinux AT gmail DOT com>.'
# Show variables (for debug use only.)
show:
@echo 'PROGRAM :' $(PROGRAM)
@echo 'SRCDIRS :' $(SRCDIRS)
@echo 'HEADERS :' $(HEADERS)
@echo 'SOURCES :' $(SOURCES)
@echo 'SRC_CXX :' $(SRC_CXX)
@echo 'OBJS :' $(OBJS)
@echo 'DEPS :' $(DEPS)
@echo 'DEPEND :' $(DEPEND)
@echo 'COMPILE.c :' $(COMPILE.c)
@echo 'COMPILE.cxx :' $(COMPILE.cxx)
@echo 'link.c :' $(LINK.c)
@echo 'link.cxx :' $(LINK.cxx)
## End of the Makefile ## Suggestions are welcome ## All rights reserved ##
#############################################################################
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment