make/cmake cliparser lib and remove redundant getopt from reveng

This commit is contained in:
Philippe Teuwen 2020-04-19 12:14:56 +02:00
commit 4967096e3b
9 changed files with 37 additions and 123 deletions

View file

@ -78,8 +78,6 @@ set (TARGET_SOURCES
../common/iso15693tools.c
../common/cardhelper.c
../common/generator.c
deps/cliparser/argtable3.c
deps/cliparser/cliparser.c
src/crypto/asn1dump.c
src/crypto/asn1utils.c
src/crypto/libpcrypto.c
@ -245,7 +243,6 @@ target_include_directories(proxmark3 PRIVATE
..
../common
../include
deps/cliparser
src
src/uart
)
@ -256,6 +253,7 @@ if (APPLE)
endif (APPLE)
find_library(cliparser REQUIRED)
find_library(jansson REQUIRED)
find_library(tinycbor REQUIRED)
find_library(lua REQUIRED)
@ -264,7 +262,7 @@ find_library(reveng REQUIRED)
find_library(z REQUIRED)
find_library(hardnested REQUIRED)
target_link_libraries(proxmark3 PRIVATE readline pthread m mbedtls jansson lua tinycbor amiibo reveng z hardnested ${ADDITIONAL_LNK})
target_link_libraries(proxmark3 PRIVATE readline pthread m mbedtls cliparser jansson lua tinycbor amiibo reveng z hardnested ${ADDITIONAL_LNK})
install(TARGETS proxmark3 DESTINATION "bin")
install(DIRECTORY cmdscripts lualibs luascripts resources dictionaries DESTINATION "share/proxmark3")

View file

@ -44,6 +44,8 @@ AMIIBOLIBPATH = ./deps/amiitool
AMIIBOLIB = $(AMIIBOLIBPATH)/libamiibo.a
HARDNESTEDPATH = ./deps/hardnested
HARDNESTEDLIB = $(HARDNESTEDPATH)/libhardnested.a
CLIPARSERPATH = ./deps/cliparser
CLIPARSERLIB = $(CLIPARSERPATH)/libcliparser.a
# common libraries
MBEDTLSLIBPATH = ../common/mbedtls
@ -51,8 +53,8 @@ MBEDTLSLIB = $(OBJDIR)/libmbedtls.a
ZLIBPATH = ../common/zlib
ZLIB = $(OBJDIR)/libz.a
LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGPATH) -I$(AMIIBOLIBPATH) -I$(HARDNESTEDPATH)
INCLUDES_CLIENT = -I./src -I../include -I../common -I./deps/cliparser -I./src/uart $(LIBS)
LIBS = -I$(LUALIBPATH) -I$(MBEDTLSLIBPATH) -I$(JANSSONLIBPATH) -I$(CBORLIBPATH) -I$(ZLIBPATH) -I$(REVENGPATH) -I$(AMIIBOLIBPATH) -I$(HARDNESTEDPATH) -I$(CLIPARSERPATH)
INCLUDES_CLIENT = -I./src -I../include -I../common -I./src/uart $(LIBS)
CFLAGS ?= -Wall -Werror -O3
# We cannot just use CFLAGS+=... because it has impact on sub-makes if CFLAGS is defined in env:
PM3CFLAGS = $(CFLAGS) -std=c99 -D_ISOC99_SOURCE $(INCLUDES_CLIENT)
@ -150,8 +152,6 @@ CMDSRCS = crapto1/crapto1.c \
crypto/asn1dump.c \
crypto/libpcrypto.c\
crypto/asn1utils.c\
deps/cliparser/argtable3.c\
deps/cliparser/cliparser.c\
loclass/cipher.c \
loclass/cipherutils.c \
loclass/ikeys.c \
@ -278,8 +278,8 @@ all: $(BINS)
all-static: LDLIBS:=-static $(LDLIBS)
all-static: $(BINS)
proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(AMIIBOLIB) $(HARDNESTEDLIB) $(QTLDLIBS)
proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) $(AMIIBOLIB) $(HARDNESTEDLIB) lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua
proxmark3: LDLIBS+=$(LUALIB) $(JANSSONLIB) $(MBEDTLSLIB) $(CBORLIB) $(ZLIB) $(REVENGLIB) $(AMIIBOLIB) $(HARDNESTEDLIB) $(CLIPARSERLIB) $(QTLDLIBS)
proxmark3: $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(LUALIB) $(JANSSONLIB) $(CBORLIB) $(REVENGLIB) $(MBEDTLSLIB) $(ZLIB) $(AMIIBOLIB) $(HARDNESTEDLIB) $(CLIPARSERLIB) lualibs/pm3_cmd.lua lualibs/mfc_default_keys.lua
$(info [=] LD $@)
$(Q)$(LD) $(LDFLAGS) $(OBJDIR)/proxmark3.o $(COREOBJS) $(CMDOBJS) $(OBJCOBJS) $(QTGUIOBJS) $(LDLIBS) -o $@
@ -310,6 +310,7 @@ clean:
$(Q)$(MAKE) --no-print-directory -C $(REVENGPATH) clean
$(Q)$(MAKE) --no-print-directory -C $(AMIIBOLIBPATH) clean
$(Q)$(MAKE) --no-print-directory -C $(HARDNESTEDPATH) clean
$(Q)$(MAKE) --no-print-directory -C $(CLIPARSERPATH) clean
install: all
$(info [@] Installing client to $(DESTDIR)$(PREFIX)...)
@ -362,6 +363,10 @@ $(AMIIBOLIB):
$(info [*] MAKE amiibo)
$(Q)$(MAKE) --no-print-directory -C $(AMIIBOLIBPATH) all
$(CLIPARSERLIB):
$(info [*] MAKE cliparser)
$(Q)$(MAKE) --no-print-directory -C $(CLIPARSERPATH) all
# common libraries:
$(MBEDTLSLIB):
$(info [*] MAKE mbedtls)
@ -397,7 +402,7 @@ $(OBJDIR)/%.o : %.m $(OBJDIR)/%.d
$(Q)$(CC) $(DEPFLAGS) $(PM3CFLAGS) -c -o $@ $<
$(Q)$(POSTCOMPILE)
DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS) $(REVENGSRCS)) \
DEPENDENCY_FILES = $(patsubst %.c, $(OBJDIR)/%.d, $(CORESRCS) $(CMDSRCS)) \
$(patsubst %.cpp, $(OBJDIR)/%.d, $(QTGUISRCS)) \
$(patsubst %.m, $(OBJDIR)/%.d, $(OBJCSRCS)) \
$(OBJDIR)/proxmark3.d

View file

@ -1,3 +1,4 @@
include(cliparser.cmake)
include(tinycbor.cmake)
include(jansson.cmake)
include(lua.cmake)

View file

@ -0,0 +1,11 @@
add_library(cliparser STATIC
cliparser/argtable3.c
cliparser/cliparser.c
)
target_include_directories(cliparser PRIVATE
../../common
../../include
../src)
target_include_directories(cliparser INTERFACE cliparser)
target_compile_options(cliparser PRIVATE -Wall -Werror -O3)

View file

@ -0,0 +1,11 @@
MYSRCPATHS =
MYINCLUDES = -I../../../common -I../../../include -I../../src
MYCFLAGS = -std=c99 -D_ISOC99_SOURCE
MYDEFS =
MYSRCS = \
argtable3.c \
cliparser.c
LIB_A = libcliparser.a
include ../../../Makefile.host

View file

@ -3,7 +3,6 @@ set_property(SOURCE PROPERTY C_STANDARD 99)
add_library(reveng STATIC
reveng/bmpbit.c
reveng/cli.c
reveng/getopt.c
reveng/model.c
reveng/poly.c
reveng/preset.c

View file

@ -10,7 +10,6 @@ MYDEFS = -DPRESETS
MYSRCS = \
bmpbit.c \
cli.c \
getopt.c \
model.c \
poly.c \
preset.c \

View file

@ -1,80 +0,0 @@
/*----------------------------------------------------------------------
Replacement for Unix "getopt()", for DOS/Windows/etc.
getopt.c 1.3 2003/09/17 16:17:59
Copyright (C) 1998, 2003 by David A. Hinds -- All Rights Reserved
This file is part of ASPEX.
ASPEX is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ASPEX is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with ASPEX; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
----------------------------------------------------------------------*/
#include <string.h>
#include <stdio.h>
#include "getopt.h"
char *optarg;
int optind = 1, opterr, optopt;
int pos = 0;
int getopt(int argc, char *argv[], const char *optstring) {
//static int pos = 0;
char *str;
if (pos == 0) {
if ((optind >= argc) || (*argv[optind] != '-'))
return EOF;
pos = 1;
if (argv[optind][pos] == '\0')
return EOF;
}
str = strchr(optstring, argv[optind][pos]);
if (str == NULL) {
optopt = argv[optind][pos];
if (opterr)
fprintf(stderr, "%s: illegal option -- %c\n", argv[0],
optopt);
return '?';
}
if (str[1] == ':') {
if (argv[optind][pos + 1] != '\0') {
optarg = &argv[optind][pos + 1];
return *str;
}
optind++;
if (optind >= argc) {
optopt = *str;
if (opterr)
fprintf(stderr, "%s: option requires an argument -- %c\n",
argv[0], optopt);
return '?';
}
optarg = argv[optind];
optind++;
pos = 0;
return *str;
} else {
pos++;
if (argv[optind][pos] == '\0') {
optind++;
pos = 0;
}
return *str;
}
}

View file

@ -1,30 +0,0 @@
/*
getopt.h 1.2 2003/09/17 16:17:59
Copyright (C) 1998, 2003 by David A. Hinds -- All Rights Reserved
This file is part of ASPEX.
ASPEX is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
ASPEX is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with ASPEX; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
#ifndef __GETOPT_H
#define __GETOPT_H
extern char *optarg;
extern int optind, opterr, optopt, pos;
int getopt(int argc, char *argv[], const char *optstring);
#endif