From a02c32339312305561a16db455d4546709ba007d Mon Sep 17 00:00:00 2001 From: hyung-hwan Date: Mon, 22 Jan 2024 01:27:39 +0900 Subject: [PATCH] removed the cfg package from go code. instead, started using -ldflags "-X var=val" to set constant values --- Makefile.am | 4 +--- Makefile.in | 17 +++++------------ configure | 4 +--- configure.ac | 2 -- go.mod | 2 -- go/cfg/cfg.go.in | 5 ----- go/cfg/go.mod.in | 6 ------ main.go | 7 ++++++- t/Makefile.in | 2 +- 9 files changed, 14 insertions(+), 35 deletions(-) delete mode 100644 go/cfg/cfg.go.in delete mode 100644 go/cfg/go.mod.in diff --git a/Makefile.am b/Makefile.am index 957c15b..a1f699f 100644 --- a/Makefile.am +++ b/Makefile.am @@ -45,14 +45,12 @@ hclgo_LINK = cp -pf hclgo.bin hclgo$(EXEEXT) || echo "FAILED TO LINK" hclgo.bin: lib/libhcl.la $(hclgo_OBJECTS) cp -pf $(srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change - sed -r -i -e "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod - echo -e "\nreplace cfg => $(abs_builddir)/go/cfg" >> $(builddir)/go.mod [ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true ## --------------------------------------------------------------- CC=$(CC) \ CGO_CFLAGS="-I$(abs_srcdir)/lib -I$(abs_builddir)/lib $(CFLAGS)" \ CGO_LDFLAGS="-L$(abs_builddir)/lib -L$(abs_builddir)/lib/.libs -lhcl -ldl -lquadmath" \ - go build -C $(srcdir) -x -o $(abs_builddir)/hclgo.bin -modfile $(abs_builddir)/go.mod + go build -C $(srcdir) -ldflags "-X 'main.BINDIR=$(bindir)' -X 'main.SBINDIR=$(sbindir)' -X 'main.LIBDIR=$(libdir)' -X 'main.SYSCONFDIR=$(sysconfdir)'" -x -o $(abs_builddir)/hclgo.bin -modfile $(abs_builddir)/go.mod ## --------------------------------------------------------------- go clean -C $(srcdir) -x -modfile $(abs_builddir)/go.mod rm -rf $(builddir)/go.mod $(builddir)/go.sum diff --git a/Makefile.in b/Makefile.in index dde2047..53ee890 100644 --- a/Makefile.in +++ b/Makefile.in @@ -106,7 +106,7 @@ am__CONFIG_DISTCLEAN_FILES = config.status config.cache config.log \ configure.lineno config.status.lineno mkinstalldirs = $(install_sh) -d CONFIG_HEADER = $(top_builddir)/lib/hcl-cfg.h -CONFIG_CLEAN_FILES = go/cfg/go.mod go/cfg/cfg.go +CONFIG_CLEAN_FILES = CONFIG_CLEAN_VPATH_FILES = am__installdirs = "$(DESTDIR)$(bindir)" PROGRAMS = $(bin_PROGRAMS) @@ -173,10 +173,9 @@ am__define_uniq_tagged_files = \ am__DIST_COMMON = $(srcdir)/Makefile.in $(top_srcdir)/ac/ar-lib \ $(top_srcdir)/ac/compile $(top_srcdir)/ac/config.guess \ $(top_srcdir)/ac/config.sub $(top_srcdir)/ac/install-sh \ - $(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing \ - $(top_srcdir)/go/cfg/cfg.go.in $(top_srcdir)/go/cfg/go.mod.in \ - README.md ac/ar-lib ac/compile ac/config.guess ac/config.sub \ - ac/depcomp ac/install-sh ac/ltmain.sh ac/missing + $(top_srcdir)/ac/ltmain.sh $(top_srcdir)/ac/missing README.md \ + ac/ar-lib ac/compile ac/config.guess ac/config.sub ac/depcomp \ + ac/install-sh ac/ltmain.sh ac/missing DISTFILES = $(DIST_COMMON) $(DIST_SOURCES) $(TEXINFOS) $(EXTRA_DIST) distdir = $(PACKAGE)-$(VERSION) top_distdir = $(distdir) @@ -410,10 +409,6 @@ $(top_srcdir)/configure: $(am__configure_deps) $(ACLOCAL_M4): $(am__aclocal_m4_deps) $(am__cd) $(srcdir) && $(ACLOCAL) $(ACLOCAL_AMFLAGS) $(am__aclocal_m4_deps): -go/cfg/go.mod: $(top_builddir)/config.status $(top_srcdir)/go/cfg/go.mod.in - cd $(top_builddir) && $(SHELL) ./config.status $@ -go/cfg/cfg.go: $(top_builddir)/config.status $(top_srcdir)/go/cfg/cfg.go.in - cd $(top_builddir) && $(SHELL) ./config.status $@ install-binPROGRAMS: $(bin_PROGRAMS) @$(NORMAL_INSTALL) @list='$(bin_PROGRAMS)'; test -n "$(bindir)" || list=; \ @@ -940,13 +935,11 @@ clean-local: @ENABLE_HCLGO_TRUE@hclgo.bin: lib/libhcl.la $(hclgo_OBJECTS) @ENABLE_HCLGO_TRUE@ cp -pf $(srcdir)/go.mod $(builddir)/go.mod >/dev/null 2>&1 || true @ENABLE_HCLGO_TRUE@ chmod u+w $(builddir)/go.mod ## with `make distcheck`, the echo's redirection to the file fails without this permission change -@ENABLE_HCLGO_TRUE@ sed -r -i -e "/^[[:space:]]*replace[[:space:]]+cfg[[:space:]]*=>/d" $(builddir)/go.mod -@ENABLE_HCLGO_TRUE@ echo -e "\nreplace cfg => $(abs_builddir)/go/cfg" >> $(builddir)/go.mod @ENABLE_HCLGO_TRUE@ [ -f $(srcdir)/go.sum ] && cp -pf $(srcdir)/go.sum $(builddir)/go.sum >/dev/null 2>&1 || true @ENABLE_HCLGO_TRUE@ CC=$(CC) \ @ENABLE_HCLGO_TRUE@ CGO_CFLAGS="-I$(abs_srcdir)/lib -I$(abs_builddir)/lib $(CFLAGS)" \ @ENABLE_HCLGO_TRUE@ CGO_LDFLAGS="-L$(abs_builddir)/lib -L$(abs_builddir)/lib/.libs -lhcl -ldl -lquadmath" \ -@ENABLE_HCLGO_TRUE@ go build -C $(srcdir) -x -o $(abs_builddir)/hclgo.bin -modfile $(abs_builddir)/go.mod +@ENABLE_HCLGO_TRUE@ go build -C $(srcdir) -ldflags "-X 'main.BINDIR=$(bindir)' -X 'main.SBINDIR=$(sbindir)' -X 'main.LIBDIR=$(libdir)' -X 'main.SYSCONFDIR=$(sysconfdir)'" -x -o $(abs_builddir)/hclgo.bin -modfile $(abs_builddir)/go.mod @ENABLE_HCLGO_TRUE@ go clean -C $(srcdir) -x -modfile $(abs_builddir)/go.mod @ENABLE_HCLGO_TRUE@ rm -rf $(builddir)/go.mod $(builddir)/go.sum diff --git a/configure b/configure index 15db4ed..4fe2932 100755 --- a/configure +++ b/configure @@ -18740,7 +18740,7 @@ printf "%s\n" "#define HCL_CONFIGURE_ARGS \"$ac_configure_args\"" >>confdefs.h printf "%s\n" "#define HCL_CONFIGURE_CMD \"$hcl_configure_cmd\"" >>confdefs.h -ac_config_files="$ac_config_files Makefile lib/Makefile mod/Makefile bin/Makefile go/cfg/go.mod go/cfg/cfg.go t/Makefile" +ac_config_files="$ac_config_files Makefile lib/Makefile mod/Makefile bin/Makefile t/Makefile" cat >confcache <<\_ACEOF # This file is a shell script that caches the results of configure @@ -19792,8 +19792,6 @@ do "lib/Makefile") CONFIG_FILES="$CONFIG_FILES lib/Makefile" ;; "mod/Makefile") CONFIG_FILES="$CONFIG_FILES mod/Makefile" ;; "bin/Makefile") CONFIG_FILES="$CONFIG_FILES bin/Makefile" ;; - "go/cfg/go.mod") CONFIG_FILES="$CONFIG_FILES go/cfg/go.mod" ;; - "go/cfg/cfg.go") CONFIG_FILES="$CONFIG_FILES go/cfg/cfg.go" ;; "t/Makefile") CONFIG_FILES="$CONFIG_FILES t/Makefile" ;; *) as_fn_error $? "invalid argument: \`$ac_config_target'" "$LINENO" 5;; diff --git a/configure.ac b/configure.ac index 97bf9fe..0db1aa7 100644 --- a/configure.ac +++ b/configure.ac @@ -690,8 +690,6 @@ AC_CONFIG_FILES([ lib/Makefile mod/Makefile bin/Makefile - go/cfg/go.mod - go/cfg/cfg.go t/Makefile ]) AC_OUTPUT diff --git a/go.mod b/go.mod index dbf7042..d494942 100644 --- a/go.mod +++ b/go.mod @@ -1,5 +1,3 @@ module code.miflux.com/hyung-hwan/hcl go 1.20 - -require cfg v0.0.0 diff --git a/go/cfg/cfg.go.in b/go/cfg/cfg.go.in deleted file mode 100644 index 0bcef51..0000000 --- a/go/cfg/cfg.go.in +++ /dev/null @@ -1,5 +0,0 @@ -package cfg - - - -const BINDIR string = "@bindir@" diff --git a/go/cfg/go.mod.in b/go/cfg/go.mod.in deleted file mode 100644 index 650b980..0000000 --- a/go/cfg/go.mod.in +++ /dev/null @@ -1,6 +0,0 @@ -module cfg - -go 1.20 - -// this package is not supposed to be used by other parties. -// it's intended for internal use only to work around buld issues with autotools. diff --git a/main.go b/main.go index e620468..aba60e2 100644 --- a/main.go +++ b/main.go @@ -1,7 +1,6 @@ package main import ( - _ "cfg" "fmt" "os" "strings" @@ -19,6 +18,12 @@ import ( `)) */ +/* to be set in build time */ +var BINDIR = "." +var SBINDIR = "." +var LIBDIR = "." +var SYSCONFDIR = "." + type Param struct { log_file string input_file string diff --git a/t/Makefile.in b/t/Makefile.in index bee8873..6bab9b5 100644 --- a/t/Makefile.in +++ b/t/Makefile.in @@ -478,7 +478,7 @@ check_SCRIPTS = \ ret-01.hcl \ retvar-01.hcl \ va-01.hcl \ - var-01.hcl + var-02.hcl check_ERRORS = \ call-01.err \