Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MSVC Windows Build & add Makefile.win #22

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
40 changes: 40 additions & 0 deletions Makefile.win
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
###########################################################################
#
# Usage: NMAKE -f Makefile.win APR={apr installion dir} APRUTIL={aprutil installion dir}
#
!IF "$(APR)" == "" || "$(APRUTIL)" == ""
!ERROR NMAKE arguments: APR=dir and APRUTIL=dir are required to build modsec-sdbm-util for Windows
!ENDIF

###########################################################################

cc = cl

link = link

includes = -I$(APRUTIL)\include -I$(APR)\include

libs = $(APR)\lib\libapr-1.lib $(APRUTIL)\lib\libaprutil-1.lib

cflags= $(includes) /nologo /DWIN32 /DWINNT /D_WINDOWS /Dinline=APR_INLINE /w /Zf /Zi /FS /O2 /GL /MD /DNDEBUG

ldflags = /nologo /Incremental:no /LTCG /debug /opt:ref,icf

objs = modsec-sdbm-util.obj

exe = modsec-sdbm-util.exe

###########################################################################

all: $(exe)

exe: $(exe)

.c.obj:
$(cc) $(cflags) -c $< -Fo$@

$(exe): $(objs)
$(link) $(ldflags) -out:$(exe) $(objs) $(libs)

clean:
del $(objs) $(exe) *.exe *.pdb *.idb *.ilk *.exp *.res *.rc *.bin *.manifest
77 changes: 76 additions & 1 deletion modsec-sdbm-util.c
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>

#include <apr.h>
#include <apr_errno.h>
#include <apr_general.h>
Expand All @@ -32,11 +32,86 @@
#define VERSION "v1.0"

#ifndef WIN32
#include <unistd.h>
# define v(fmt, ARGS...) do { if (verbose) printf("%s:%d:%s(): " fmt, __FILE__, \
__LINE__, __func__, ## ARGS); } while (0)
# define p(fmt, ARGS...) do { printf(fmt, ## ARGS); } while (0)
#endif
#ifdef WIN32
#include <windows.h>
#include <string.h>

int opterr = 1, /* if error message should be printed */
optind = 1, /* index into parent argv vector */
optopt, /* character checked for validity */
optreset; /* reset getopt */
char *optarg; /* argument associated with option */

#define BADCH (int)'?'
#define BADARG (int)':'
#define EMSG ""

/*
* getopt --
* Parse argc/argv argument vector.
*/
int
getopt(int nargc, char * const nargv[], const char *ostr)
{
static char *place = EMSG; /* option letter processing */
const char *oli; /* option letter list index */

if (optreset || !*place) { /* update scanning pointer */
optreset = 0;
if (optind >= nargc || *(place = nargv[optind]) != '-') {
place = EMSG;
return (-1);
}
if (place[1] && *++place == '-') { /* found "--" */
++optind;
place = EMSG;
return (-1);
}
} /* option letter okay? */
if ((optopt = (int)*place++) == (int)':' ||
!(oli = strchr(ostr, optopt))) {
/*
* if the user didn't specify '-' as an option,
* assume it means -1.
*/
if (optopt == (int)'-')
return (-1);
if (!*place)
++optind;
if (opterr && *ostr != ':')
(void)printf("illegal option -- %c\n", optopt);
return (BADCH);
}
if (*++oli != ':') { /* don't need argument */
optarg = NULL;
if (!*place)
++optind;
}
else { /* need an argument */
if (*place) /* no white space */
optarg = place;
else if (nargc <= ++optind) { /* no arg */
place = EMSG;
if (*ostr == ':')
return (BADARG);
if (opterr)
(void)printf("option requires an argument -- %c\n", optopt);
return (BADCH);
}
else /* white space */
optarg = nargv[optind];
place = EMSG;
++optind;
}
return (optopt); /* dump back option letter */
}

#define strndup strdup
#define p printf
#define v if (verbose) printf
#endif
Expand Down