Moved main() to a separate file

This commit is contained in:
Pierre Pronchery 2014-10-03 13:51:19 +02:00
parent d8e7f7a943
commit 3591bbb9fc
6 changed files with 152 additions and 108 deletions

View File

@ -48,6 +48,7 @@ dist:
$(PACKAGE)-$(VERSION)/doc/scripts/project.conf \ $(PACKAGE)-$(VERSION)/doc/scripts/project.conf \
$(PACKAGE)-$(VERSION)/src/configure.c \ $(PACKAGE)-$(VERSION)/src/configure.c \
$(PACKAGE)-$(VERSION)/src/settings.c \ $(PACKAGE)-$(VERSION)/src/settings.c \
$(PACKAGE)-$(VERSION)/src/main.c \
$(PACKAGE)-$(VERSION)/src/makedepend.c \ $(PACKAGE)-$(VERSION)/src/makedepend.c \
$(PACKAGE)-$(VERSION)/src/makefile.c \ $(PACKAGE)-$(VERSION)/src/makefile.c \
$(PACKAGE)-$(VERSION)/src/Makefile \ $(PACKAGE)-$(VERSION)/src/Makefile \

View File

@ -18,7 +18,7 @@ INSTALL = install
all: $(TARGETS) all: $(TARGETS)
configure_OBJS = configure.o settings.o configure_OBJS = configure.o settings.o main.o
configure_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) configure_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS)
configure_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) makefile.o configure_LDFLAGS = $(LDFLAGSF) $(LDFLAGS) makefile.o
@ -41,6 +41,9 @@ configure.o: configure.c configure.h makefile.h ../config.h
settings.o: settings.c settings.h settings.o: settings.c settings.h
$(CC) $(configure_CFLAGS) -c settings.c $(CC) $(configure_CFLAGS) -c settings.c
main.o: main.c configure.h
$(CC) $(configure_CFLAGS) -c main.c
makedepend.o: makedepend.c makedepend.o: makedepend.c
$(CC) $(makedepend_CFLAGS) -c makedepend.c $(CC) $(makedepend_CFLAGS) -c makedepend.c

View File

@ -17,7 +17,6 @@
#include <System.h> #include <System.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h>
#ifndef __WIN32__ #ifndef __WIN32__
# include <sys/utsname.h> # include <sys/utsname.h>
#endif #endif
@ -102,8 +101,6 @@ const struct ExtensionType * sExtensionType = _sExtensionType;
/* prototypes */ /* prototypes */
static void _prefs_init(Prefs * prefs);
String const * _source_extension(String const * source); String const * _source_extension(String const * source);
ObjectType _source_type(String const * source); ObjectType _source_type(String const * source);
@ -170,7 +167,7 @@ static int _load_subdirs_subdir(Prefs * prefs, char const * directory,
configArray * ca, char const * subdir); configArray * ca, char const * subdir);
static int _configure_do(Configure * configure, configArray * ca); static int _configure_do(Configure * configure, configArray * ca);
static int _configure(Prefs * prefs, char const * directory) int configure(Prefs * prefs, char const * directory)
{ {
int ret; int ret;
Configure cfgr; Configure cfgr;
@ -416,33 +413,6 @@ String const * configure_get_soext(Configure * configure)
} }
/* prefs_init */
static void _prefs_init(Prefs * prefs)
{
struct stat st;
memset(prefs, 0, sizeof(*prefs));
prefs->destdir = "";
if(stat("/Apps", &st) == 0)
{
prefs->bindir = "Binaries";
prefs->includedir = "Includes";
prefs->libdir = "Libraries";
/* XXX needs auto-detection for the sub-directory */
prefs->prefix = "/Apps";
prefs->sbindir = "Binaries";
}
else
{
prefs->bindir = "bin";
prefs->includedir = "include";
prefs->libdir = "lib";
prefs->prefix = "/usr/local";
prefs->sbindir = "sbin";
}
}
/* source_extension */ /* source_extension */
String const * _source_extension(String const * source) String const * _source_extension(String const * source)
{ {
@ -468,78 +438,3 @@ ObjectType _source_type(String const * source)
return sExtensionType[i].type; return sExtensionType[i].type;
return OT_UNKNOWN; return OT_UNKNOWN;
} }
/* usage */
static int _usage(void)
{
Prefs prefs;
_prefs_init(&prefs);
fprintf(stderr, "%s%s%s%s%s%s%s%s%s%s%s",
"Usage: configure [-nvS][options...][directory...]\n"
" -n Do not actually write Makefiles\n"
" -v Verbose mode\n"
" -b Binary files directory (default: \"", prefs.bindir, "\")\n"
" -d Destination prefix (default: \"\")\n"
" -i Include files directory (default: \"", prefs.includedir, "\")\n"
" -l Library files directory (default: \"", prefs.libdir, "\")\n"
" -O Force Operating System (default: auto-detected)\n"
" -p Installation directory prefix (default: \"", prefs.prefix, "\")\n"
" -S Warn about potential security risks\n"
" -s Super-user executable files directory (default: \"", prefs.sbindir,
"\")\n");
return 1;
}
/* main */
int main(int argc, char * argv[])
{
int ret = 0;
Prefs prefs;
int o;
_prefs_init(&prefs);
while((o = getopt(argc, argv, "d:i:l:nO:p:Ss:v")) != -1)
switch(o)
{
case 'b':
prefs.bindir = optarg;
break;
case 'd':
prefs.destdir = optarg;
break;
case 'i':
prefs.includedir = optarg;
break;
case 'l':
prefs.libdir = optarg;
break;
case 'n':
prefs.flags |= PREFS_n;
break;
case 'O':
prefs.os = optarg;
break;
case 'p':
prefs.prefix = optarg;
break;
case 'S':
prefs.flags |= PREFS_S;
break;
case 's':
prefs.sbindir = optarg;
break;
case 'v':
prefs.flags |= PREFS_v;
break;
case '?':
return _usage();
}
if(optind == argc)
return _configure(&prefs, ".");
for(; optind < argc; optind++)
ret |= _configure(&prefs, argv[optind]);
return (ret == 0) ? 0 : 2;
}

View File

@ -151,6 +151,8 @@ typedef struct _Configure
/* functions */ /* functions */
int configure(Prefs * prefs, char const * directory);
/* accessors */ /* accessors */
String const * configure_get_config(Configure * configure, String const * configure_get_config(Configure * configure,
String const * section, String const * variable); String const * section, String const * variable);

140
src/main.c Normal file
View File

@ -0,0 +1,140 @@
/* $Id$ */
/* Copyright (c) 2014 Pierre Pronchery <khorben@defora.org> */
/* This file is part of DeforaOS Devel configure */
/* This program 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, version 3 of the License.
*
* This program 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 this program. If not, see <http://www.gnu.org/licenses/>. */
#include <sys/stat.h>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include "configure.h"
#include "../config.h"
#ifndef PROGNAME
# define PROGNAME PACKAGE
#endif
/* configure */
/* private */
/* prototypes */
static void _prefs_init(Prefs * prefs);
static int _usage(void);
/* functions */
/* prefs_init */
static void _prefs_init(Prefs * prefs)
{
struct stat st;
memset(prefs, 0, sizeof(*prefs));
prefs->destdir = "";
if(stat("/Apps", &st) == 0)
{
prefs->bindir = "Binaries";
prefs->includedir = "Includes";
prefs->libdir = "Libraries";
/* XXX needs auto-detection for the sub-directory */
prefs->prefix = "/Apps";
prefs->sbindir = "Binaries";
}
else
{
prefs->bindir = "bin";
prefs->includedir = "include";
prefs->libdir = "lib";
prefs->prefix = "/usr/local";
prefs->sbindir = "sbin";
}
}
/* usage */
static int _usage(void)
{
Prefs prefs;
_prefs_init(&prefs);
fprintf(stderr, "%s%s%s%s%s%s%s%s%s%s%s",
"Usage: configure [-nvS][options...][directory...]\n"
" -n Do not actually write Makefiles\n"
" -v Verbose mode\n"
" -b Binary files directory (default: \"", prefs.bindir, "\")\n"
" -d Destination prefix (default: \"\")\n"
" -i Include files directory (default: \"", prefs.includedir, "\")\n"
" -l Library files directory (default: \"", prefs.libdir, "\")\n"
" -O Force Operating System (default: auto-detected)\n"
" -p Installation directory prefix (default: \"", prefs.prefix, "\")\n"
" -S Warn about potential security risks\n"
" -s Super-user executable files directory (default: \"", prefs.sbindir,
"\")\n");
return 1;
}
/* public */
/* functions */
/* main */
int main(int argc, char * argv[])
{
int ret = 0;
Prefs prefs;
int o;
_prefs_init(&prefs);
while((o = getopt(argc, argv, "d:i:l:nO:p:Ss:v")) != -1)
switch(o)
{
case 'b':
prefs.bindir = optarg;
break;
case 'd':
prefs.destdir = optarg;
break;
case 'i':
prefs.includedir = optarg;
break;
case 'l':
prefs.libdir = optarg;
break;
case 'n':
prefs.flags |= PREFS_n;
break;
case 'O':
prefs.os = optarg;
break;
case 'p':
prefs.prefix = optarg;
break;
case 'S':
prefs.flags |= PREFS_S;
break;
case 's':
prefs.sbindir = optarg;
break;
case 'v':
prefs.flags |= PREFS_v;
break;
case '?':
return _usage();
}
if(optind == argc)
return configure(&prefs, ".");
for(; optind < argc; optind++)
ret |= configure(&prefs, argv[optind]);
return (ret == 0) ? 0 : 2;
}

View File

@ -10,13 +10,16 @@ dist=Makefile,configure.h,makefile.h,settings.h
[configure] [configure]
type=binary type=binary
depends=makefile.o depends=makefile.o
sources=configure.c,settings.c sources=configure.c,settings.c,main.c
ldflags=makefile.o ldflags=makefile.o
install=$(BINDIR) install=$(BINDIR)
[configure.c] [configure.c]
depends=configure.h,makefile.h,../config.h depends=configure.h,makefile.h,../config.h
[main.c]
depends=configure.h
[settings.c] [settings.c]
depends=settings.h depends=settings.h