Implemented config.{h,sh} optional generation
This commit is contained in:
parent
466d1b72e3
commit
4d80855236
11
src/Makefile
11
src/Makefile
@ -4,7 +4,7 @@ DESTDIR =
|
||||
BINDIR = $(PREFIX)/bin
|
||||
INCLUDEDIR= $(PREFIX)/include
|
||||
CC = cc
|
||||
CFLAGSF = -W -Wall -ansi -D_GNU_SOURCE
|
||||
CFLAGSF = -W -Wall -ansi
|
||||
CFLAGS = -g
|
||||
LDFLAGSF= -l System -l dl
|
||||
RM = rm -f
|
||||
@ -14,7 +14,7 @@ INSTALL = install
|
||||
|
||||
all: $(TARGETS)
|
||||
|
||||
configure_OBJS = configure.o makefile.o
|
||||
configure_OBJS = configure.o makefile.o settings.o
|
||||
configure_CFLAGS = $(CFLAGSF) $(CFLAGS)
|
||||
configure: $(configure_OBJS)
|
||||
$(CC) $(LDFLAGSF) $(LDFLAGS) -o configure $(configure_OBJS)
|
||||
@ -27,9 +27,12 @@ makedepend: $(makedepend_OBJS)
|
||||
configure.o: configure.c configure.h makefile.h
|
||||
$(CC) $(configure_CFLAGS) -c configure.c
|
||||
|
||||
makefile.o: makefile.c configure.h
|
||||
makefile.o: makefile.c configure.h settings.h
|
||||
$(CC) $(configure_CFLAGS) -c makefile.c
|
||||
|
||||
settings.o: settings.c settings.h
|
||||
$(CC) $(configure_CFLAGS) -c settings.c
|
||||
|
||||
makedepend.o: makedepend.c
|
||||
$(CC) $(makedepend_CFLAGS) -c makedepend.c
|
||||
|
||||
@ -47,3 +50,5 @@ install: all
|
||||
uninstall:
|
||||
$(RM) $(DESTDIR)$(BINDIR)/configure
|
||||
$(RM) $(DESTDIR)$(BINDIR)/makedepend
|
||||
|
||||
.PHONY: all clean distclean install uninstall
|
||||
|
@ -289,13 +289,14 @@ static int _usage(void)
|
||||
Prefs prefs;
|
||||
|
||||
_prefs_init(&prefs);
|
||||
fprintf(stderr, "%s%s%s%s%s%s%s",
|
||||
fprintf(stderr, "%s%s%s%s%s%s%s%s%s",
|
||||
"Usage: configure [-nv][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\
|
||||
-p Installation directory prefix (default: \"", prefs.prefix, "\")\n");
|
||||
return 1;
|
||||
}
|
||||
@ -320,6 +321,9 @@ int main(int argc, char * argv[])
|
||||
case 'i':
|
||||
prefs.includedir = optarg;
|
||||
break;
|
||||
case 'l':
|
||||
prefs.libdir = optarg;
|
||||
break;
|
||||
case 'n':
|
||||
prefs.flags |= PREFS_n;
|
||||
break;
|
||||
@ -347,10 +351,12 @@ static void _prefs_init(Prefs * prefs)
|
||||
{
|
||||
prefs->bindir = "bin";
|
||||
prefs->includedir = "include";
|
||||
prefs->libdir = "lib";
|
||||
prefs->prefix = "/usr/local";
|
||||
return;
|
||||
}
|
||||
prefs->bindir = "Binaries";
|
||||
prefs->includedir = "Include";
|
||||
prefs->includedir = "Includes";
|
||||
prefs->libdir = "Libraries";
|
||||
prefs->prefix = "/Apps"; /* FIXME detect System or Apps/x first */
|
||||
}
|
||||
|
@ -2,8 +2,8 @@
|
||||
|
||||
|
||||
|
||||
#ifndef __CONFIGURE_H
|
||||
# define __CONFIGURE_H
|
||||
#ifndef CONFIGURE_CONFIGURE_H
|
||||
# define CONFIGURE_CONFIGURE_H
|
||||
|
||||
# include <System.h>
|
||||
|
||||
@ -73,6 +73,7 @@ typedef struct _Prefs
|
||||
char * bindir;
|
||||
char * destdir;
|
||||
char * includedir;
|
||||
char * libdir;
|
||||
char * prefix;
|
||||
} Prefs;
|
||||
# define PREFS_n 0x1
|
||||
@ -92,4 +93,4 @@ int configure_error(char const * message, int ret);
|
||||
int enum_string(int last, const String * strings[], String * str);
|
||||
int enum_string_short(int last, const String * strings[], String * str);
|
||||
|
||||
#endif /* !__CONFIGURE_H */
|
||||
#endif /* !CONFIGURE_CONFIGURE_H */
|
||||
|
@ -6,6 +6,7 @@
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "settings.h"
|
||||
#include "configure.h"
|
||||
|
||||
ARRAY(Config *, config);
|
||||
@ -97,6 +98,7 @@ static int _variables_package(Prefs * prefs, Config * config, FILE * fp,
|
||||
{
|
||||
String * package;
|
||||
String * version;
|
||||
String * p;
|
||||
|
||||
if((package = config_get(config, "", "package")) == NULL)
|
||||
return 0;
|
||||
@ -115,6 +117,8 @@ static int _variables_package(Prefs * prefs, Config * config, FILE * fp,
|
||||
if(fp != NULL)
|
||||
fprintf(fp, "%s%s%s%s%s", "PACKAGE\t= ", package,
|
||||
"\nVERSION\t= ", version, "\n");
|
||||
if((p = config_get(config, "", "config")) != NULL)
|
||||
return settings(prefs, config, directory, package, version);
|
||||
return 0;
|
||||
}
|
||||
|
||||
@ -122,7 +126,7 @@ static int _variables_print(Prefs * prefs, Config * config, FILE * fp,
|
||||
char const * input, char const * output)
|
||||
{
|
||||
String * prints;
|
||||
int i;
|
||||
unsigned long i;
|
||||
char c;
|
||||
|
||||
if(prefs->flags & PREFS_n)
|
||||
@ -150,7 +154,7 @@ static int _variables_print(Prefs * prefs, Config * config, FILE * fp,
|
||||
static int _variables_targets(Prefs * prefs, Config * config, FILE * fp)
|
||||
{
|
||||
String * prints;
|
||||
int i;
|
||||
unsigned long i;
|
||||
char c;
|
||||
String * type;
|
||||
|
||||
@ -265,14 +269,13 @@ static int _executables_variables(Configure * configure, Config * config,
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void _binary_ldflags(Configure * configure, Config * config, FILE * fp,
|
||||
static void _binary_ldflags(Configure * configure, FILE * fp,
|
||||
String const * ldflags);
|
||||
static void _variables_binary(Configure * configure, Config * config, FILE * fp,
|
||||
char * done)
|
||||
{
|
||||
String const * p;
|
||||
|
||||
/* FIXME path given from user or autodetected */
|
||||
if(!done[TT_LIBRARY])
|
||||
{
|
||||
fprintf(fp, "%s%s\n", "PREFIX\t= ", configure->prefs->prefix);
|
||||
@ -310,20 +313,20 @@ static void _variables_binary(Configure * configure, Config * config, FILE * fp,
|
||||
!= NULL)
|
||||
{
|
||||
fprintf(fp, "%s", "LDFLAGSF= ");
|
||||
_binary_ldflags(configure, config, fp, p);
|
||||
_binary_ldflags(configure, fp, p);
|
||||
}
|
||||
if((p = config_get(config, "", "ldflags")) != NULL)
|
||||
{
|
||||
fprintf(fp, "%s", "LDFLAGS\t= ");
|
||||
_binary_ldflags(configure, config, fp, p);
|
||||
_binary_ldflags(configure, fp, p);
|
||||
}
|
||||
}
|
||||
|
||||
static void _binary_ldflags(Configure * configure, Config * config, FILE * fp,
|
||||
static void _binary_ldflags(Configure * configure, FILE * fp,
|
||||
String const * ldflags)
|
||||
{
|
||||
char * libs_gnu[] = { "socket", NULL };
|
||||
char * libs_bsd[] = { "dl", "socket", NULL };
|
||||
char * libs_bsd[] = { "crypt", "dl", "socket", NULL };
|
||||
char * libs_sunos[] = { "dl", NULL };
|
||||
char buf[10];
|
||||
char ** libs;
|
||||
@ -369,13 +372,16 @@ static void _variables_library(Configure * configure, Config * config,
|
||||
{
|
||||
String * p;
|
||||
|
||||
/* FIXME path given from user or autodetected */
|
||||
if(!done[TT_LIBRARY])
|
||||
{
|
||||
fprintf(fp, "%s", "PREFIX\t= /usr/local\n");
|
||||
fprintf(fp, "%s", "DESTDIR\t=\n");
|
||||
fprintf(fp, "%s%s\n", "PREFIX\t= ", configure->prefs->prefix);
|
||||
fprintf(fp, "%s%s\n", "DESTDIR\t= ", configure->prefs->destdir);
|
||||
}
|
||||
fprintf(fp, "%s", "LIBDIR\t= $(PREFIX)/lib\n");
|
||||
if(configure->prefs->libdir[0] == '/')
|
||||
fprintf(fp, "%s%s\n", "LIBDIR\t= ", configure->prefs->libdir);
|
||||
else
|
||||
fprintf(fp, "%s%s\n", "LIBDIR\t= $(PREFIX)/",
|
||||
configure->prefs->libdir);
|
||||
if(!done[TT_BINARY])
|
||||
{
|
||||
fprintf(fp, "%s", "CC\t= cc\n");
|
||||
|
@ -2,20 +2,23 @@
|
||||
|
||||
|
||||
|
||||
#ifndef __MAKEFILE_H
|
||||
# define __MAKEFILE_H
|
||||
#ifndef CONFIGURE_MAKEFILE_H
|
||||
# define CONFIGURE_MAKEFILE_H
|
||||
|
||||
# include <System.h>
|
||||
# include "configure.h"
|
||||
|
||||
|
||||
/* types */
|
||||
/* FIXME should be:
|
||||
ARRAY(Config *, config);
|
||||
but it can't be included multiple times */
|
||||
typedef Array configArray;
|
||||
extern configArray * configarray_new(void);
|
||||
|
||||
|
||||
/* functions */
|
||||
int makefile(Configure * configure, Config * config, String * directory,
|
||||
configArray * ca, int from, int to);
|
||||
|
||||
#endif
|
||||
#endif /* !CONFIGURE_MAKEFILE_H */
|
||||
|
@ -6,13 +6,16 @@ dist=configure.h,makefile.h
|
||||
|
||||
[configure]
|
||||
type=binary
|
||||
sources=configure.c,makefile.c
|
||||
sources=configure.c,makefile.c,settings.c
|
||||
|
||||
[configure.c]
|
||||
depends=configure.h,makefile.h
|
||||
|
||||
[makefile.c]
|
||||
depends=configure.h
|
||||
depends=configure.h,settings.h
|
||||
|
||||
[settings.c]
|
||||
depends=settings.h
|
||||
|
||||
[makedepend]
|
||||
type=binary
|
||||
|
121
src/settings.c
Normal file
121
src/settings.c
Normal file
@ -0,0 +1,121 @@
|
||||
/* settings.c */
|
||||
|
||||
|
||||
|
||||
#include <System.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
#include "configure.h"
|
||||
#include "settings.h"
|
||||
|
||||
|
||||
/* types */
|
||||
typedef enum _SETTINGS_TYPE
|
||||
{
|
||||
ST_H = 0,
|
||||
ST_SH
|
||||
} SettingsType;
|
||||
#define ST_LAST ST_SH
|
||||
String * sSettingsType[ST_LAST+1] =
|
||||
{
|
||||
"h", "sh"
|
||||
};
|
||||
|
||||
|
||||
/* functions */
|
||||
/* settings */
|
||||
static int _settings_do(Prefs * prefs, String const * directory,
|
||||
String const * package, String const * version,
|
||||
String const * extension);
|
||||
int settings(Prefs * prefs, Config * config, String const * directory,
|
||||
String const * package, String const * version)
|
||||
{
|
||||
int ret = 0;
|
||||
String * p;
|
||||
unsigned long i;
|
||||
char c;
|
||||
|
||||
if((p = config_get(config, "", "config")) == NULL)
|
||||
return 0;
|
||||
for(i = 0;; i++)
|
||||
{
|
||||
if(p[i] != ',' && p[i] != '\0')
|
||||
continue;
|
||||
c = p[i];
|
||||
p[i] = '\0';
|
||||
ret |= _settings_do(prefs, directory, package, version, p);
|
||||
if(c == '\0')
|
||||
break;
|
||||
p[i] = c;
|
||||
p+=i+1;
|
||||
i = 0;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int _do_h(FILE * fp, String const * package, String const * version);
|
||||
static int _do_sh(FILE * fp, String const * package, String const * version);
|
||||
static int _settings_do(Prefs * prefs, String const * directory,
|
||||
String const * package, String const * version,
|
||||
String const * extension)
|
||||
{
|
||||
int ret = 0;
|
||||
int i;
|
||||
String * filename;
|
||||
FILE * fp;
|
||||
|
||||
for(i = 0; i <= ST_LAST; i++)
|
||||
if(strcmp(extension, sSettingsType[i]) == 0)
|
||||
break;
|
||||
if(i > ST_LAST)
|
||||
{
|
||||
fprintf(stderr, "%s%s%s", "configure: ", extension,
|
||||
": Unknown settings type\n");
|
||||
return 1;
|
||||
}
|
||||
if(prefs->flags & PREFS_n)
|
||||
return 0;
|
||||
if((filename = string_new(directory)) == NULL)
|
||||
return 1;
|
||||
if(string_append(&filename, "/config.") != 0
|
||||
|| string_append(&filename, extension) != 0)
|
||||
{
|
||||
string_delete(filename);
|
||||
return 1;
|
||||
}
|
||||
if((fp = fopen(filename, "w")) == NULL)
|
||||
ret |= configure_error(filename, 1);
|
||||
else
|
||||
{
|
||||
printf("%s%s%s%s\n", "Creating config.", extension, " in ",
|
||||
directory);
|
||||
switch(i)
|
||||
{
|
||||
case ST_H:
|
||||
ret |= _do_h(fp, package, version);
|
||||
break;
|
||||
case ST_SH:
|
||||
ret |= _do_sh(fp, package, version);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
fclose(fp);
|
||||
}
|
||||
string_delete(filename);
|
||||
return ret;
|
||||
}
|
||||
|
||||
static int _do_h(FILE * fp, String const * package, String const * version)
|
||||
{
|
||||
fprintf(fp, "%s%s%s%s%s%s", "#define PACKAGE \"", package, "\"\n",
|
||||
"#define VERSION \"", version, "\"\n");
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int _do_sh(FILE * fp, String const * package, String const * version)
|
||||
{
|
||||
fprintf(fp, "%s%s%s%s%s%s", "PACKAGE=\"", package, "\"\n",
|
||||
"VERSION=\"", version, "\"\n");
|
||||
return 0;
|
||||
}
|
15
src/settings.h
Normal file
15
src/settings.h
Normal file
@ -0,0 +1,15 @@
|
||||
/* settings.h */
|
||||
|
||||
|
||||
#ifndef CONFIGURE_SETTINGS_H
|
||||
# define CONFIGURE_SETTINGS_H
|
||||
|
||||
# include <System.h>
|
||||
# include "configure.h"
|
||||
|
||||
|
||||
/* functions */
|
||||
int settings(Prefs * prefs, Config * config, String const * directory,
|
||||
String const * package, String const * version);
|
||||
|
||||
#endif /* !CONFIGURE_SETTINGS_H */
|
Loading…
Reference in New Issue
Block a user