Althttpd

Check-in [cad917d5b2]
Login

Check-in [cad917d5b2]

Many hyperlinks are disabled.
Use anonymous login to enable hyperlinks.

Overview
Comment:Revamp makefiles. Use the new VERSION file to set the version number. The mkversion.c program builds VERSION.h which is imported by programs to access precise version information. Update build targest.
Downloads: Tarball | ZIP archive | SQL archive
Timelines: family | ancestors | descendants | both | trunk
Files: files | file ages | folders
SHA3-256: cad917d5b2cf475d2f8e7dd6f5c25b12f4eb01fc8d36d8bad34b5687cb84fbb4
User & Date: drh 2024-04-14 18:18:07
Context
2024-04-14
19:31
With the static-ssl.mk, do a full static link of logtodb. ... (check-in: d796f3b847 user: drh tags: trunk)
18:18
Revamp makefiles. Use the new VERSION file to set the version number. The mkversion.c program builds VERSION.h which is imported by programs to access precise version information. Update build targest. ... (check-in: cad917d5b2 user: drh tags: trunk)
2024-04-13
11:41
Add the --tail option to the logtodb utility program. ... (check-in: d4699f1e41 user: drh tags: trunk)
Changes
Hide Diffs Unified Diffs Ignore Whitespace Patch

Changes to Makefile.










1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43



44
45
46
47
48










default: althttpd althttpsd
SHELL = /bin/bash
VERSION_NUMBER = 2.0
CC=cc
CFLAGS=-Os -Wall -Wextra

manifest:
	@if which fossil > /dev/null; then \
		fossil update --nosync current; \
	else \
	  echo "fossil binary not found. Version hash/time might be incorrect."
	fi
manifest.uuid: manifest

# We do the version-setting CPPFLAGS this way, instead of via
# $(shell...), for the sake of portability with BSD Make. Some hoops
# have to be jumped through to get the escaping "just right," though.
version: Makefile manifest.uuid
	@hash=`cut -c1-12 manifest.uuid`; \
	time=`sed -n 2p manifest | cut -d' ' -f2`; \
	{ echo -n "ALTHTTPD_VERSION=\""; \
		echo '$(VERSION_NUMBER)' "[$$hash] [$$time]\""; \
	} > $@

althttpd:	althttpd.c version
	@flags="`cat version`"; set -x; \
	$(CC) $(CFLAGS) "-D$$flags" -o althttpd althttpd.c

althttpsd:	althttpd.c version
	@flags="`cat version`"; set -x; \
	$(CC) $(CFLAGS) "-D$$flags" -fPIC -o althttpsd -DENABLE_TLS althttpd.c -lssl -lcrypto

static-althttpd:	althttpd.c version
	@flags="`cat version`"; set -x; \
	$(CC) $(CFLAGS) "-D$$flags" -static -o althttpd althttpd.c

static-althttpsd:	althttpd.c version
	@flags="`cat version`"; set -x; \
	$(CC) $(CFLAGS) "-D$$flags" -static -fPIC -o althttpsd -DENABLE_TLS althttpd.c -lssl -lcrypto -lpthread -ldl

sqlite3.o:	sqlite3.c
	$(CC) $(CFLAGS) -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_THREADSAFE=0 -c -o sqlite3.o sqlite3.c




logtodb:	logtodb.c sqlite3.o
	$(CC) $(CFLAGS) -o logtodb logtodb.c sqlite3.o

clean:
	rm -f althttpd althttpsd version sqlite3.o

>
>
>
>
>
>
>
>
>

<
<

|

<
<
<
<
<
<
|
|
<
<
<
|
<
<
<
<
<

|
<
|

|
<
|

|
<
|

|
<
|




>
>
>
|
|


|
>
1
2
3
4
5
6
7
8
9
10


11
12
13






14
15



16





17
18

19
20
21

22
23
24

25
26
27

28
29
30
31
32
33
34
35
36
37
38
39
40
41
# Makefile for althttpd and utilities.  Summary of targets:
#
#    make althttpd                 <--  althttpd without OpenSSL
#    make althttpsd                <--  althttpd including OpenSSL for TLS support
#    make static-althttpd          <--  statically linked version of althttpd
#    make static-althttpsd         <--  statically linked version of althttpsd
#    make logtodb                  <--  Program to build SQLite database from log file
#    make static-logtodb           <--  Statically linked version of the same
#
default: althttpd althttpsd


CC=cc
CFLAGS=-Os -Wall -Wextra -I.







VERSION.h:	VERSION manifest manifest.uuid mkversion.c
	$(CC) -o mkversion mkversion.c



	./mkversion manifest.uuid manifest VERSION >VERSION.h






althttpd:	althttpd.c VERSION.h

	$(CC) $(CFLAGS) -o althttpd althttpd.c

althttpsd:	althttpd.c VERSION.h

	$(CC) $(CFLAGS) -fPIC -o althttpsd -DENABLE_TLS althttpd.c -lssl -lcrypto

static-althttpd:	althttpd.c VERSION.h

	$(CC) $(CFLAGS) -static -o static-althttpd althttpd.c

static-althttpsd:	althttpd.c VERSION.h

	$(CC) $(CFLAGS) -static -fPIC -o static-althttpsd -DENABLE_TLS althttpd.c -lssl -lcrypto -lpthread -ldl

sqlite3.o:	sqlite3.c
	$(CC) $(CFLAGS) -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_THREADSAFE=0 -c -o sqlite3.o sqlite3.c

static-logtodb:	logtodb.c sqlite3.o VERSION.h
	$(CC) $(CFLAGS) -o static-logtodb logtodb.c sqlite3.o

logtodb:	logtodb.c VERSION.h
	$(CC) $(CFLAGS) -o logtodb logtodb.c -lsqlite3 -lm -ldl -lpthread

clean:
	rm -f althttpd althttpsd VERSION.h sqlite3.o static-althttpd \
              static-althttpsd logtodb static-logtodb

Added VERSION.



>
1
2.0

Changes to althttpd.c.

341
342
343
344
345
346
347

348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
#include <sys/resource.h>
#include <signal.h>
#include <dirent.h>
#ifdef linux
#include <sys/sendfile.h>
#endif
#include <assert.h>


/*
** Configure the server by setting the following macros and recompiling.
*/
#ifndef DEFAULT_PORT
#define DEFAULT_PORT "80"             /* Default TCP port for HTTP */
#endif
#ifndef MAX_CONTENT_LENGTH
#define MAX_CONTENT_LENGTH 250000000  /* Max length of HTTP request content */
#endif
#ifndef MAX_CPU
#define MAX_CPU 30                    /* Max CPU cycles in seconds */
#endif

#ifndef ALTHTTPD_VERSION
#define ALTHTTPD_VERSION "2.0"
#endif

#ifndef BANISH_TIME
#define BANISH_TIME 300               /* How long to banish for abuse (sec) */
#endif

#ifndef SERVER_SOFTWARE
#  define SERVER_SOFTWARE "althttpd " ALTHTTPD_VERSION
#endif
#ifndef SERVER_SOFTWARE_TLS
#  ifdef ENABLE_TLS
#    define SERVER_SOFTWARE_TLS SERVER_SOFTWARE ", " OPENSSL_VERSION_TEXT
#  else
#    define SERVER_SOFTWARE_TLS SERVER_SOFTWARE
#  endif







>














<
<
<
<





|







341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362




363
364
365
366
367
368
369
370
371
372
373
374
375
#include <sys/resource.h>
#include <signal.h>
#include <dirent.h>
#ifdef linux
#include <sys/sendfile.h>
#endif
#include <assert.h>
#include "VERSION.h"

/*
** Configure the server by setting the following macros and recompiling.
*/
#ifndef DEFAULT_PORT
#define DEFAULT_PORT "80"             /* Default TCP port for HTTP */
#endif
#ifndef MAX_CONTENT_LENGTH
#define MAX_CONTENT_LENGTH 250000000  /* Max length of HTTP request content */
#endif
#ifndef MAX_CPU
#define MAX_CPU 30                    /* Max CPU cycles in seconds */
#endif





#ifndef BANISH_TIME
#define BANISH_TIME 300               /* How long to banish for abuse (sec) */
#endif

#ifndef SERVER_SOFTWARE
#  define SERVER_SOFTWARE "althttpd " RELEASE_VERSION
#endif
#ifndef SERVER_SOFTWARE_TLS
#  ifdef ENABLE_TLS
#    define SERVER_SOFTWARE_TLS SERVER_SOFTWARE ", " OPENSSL_VERSION_TEXT
#  else
#    define SERVER_SOFTWARE_TLS SERVER_SOFTWARE
#  endif
3884
3885
3886
3887
3888
3889
3890


3891
3892
3893
3894
3895
3896
3897
      if( freopen(zArg, "rb", stdin)==0 || stdin==0 ){
        Malfunction(514, /* LOG: cannot open --input file */
                    "cannot open --input file \"%s\"\n", zArg);
      }
    }else
    if( strcmp(z, "-version")==0 ){
      puts(SERVER_SOFTWARE_TLS);


      return 0;
    }else
    if( strcmp(z, "-datetest")==0 ){
      TestParseRfc822Date();
      printf("Ok\n");
      althttpd_exit(0);
    }else







>
>







3881
3882
3883
3884
3885
3886
3887
3888
3889
3890
3891
3892
3893
3894
3895
3896
      if( freopen(zArg, "rb", stdin)==0 || stdin==0 ){
        Malfunction(514, /* LOG: cannot open --input file */
                    "cannot open --input file \"%s\"\n", zArg);
      }
    }else
    if( strcmp(z, "-version")==0 ){
      puts(SERVER_SOFTWARE_TLS);
      printf("%s %.20s\n", MANIFEST_DATE, MANIFEST_UUID);
      printf("Compiled on " __DATE__ " using " COMPILER "\n");
      return 0;
    }else
    if( strcmp(z, "-datetest")==0 ){
      TestParseRfc822Date();
      printf("Ok\n");
      althttpd_exit(0);
    }else

Changes to logtodb.c.

18
19
20
21
22
23
24

25
26
27
28
29
30
31
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>
#include "sqlite3.h"


/*
** Number of elements in an array
*/
#define ArraySize(X)  (int)(sizeof(X)/sizeof(X[0]))

/*







>







18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <string.h>
#include <assert.h>
#include <unistd.h>
#include <sys/stat.h>
#include <sys/types.h>
#include <ctype.h>
#include "sqlite3.h"
#include "VERSION.h"

/*
** Number of elements in an array
*/
#define ArraySize(X)  (int)(sizeof(X)/sizeof(X[0]))

/*
52
53
54
55
56
57
58

59
60
61
62
63
64
65
  "  --db  DATABASE            Name of database file to create and populate\n"
  "  -f                        Monitor LOGFILE as per \"tail -f\"\n"
  "  --keep S                  Keep only the last S seconds of data\n"
  "  --logfile LOGFILE         The logfile to interpret\n"
  "  --reset                   Delete any prior content in DATABASE\n"
  "  --tail N                  Read only the last N bytes of the log file\n"
  "  -v                        Debugging output\n"

;

/*
** Database connection setup.
*/
static const char zSetup[] =
  "PRAGMA journal_mode=WAL;\n"







>







53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
  "  --db  DATABASE            Name of database file to create and populate\n"
  "  -f                        Monitor LOGFILE as per \"tail -f\"\n"
  "  --keep S                  Keep only the last S seconds of data\n"
  "  --logfile LOGFILE         The logfile to interpret\n"
  "  --reset                   Delete any prior content in DATABASE\n"
  "  --tail N                  Read only the last N bytes of the log file\n"
  "  -v                        Debugging output\n"
  "  --version                 Show version information for this program\n"
;

/*
** Database connection setup.
*/
static const char zSetup[] =
  "PRAGMA journal_mode=WAL;\n"
550
551
552
553
554
555
556






557
558
559
560
561
562
563
      }
      nTail = integerValue(argv[++i]);
      continue;
    }
    if( strcmp(zArg, "-help")==0 || strcmp(zArg, "-?")==0 ){
      printf("%s", zHelp);
      exit(0);






    }
    fprintf(stderr, "unknown command-line argument: \"%s\"\n", argv[i]);
    fprintf(stderr, "%s", zHelp);
    exit(1);
  }
  if( zDb==0 ){
    fprintf(stderr, "No database file specified.  Use the --db option.\n");







>
>
>
>
>
>







552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
      }
      nTail = integerValue(argv[++i]);
      continue;
    }
    if( strcmp(zArg, "-help")==0 || strcmp(zArg, "-?")==0 ){
      printf("%s", zHelp);
      exit(0);
    }
    if( strcmp(zArg, "-version")==0 ){
      printf("Version " RELEASE_VERSION " " MANIFEST_DATE "\n");
      printf("SQLite %s %.35s\n", sqlite3_libversion(), sqlite3_sourceid());
      printf("Compiled on " __DATE__ " using " COMPILER "\n");
      exit(0);
    }
    fprintf(stderr, "unknown command-line argument: \"%s\"\n", argv[i]);
    fprintf(stderr, "%s", zHelp);
    exit(1);
  }
  if( zDb==0 ){
    fprintf(stderr, "No database file specified.  Use the --db option.\n");

Added mkversion.c.























































































































































































































































































































































































>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
/*
** This C program generates the "VERSION.h" header file from information
** extracted out of the "manifest", "manifest.uuid", and "VERSION" files.
** Call this program with three arguments:
**
**     ./a.out manifest.uuid manifest VERSION
**
** Note that the manifest.uuid and manifest files are generated by Fossil.
**
** The output becomes the "VERSION.h" file.  The output is a C-language
** header that contains #defines for various properties of the build:
**
**   MANIFEST_UUID              These values are text strings that
**   MANIFEST_VERSION           identify the Fossil check-in to which
**                              the source tree belongs.  They do not
**                              take into account any uncommitted edits.
**
**   MANIFEST_DATE              The date/time of the source-code check-in
**   MANIFEST_YEAR              in various formats.
**   MANIFEST_NUMERIC_DATE
**   MANIFEST_NUMERIC_TIME
**
**   RELEASE_VERSION            The version number (from the VERSION source
**   RELEASE_VERSION_NUMBER     file) in various format.
**   RELEASE_RESOURCE_VERSION
**
** New #defines may be added in the future.
*/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

#if defined(_MSC_VER) && (_MSC_VER < 1800) /* MSVS 2013 */
#  define strtoll _strtoi64
#endif

/* These macros are provided to \"stringify\" the value of the define
** for those options in which the value is meaningful. */
#define CTIMEOPT_VAL_(opt) #opt
#define CTIMEOPT_VAL(opt) CTIMEOPT_VAL_(opt)


static FILE *open_for_reading(const char *zFilename){
  FILE *f = fopen(zFilename, "r");
  if( f==0 ){
    fprintf(stderr, "cannot open \"%s\" for reading\n", zFilename);
    exit(1);
  }
  return f;
}

/*
** Given an arbitrary-length input string key zIn, generate
** an N-byte hexadecimal hash of that string into zOut.
*/
static void hash(const char *zIn, int N, char *zOut){
  unsigned char i, j, t;
  int m, n;
  unsigned char s[256];
  for(m=0; m<256; m++){ s[m] = m; }
  for(j=0, m=n=0; m<256; m++, n++){
    j += s[m] + zIn[n];
    if( zIn[n]==0 ){ n = -1; }
    t = s[j];
    s[j] = s[m];
    s[m] = t;
  }
  i = j = 0;
  for(n=0; n<N-2; n+=2){
    i++;
    t = s[i];
    j += t;
    s[i] = s[j];
    s[j] = t;
    t += s[i];
    zOut[n] = "0123456789abcdef"[(t>>4)&0xf];
    zOut[n+1] = "0123456789abcdef"[t&0xf];
  }
  zOut[n] = 0;
}

int main(int argc, char *argv[]){
    FILE *m,*u,*v;
    char *z;
#if defined(__DMC__)            /* e.g. 0x857 */
    int i = 0;
#endif
    int j = 0, x = 0, d = 0;
    size_t n;
    int vn[3];
    char b[1000];
    char vx[1000];
    if( argc!=4 ){
      fprintf(stderr, "Usage: %s manifest.uuid manifest VERSION\n", argv[0]);
      exit(1);
    }
    memset(b,0,sizeof(b));
    memset(vx,0,sizeof(vx));
    u = open_for_reading(argv[1]);
    if( fgets(b, sizeof(b)-1,u)==0 ){
      fprintf(stderr, "malformed manifest.uuid file: %s\n", argv[1]);
      exit(1);
    }
    fclose(u);
    for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){}
    *z = 0;
    printf("#define MANIFEST_UUID \"%s\"\n",b);
    printf("#define MANIFEST_VERSION \"[%10.10s]\"\n",b);
    m = open_for_reading(argv[2]);
    while(b ==  fgets(b, sizeof(b)-1,m)){
      if(0 == strncmp("D ",b,2)){
        int k, n;
        char zDateNum[30];
        printf("#define MANIFEST_DATE \"%.10s %.8s\"\n",b+2,b+13);
        printf("#define MANIFEST_YEAR \"%.4s\"\n",b+2);
        n = 0;
        for(k=0; k<10; k++){
          if( isdigit(b[k+2]) ) zDateNum[n++] = b[k+2];
        }
        zDateNum[n] = 0;
        printf("#define MANIFEST_NUMERIC_DATE %s\n", zDateNum);
        n = 0;
        for(k=0; k<8; k++){
          if( isdigit(b[k+13]) ) zDateNum[n++] = b[k+13];
        }
        zDateNum[n] = 0;
        for(k=0; zDateNum[k]=='0'; k++){}
        printf("#define MANIFEST_NUMERIC_TIME %s\n", zDateNum+k);
      }
    }
    fclose(m);
    v = open_for_reading(argv[3]);
    if( fgets(b, sizeof(b)-1,v)==0 ){
      fprintf(stderr, "malformed VERSION file: %s\n", argv[3]);
      exit(1);
    }
    fclose(v);
    for(z=b; z[0] && z[0]!='\r' && z[0]!='\n'; z++){}
    *z = 0;
    printf("#define RELEASE_VERSION \"%s\"\n", b);
    z=b;
    vn[0] = vn[1] = vn[2] = 0;
    while(1){
      if( z[0]>='0' && z[0]<='9' ){
        x = x*10 + z[0] - '0';
      }else{
        if( j<3 ) vn[j++] = x;
        x = 0;
        if( z[0]==0 ) break;
      }
      z++;
    }
    for(z=vx; z[0]=='0'; z++){}
    printf("#define RELEASE_VERSION_NUMBER %d%02d%02d\n", vn[0], vn[1], vn[2]);
    memset(vx,0,sizeof(vx));
    strcpy(vx,b);
    for(z=vx; z[0]; z++){
      if( z[0]=='-' ){
        z[0] = 0;
        break;
      }
      if( z[0]!='.' ) continue;
      if ( d<3 ){
        z[0] = ',';
        d++;
      }else{
        z[0] = '\0';
        break;
      }
    }
    printf("#define RELEASE_RESOURCE_VERSION %s", vx);
    while( d<3 ){ printf(",0"); d++; }
    printf("\n");
#if defined(__clang__) && defined(__clang_major__)
    printf("#define COMPILER \"clang-" 
                    CTIMEOPT_VAL(__clang_major__) "."
                    CTIMEOPT_VAL(__clang_minor__) "."
                    CTIMEOPT_VAL(__clang_patchlevel__) "\"\n");
#elif defined(__GNUC__) && defined(__VERSION__)
    printf("#define COMPILER \"gcc-" __VERSION__ "\"\n");
#else
    printf("#define COMPILER \"unknown\"\n");
#endif
    return 0;
}

Changes to static-ssl.mk.

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27

28
29

30



31
32
33
34






35
36
# 2022-02-16:
# This makefile is used by the author (drh) to build versions of
# althttpd that are statically linked against OpenSSL.  The resulting
# binaries power sqlite.org, fossil-scm.org, and other machines.
#
# This is not a general-purpose makefile.  But perhaps you can adapt
# it to your specific needs.
#

default: althttpd

VERSION_NUMBER ?= 2.0
VERSION_HASH ?= $(shell cut -c1-12 manifest.uuid)
VERSION_TIME ?= $(shell sed -n 2p manifest | cut -d' ' -f2)
ALTHTTPD_VERSION ?= "$(VERSION_NUMBER) [$(VERSION_HASH)] $(VERSION_TIME)"
CPPFLAGS += -DALTHTTPD_VERSION='$(ALTHTTPD_VERSION)'

manifest:
	@if which fossil > /dev/null; then \
		fossil update --nosync current; \
	else \
	  echo "fossil binary not found. Version hash/time might be incorrect."
	fi
manifest.uuid: manifest

OPENSSLDIR = /home/drh/fossil/release-build/compat/openssl
OPENSSLLIB = -L$(OPENSSLDIR) -lssl -lcrypto -ldl

CPPFLAGS += -I$(OPENSSLDIR)/include -DENABLE_TLS
CPPFLAGS += -Wall -Wextra

CFLAGS = -Os




althttpd:	althttpd.c manifest
	gcc $(CPPFLAGS) $(CFLAGS) -o althttpd althttpd.c $(OPENSSLLIB)







clean:	
	rm -f althttpd










<
<
<
<
<
<
<
<
<
<
<
<
<
<
<


>
|
|
>
|
>
>
>

|
|

>
>
>
>
>
>
|
|
1
2
3
4
5
6
7
8
9
10















11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# 2022-02-16:
# This makefile is used by the author (drh) to build versions of
# althttpd that are statically linked against OpenSSL.  The resulting
# binaries power sqlite.org, fossil-scm.org, and other machines.
#
# This is not a general-purpose makefile.  But perhaps you can adapt
# it to your specific needs.
#

default: althttpd















OPENSSLDIR = /home/drh/fossil/release-build/compat/openssl
OPENSSLLIB = -L$(OPENSSLDIR) -lssl -lcrypto -ldl
CC=gcc
CFLAGS = -I$(OPENSSLDIR)/include -I. -DENABLE_TLS
CFLAGS += -Os -Wall -Wextra
LIBS = $(OPENSSLLIB)

VERSION.h:	VERSION manifest manifest.uuid mkversion.c
	$(CC) -o mkversion mkversion.c
	./mkversion manifest.uuid manifest VERSION >VERSION.h

althttpd:	althttpd.c VERSION.h
	$(CC) $(CFLAGS) -o althttpd althttpd.c $(LIBS)

sqlite3.o:	sqlite3.c
	$(CC) $(CFLAGS) -DSQLITE_OMIT_LOAD_EXTENSION -DSQLITE_THREADSAFE=0 -c -o sqlite3.o sqlite3.c

logtodb:	logtodb.c sqlite3.o VERSION.h
	$(CC) $(CFLAGS) -o logtodb logtodb.c sqlite3.o

clean:
	rm -f althttpd VERSION.h sqlite3.o logtodb