jw-pkg/scripts/jw-pkg-create-project.sh
Jan Lindemann d90c0ebf18
cache.mk: Include from topdir.mk, not make.mk
During a topdir "make all", caching variables is currently not the
first thing that happens. Instead, variables are cached as soon as a
project recurses into the make subdirectory. That was necessary,
because some makefiles were regenerated in the make subdirectory by
autoconf, potentially contributing variables that needed to be
cached.

As of now, autoconf is long gone and this is no longer true. And for
some variables, the two step process becomes involved, notably for
PYTHONPATH, which coding agents would like to look at from the topdir
very early on.

This commit moves the .project-cache.mk creation to topdir.mk, and
.projects-cache.mk creation to jw-pkg/Makefile to address that.

Signed-off-by: Jan Lindemann <jan@janware.com>
2026-07-22 14:38:24 +02:00

199 lines
2.9 KiB
Shell

#!/bin/bash
log()
{
printf '%s\n' "$*"
}
err()
{
log "$*"
}
fatal()
{
err "$*"
exit 1
}
usage()
{
echo "$myname [-h] [-s summary] [-d description] [-g pkg-group] name"
[ "$1" ] && exit $1
}
cat_Makefile()
{
cat <<-EOT
TOPDIR = .
include \$(TOPDIR)/make/proj.mk
include \$(JWBDIR)/make/topdir.mk
EOT
}
cat_VERSION()
{
cat <<-EOT
1.0.0-0-dev
EOT
}
cat_make_Makefile()
{
cat <<-EOT
TOPDIR = ..
include \$(TOPDIR)/make/proj.mk
include \$(JWBDIR)/make/make.mk
EOT
}
cat_make_proj_mk()
{
cat <<-EOT
# to be included from inside the project directory
DEV_PROJECTS_DIR ?= \$(TOPDIR)/..
ifeq (\$(TARGET),mingw)
FLAVOUR_PATH_PREFIX = win32/
endif
JWBDIR ?= \$(firstword \$(wildcard \$(DEV_PROJECTS_DIR)/jw-pkg \$(BUILD_TOOLS_PREFIX)/opt/\$(FLAVOUR_PATH_PREFIX)jw-pkg))
USE_PROJECT_LIB = false
HDRDIR_SCOPE_SUFFIX = \$(PROJECT)
EOT
}
cat_make_project_conf()
{
local login=$JANWARE_USER
[ "$login" ] || login=`whoami`
local fullname=`getent passwd $login | cut -d: -f5`
[ "$fullname" ] || fullname=$JANWARE_USER
[ "$fullname" ] || fullname=`whoami | xargs getent passwd | cut -d: -f5`
[ "$fullname" ] || fullname=`whoami`
cat <<-EOT
[summary]
$summary
[description]
$description
[global]
group = "$pkg_group"
subpackages = $subpackages
license = Copyright (c) $fullname, all rights reserved
jw-maintainer = $JANWARE_USER
[build]
libname = none
[pkg.requires.jw]
devel = $name-run = VERSION-REVISION, jw-pkg-devel = VERSION
build = jw-pkg-devel
EOT
}
cat_gitignore()
{
cat <<-EOT
*.done
*.dist
*.dep.mk
.cache-project.mk
*.o
*.so.*
*.so
*.a
*.rep
ld-*.conf
*.ldscript
*.pc
$name
*_generated_*
*.secret
local.mk
.gdb_history
dist
mkspec.sh
*.out
*.orig
*.old
.feedfs_history
.exrc
*.swp
*tmp*
__init__.py
__pycache__
pyproject.toml
pyrightconfig.json
EOT
}
# ---------------------- here we go
myname=`basename $0`
projdir=.
summary=
description=
subpackages="run"
eval set -- `getopt -- hd:s:p:g: "$@"`
while [ "$1" != -- ]; do
case $1 in
-d)
eval description=\"$2\"
shift;;
-s)
eval summary=\"$2\"
shift;;
-p)
eval subpackages=\"$2\"
shift;;
-g)
eval pkg_group=\"$2\"
shift;;
-h)
usage 0;;
*)
usage 1;;
esac
shift
done
shift
[ -z "$description" ] && description="$summary"
[ -z "$summary" ] && summary="$description"
[ -z "$pkg_group" ] && pkg_group="Amusements/Teaching/Other"
[ -f $projdir/Makefile ] || {
fatal "$projdir doesn't contain a Makefile"
}
name="$1"
[ -d $projdir/$name ] && {
fatal "$projdir/$name already exists"
}
set -e
mkdir -p $projdir
mkdir $name
cd $projdir/$name
mkdir make
cat_Makefile > Makefile
cat_make_Makefile > make/Makefile
cat_VERSION > VERSION
cat_make_proj_mk > make/proj.mk
cat_make_project_conf > make/project.conf
cat_gitignore > .gitignore
log Successfully created project template \"$name\".