Skip to content

Commit

Permalink
Template: make install now installs in opam directory
Browse files Browse the repository at this point in the history
  • Loading branch information
balat committed Sep 2, 2024
1 parent 3cea91a commit 4c298fe
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 22 deletions.
5 changes: 3 additions & 2 deletions template.distillery/Makefile.options
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,14 @@ USE_NPM := yes
## The following part contains the configuration for the ocsigenserver.

# Port for running the server (make run.*)
PORT := 80
PORT := 8080

# Port for testing (make test.*)
TEST_PORT := 8080

# Root of installation (must end with /)
PREFIX := /usr/local/
#PREFIX := /usr/local/
PREFIX := ${OPAM_SWITCH_PREFIX}/

# Local folder for make test.* (must end with /)
TEST_PREFIX := local/
Expand Down
37 changes: 25 additions & 12 deletions template.distillery/Makefile.os
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ all byte opt:: ${VOLATILE_SCHEMA}

DIST_FILES = $(ELIOMSTATICDIR)/$(PROJECT_NAME).js $(LIBDIR)/$(PROJECT_NAME).cma

.PHONY: test.byte test.opt staticfiles
.PHONY: test.byte test.opt staticfiles byte opt

test.byte:: byte | $(addprefix $(TEST_PREFIX),$(DIST_DIRS)) staticfiles
@echo "==== The website is available at http://localhost:$(TEST_PORT) ===="
Expand All @@ -58,10 +58,10 @@ test.opt:: opt | $(addprefix $(TEST_PREFIX),$(DIST_DIRS)) staticfiles

test.static.byte: static.byte | $(addprefix $(TEST_PREFIX),$(DIST_DIRS)) staticfiles
@echo "==== The website is available at http://localhost:$(TEST_PORT) ===="
dune exec ./%%%PROJECT_NAME%%%_main.bc
dune exec ./$(PROJECT_NAME)_main.bc
test.static.opt: static.opt | $(addprefix $(TEST_PREFIX),$(DIST_DIRS)) staticfiles
@echo "==== The website is available at http://localhost:$(TEST_PORT) ===="
dune exec ./%%%PROJECT_NAME%%%_main.exe
dune exec ./$(PROJECT_NAME)_main.exe

$(addprefix $(TEST_PREFIX), $(DIST_DIRS)):
mkdir -p $@
Expand All @@ -73,29 +73,35 @@ staticfiles:
## Static executable

static.byte: byte
dune build %%%PROJECT_NAME%%%_main.bc
dune build $(PROJECT_NAME)_main.bc

static.opt: opt
dune build %%%PROJECT_NAME%%%_main.exe
dune build $(PROJECT_NAME)_main.exe

##----------------------------------------------------------------------
## Installing & Running

.PHONY: install install.byte install.byte install.opt install.static install.etc install.lib install.lib.byte install.lib.opt run.byte run.opt
.PHONY: install install.exe install.byte install.byte install.opt install.static install.etc install.lib install.lib.byte install.lib.opt run.byte run.opt
install: install.byte install.opt
install.exe: install.etc install.static
dune install
install.byte: install.lib.byte install.etc install.static | $(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(shell dirname $(CMDPIPE)))
install.opt: install.lib.opt install.etc install.static | $(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(shell dirname $(CMDPIPE)))
install.lib: install.lib.byte install.lib.opt
install.lib.byte: $(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cma | $(PREFIX)$(LIBDIR)
install $< $(PREFIX)$(LIBDIR)
install.lib.opt: $(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cmxs | $(PREFIX)$(LIBDIR)
install $< $(PREFIX)$(LIBDIR)
install.lib.byte: byte | $(PREFIX)$(LIBDIR)
install $(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cma $(PREFIX)$(LIBDIR)
install.lib.opt: opt | $(PREFIX)$(LIBDIR)
install $(TEST_PREFIX)$(LIBDIR)/$(PROJECT_NAME).cmxs $(PREFIX)$(LIBDIR)
install.static: $(TEST_PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js | $(PREFIX)$(STATICDIR) $(PREFIX)$(ELIOMSTATICDIR)
cp -r $(LOCAL_STATIC_CSS) $(PREFIX)$(FILESDIR)
cp -r $(LOCAL_STATIC_IMAGES) $(PREFIX)$(FILESDIR)
cp -r $(LOCAL_STATIC_FONTS) $(PREFIX)$(FILESDIR)
[ -z $(WWWUSER) ] || chown -R $(WWWUSER) $(PREFIX)$(FILESDIR)
install $(addprefix -o ,$(WWWUSER)) $< $(PREFIX)$(ELIOMSTATICDIR)
HASH=`md5sum _build/default/client/$(PROJECT_NAME).bc.js | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(JS_PREFIX)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR) && \
ln -sf $(PROJECT_NAME)_$$HASH.js $(PREFIX)$(ELIOMSTATICDIR)/$(PROJECT_NAME).js
HASH=`cat $(LOCAL_CSS) | md5sum | cut -d ' ' -f 1` && \
install $(addprefix -o ,$(WWWUSER)) $(CSS_PREFIX)_$$HASH.css $(PREFIX)$(ELIOMSTATICDIR)/css && \
ln -sf $(PROJECT_NAME)_$$HASH.css $(PREFIX)$(ELIOMSTATICDIR)/css/$(PROJECT_NAME).css
install.etc: $(TEST_PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf | $(PREFIX)$(ETCDIR)
install $< $(PREFIX)$(ETCDIR)/$(PROJECT_NAME).conf

Expand All @@ -111,12 +117,19 @@ $(addprefix $(PREFIX),$(DATADIR) $(LOGDIR) $(ELIOMSTATICDIR) $(shell dirname $(C
install $(addprefix -o ,$(WWWUSER)) -d $@

run.byte:
@echo "==== Running ocsigenserver with configuration file ===="
@echo "==== The website is available at http://localhost:$(PORT) ===="
$(OCSIGENSERVER) $(RUN_DEBUG) -c ${PREFIX}${ETCDIR}/${PROJECT_NAME}.conf
run.opt:
@echo "==== Running ocsigenserver with configuration file ===="
@echo "==== The website is available at http://localhost:$(PORT) ===="
$(OCSIGENSERVER.OPT) $(RUN_DEBUG) -c ${PREFIX}${ETCDIR}/${PROJECT_NAME}.conf

run.static:
@echo "==== Running static executable ===="
@echo "==== The website is available at http://localhost:$(PORT) ===="
${PROJECT_NAME}

##----------------------------------------------------------------------

##----------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion template.distillery/PROJECT_NAME.opam
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
opam-version: "2.0"
name: "%%%PROJECT_NAME%%%"
version: "0.1"
synopsis: "Pseudo package for defining project dependencies"
synopsis: "%%%PROJECT_NAME%%%"

depends: [
"eliom" {>= "11.0.0" & < "12.0.0"}
Expand Down
21 changes: 14 additions & 7 deletions template.distillery/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -119,20 +119,27 @@ make test.static.byte (or test.static.opt)
make all (or byte or opt)
```

- DEPRECATED Deploy your project on your system
- Deploy your project on your system
```Shell
sudo make install (or install.byte or install.opt)
make install (or install.byte or install.opt)
```

- DEPRECATED Run the server on the deployed project
- Run the server on the deployed project
```Shell
sudo make run.byte (or run.opt)
make run.byte (or run.opt)
```

If Eliom isn't installed globally, however, you need to
re-export some environment variables to make this work:
- Run the static executable of the deployed project
```Shell
sudo PATH=$PATH OCAMLPATH=$OCAMLPATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH make run.byte/run.opt
make run.static
```

If you want to use a global install, update PREFIX in `Makefile.options`
and run make ```install``` as root. If OCaml/Eliom is not installed
globally, you will need to re-export some environment variables to make
this work:
```Shell
sudo PATH=$PATH OCAMLPATH=$OCAMLPATH LD_LIBRARY_PATH=$LD_LIBRARY_PATH make run.opt
```

- If you need a findlib package in your project, add it to the
Expand Down

0 comments on commit 4c298fe

Please sign in to comment.