Implement new Makefile as well as clean up source code

This commit is contained in:
Liam Waldron 2025-02-18 11:38:17 -05:00
parent 0c3f2db582
commit 92d25f7efe
5 changed files with 67 additions and 138 deletions

View File

@ -1,3 +1,11 @@
#
# Makefile
#
IDIR = ./include
BDIR = ./build
SDIR = ./src
include config.mk
all:
@ -8,27 +16,45 @@ help:
@echo "Make options for libglacier:"
@echo ""
@echo "lib - generate the static library"
@echo "test - generate a test binary"
@echo "install - install the static library and header files to PREFIX"
@echo "clean - remove all generated files"
test:
deprecate:
@echo "[WARN]"
@echo "[WARN] This rule has been deprecated, proceed with caution."
@echo "[WARN]"
test: deprecate
$(CC) libglacier.c $(LIBFLAGS) -o libglacier.test
cp etc/example.cfg ./glacier.cfg
lib:
lib: $(SDIR)/libglacier.c
mkdir build
mkdir build/lib
$(CC) libglacier.c -c $(LIBFLAGS) -o build/lib/libglacier.o
$(AR) -rc build/lib/libglacier.a build/lib/libglacier.o
$(CC) $(SDIR)/libglacier.c -c $(LIBFLAGS) -o $(BDIR)/lib/libglacier.o
$(AR) -rc $(BDIR)/lib/libglacier.a build/lib/libglacier.o
install:
install build/lib/libglacier.a $(PREFIX)/lib
install include/config.h $(PREFIX)/include/glacier
install include/data.h $(PREFIX)/include/glacier
install include/log.h $(PREFIX)/include/glacier
install include/pkgops.h $(PREFIX)/include/glacier
install include/runtime.h $(PREFIX)/include/glacier
install include/security.h $(PREFIX)/include/glacier
install_lib: $(BDIR)/lib/libglacier.a
@echo "[INFO]"
@echo "[INFO] Installing library to PREFIX/lib..."
@echo "[INFO]"
install $(BDIR)/lib/libglacier.a $(PREFIX)/lib
install_head: $(IDIR)/config.h $(IDIR)/data.h $(IDIR)/log.h $(IDIR)/pkgops.h $(IDIR)/runtime.h $(IDIR)/security.h
@echo "[INFO]"
@echo "[INFO] Installing header files to PREFIX/include/glacier..."
@echo "[INFO]"
install $(IDIR)/config.h $(PREFIX)/include/glacier
install $(IDIR)/data.h $(PREFIX)/include/glacier
install $(IDIR)/log.h $(PREFIX)/include/glacier
install $(IDIR)/pkgops.h $(PREFIX)/include/glacier
install $(IDIR)/runtime.h $(PREFIX)/include/glacier
install $(IDIR)/security.h $(PREFIX)/include/glacier
install: install_lib install_head
@echo "[INFO]"
@echo "[INFO] Finished installing library and header files to PREFIX."
@echo "[INFO]"
clean:
rm -rf build
rm -rf $(BDIR)

View File

@ -1,103 +0,0 @@
/*
* config.c - Configuration parsing functions
*
* This file is part of libglacier.
*
* Liblacier 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 3 of the License, or (at your option) any later version.
*
* Libglacier 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 Libglacier. If
* not, see <https://www.gnu.org/licenses/>.
*/
/* ALL FUNCTIONS IN THIS FILE DEFINED IN: config.h */
/*
* init_config
*
* DESCRIPTION: Initialize libconfig.
* PARAMETERS: None.
*
*/
int
init_config(void)
{
config_init(&cfg);
if (! config_read_file(&cfg, runtime_files[0])) {
fprintf(stderr, "%s:%d - %s\n", config_error_file(&cfg),
config_error_line(&cfg), config_error_text(&cfg));
config_destroy(&cfg);
return(EXIT_FAILURE);
}
if (LG_VERBOSE == 1) {
infolog("Initialized libconfig");
}
return 0;
}
/*
* die_config
*
* DESCRIPTION: Kill libconfig.
* PARAMETERS: None.
*
*/
int
die_config(void)
{
config_destroy(&cfg);
if (LG_VERBOSE == 1) {
infolog("Destroyed libconfig");
}
return(EXIT_SUCCESS);
}
/*
* load_all_from_config
*
* DESCRIPTION: Loads all settings from the Glacier config file.
* PARAMETERS: None.
*
*/
int
load_all_from_config(void)
{
/* this is probably really ugly but it works */
if (! config_lookup_bool(&cfg, "GLACIER_DO_INT_CHECK", &GLACIER_DO_INT_CHECK)) { return 1; }
if (! config_lookup_bool(&cfg, "GLACIER_VERBOSE", &GLACIER_VERBOSE)) { return 1; }
return 0;
}
/*
* load_all_from_profile
*
* DESCRIPTION: Loads all settings from the Glacier system profile.
* PARAMETERS: None.
*
*/
int
load_all_from_profile(void)
{
if (! config_lookup_string(&cfg, "GLACIER_REPO", &GLACIER_REPO)) { return 1; }
if (! config_lookup_string(&cfg, "GLACIER_ARCH", &GLACIER_ARCH)) { return 1; }
if (! config_lookup_string(&cfg, "GLACIER_TARGET", &GLACIER_TARGET)) { return 1; }
if (! config_lookup_string(&cfg, "GLACIER_SYSTEM_PROFILE", &GLACIER_SYSTEM_PROFILE)) { return 1; }
return 0;
}

27
src/config.h Normal file
View File

@ -0,0 +1,27 @@
/*
* config.h - Various compile-time settings for libglacier
*
* This file is part of Glacier.
*
* Glacier 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 3 of the License, or (at your option) any later version.
*
* Glacier 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 Glacier. If
* not, see <https://www.gnu.org/licenses/>.
*/
#ifndef CONFIG_H_
#define CONFIG_H_
/* LG_VERBOSE - whether to use verbose logging for library events or not
*
* 0 is false, 1 is true
*/
#define LG_VERBOSE 0
#endif

View File

@ -1,20 +0,0 @@
/*
* data.c - Data structure functions
*
* This file is part of libglacier.
*
* Liblacier 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 3 of the License, or (at your option) any later version.
*
* Libglacier 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 Libglacier. If
* not, see <https://www.gnu.org/licenses/>.
*/
/* ALL FUNCTIONS IN THIS FILE DEFINED IN: config.h */

View File

@ -31,7 +31,6 @@
#include <wchar.h>
#include "config.h"
#include "include/globals.h"
#define BUFFER_SIZE 1024
#define MAX_CHILDREN 64