From 3591bbb9fc45c5ced4d2de636645e48bb948daf6 Mon Sep 17 00:00:00 2001 From: Pierre Pronchery Date: Fri, 3 Oct 2014 13:51:19 +0200 Subject: [PATCH] Moved main() to a separate file --- Makefile | 1 + src/Makefile | 5 +- src/configure.c | 107 +----------------------------------- src/configure.h | 2 + src/main.c | 140 +++++++++++++++++++++++++++++++++++++++++++++++ src/project.conf | 5 +- 6 files changed, 152 insertions(+), 108 deletions(-) create mode 100644 src/main.c diff --git a/Makefile b/Makefile index 7db3b86..06aeb9b 100644 --- a/Makefile +++ b/Makefile @@ -48,6 +48,7 @@ dist: $(PACKAGE)-$(VERSION)/doc/scripts/project.conf \ $(PACKAGE)-$(VERSION)/src/configure.c \ $(PACKAGE)-$(VERSION)/src/settings.c \ + $(PACKAGE)-$(VERSION)/src/main.c \ $(PACKAGE)-$(VERSION)/src/makedepend.c \ $(PACKAGE)-$(VERSION)/src/makefile.c \ $(PACKAGE)-$(VERSION)/src/Makefile \ diff --git a/src/Makefile b/src/Makefile index 9a11782..7d23838 100644 --- a/src/Makefile +++ b/src/Makefile @@ -18,7 +18,7 @@ INSTALL = install all: $(TARGETS) -configure_OBJS = configure.o settings.o +configure_OBJS = configure.o settings.o main.o configure_CFLAGS = $(CPPFLAGSF) $(CPPFLAGS) $(CFLAGSF) $(CFLAGS) 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 $(CC) $(configure_CFLAGS) -c settings.c +main.o: main.c configure.h + $(CC) $(configure_CFLAGS) -c main.c + makedepend.o: makedepend.c $(CC) $(makedepend_CFLAGS) -c makedepend.c diff --git a/src/configure.c b/src/configure.c index 421878c..2ee0615 100644 --- a/src/configure.c +++ b/src/configure.c @@ -17,7 +17,6 @@ #include #include -#include #ifndef __WIN32__ # include #endif @@ -102,8 +101,6 @@ const struct ExtensionType * sExtensionType = _sExtensionType; /* prototypes */ -static void _prefs_init(Prefs * prefs); - String const * _source_extension(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); 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; 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 */ String const * _source_extension(String const * source) { @@ -468,78 +438,3 @@ ObjectType _source_type(String const * source) return sExtensionType[i].type; 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; -} diff --git a/src/configure.h b/src/configure.h index bf1c2ff..b8df987 100644 --- a/src/configure.h +++ b/src/configure.h @@ -151,6 +151,8 @@ typedef struct _Configure /* functions */ +int configure(Prefs * prefs, char const * directory); + /* accessors */ String const * configure_get_config(Configure * configure, String const * section, String const * variable); diff --git a/src/main.c b/src/main.c new file mode 100644 index 0000000..ba48115 --- /dev/null +++ b/src/main.c @@ -0,0 +1,140 @@ +/* $Id$ */ +/* Copyright (c) 2014 Pierre Pronchery */ +/* 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 . */ + + + +#include +#include +#include +#include +#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; +} diff --git a/src/project.conf b/src/project.conf index f36a423..71a76a4 100644 --- a/src/project.conf +++ b/src/project.conf @@ -10,13 +10,16 @@ dist=Makefile,configure.h,makefile.h,settings.h [configure] type=binary depends=makefile.o -sources=configure.c,settings.c +sources=configure.c,settings.c,main.c ldflags=makefile.o install=$(BINDIR) [configure.c] depends=configure.h,makefile.h,../config.h +[main.c] +depends=configure.h + [settings.c] depends=settings.h